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!
已解决! 转到解答。
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
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