sqrt causing lockup  (NOT a float/linker issue)

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

sqrt causing lockup  (NOT a float/linker issue)

跳至解决方案
895 次查看
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!

标签 (1)
0 项奖励
回复
1 解答
509 次查看
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 项奖励
回复
1 回复
510 次查看
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 项奖励
回复