AnsweredAssumed Answered

Temporary variables not initializing?

Question asked by Allen Babb on Aug 17, 2011
Latest reply on Aug 24, 2011 by stanish

Is there anything wrong with this code?

 

/*. .. */extern unsigned char Fo_A[];   //Defined in ASM file/* ... */const signed short S[3] = {-10, 0, 10};  //Singleton table/* ... */signed short dT_ThrotA; //Output variables/* ... */void DeFuzz(void){  signed int tempNum;   //Temporary Numerator var  signed int tempDen;  unsigned int i;       //iteration counter  //***Motor A***  tempNum = 0;  tempDen = 0;  for(i = 3; i>0;i--){    tempNum = tempNum + (Fo_A[i] * S[i]);    tempDen = tempDen + Fo_A[i];  }  dT_ThrotA = (tempNum / tempDen);  /* ... */}

 

 

It's run through about 50 times per second thanks to a timer based ISR.

 

When I run it through the debugger, every now and then the tempNum and tempDen get a random number in them instead of being initialized to 0... I can't figure out why it's doing this.

Outcomes