sqrt causing lockup  (NOT a float/linker issue)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

sqrt causing lockup  (NOT a float/linker issue)

Jump to solution
779 Views
z537z
Contributor I

I've been using sqrt for a while without any issue.

Added a loop to run this function many times to average many ADC samples.

It runs fine then on the 5th time locks up on the second STA here:

 

STA      Kexp:1
PULA
ADC      #(D_EXPHI)
STA      Kexp:0
; // { exp done }

 

My code is:

void ADC(void) {  float Fresult;  float PFResult;  float Result_a;  float Result_b;  float temp;  float Result_c;   /*  take 4 ADC readings: VOLT, CURR, FREQ and PF  */  Fresult = (float)FREQ;  PFResult = (float)PF;  Result_a = (VOLT*VOLT)/(CURR*CURR);  temp = sqrt(Fresult);  Result_b = PFResult/(temp*Fresult);                 Result_c = Result_a*Result_b*4096;  adcval = (int)Result_c;  return;}//ADC

 

Hangs up on the "temp" variable. Only on the 5th time through this code.

The only difference is a counter goes from 4 to 5 for this cycle, but I don't see how that'd make a difference.

What's happening here?

 

Many thanks!

Labels (1)
0 Kudos
1 Solution
393 Views
bigmac
Specialist III

Hello,

 

You do not say how the "hang" is evidenced, i.e. what happens to the program counter when this occurs.  If you are experiencing a reset, it may be possible that this is a COP reset.

 

The square root process for a floating point number will likely be a lengthy process, and unless you are clearing the COP timer within each loop, it may be quite possible for COP timeout to occur after five iterations.

 

Regards,

Mac

 

View solution in original post

0 Kudos
1 Reply
394 Views
bigmac
Specialist III

Hello,

 

You do not say how the "hang" is evidenced, i.e. what happens to the program counter when this occurs.  If you are experiencing a reset, it may be possible that this is a COP reset.

 

The square root process for a floating point number will likely be a lengthy process, and unless you are clearing the COP timer within each loop, it may be quite possible for COP timeout to occur after five iterations.

 

Regards,

Mac

 

0 Kudos