Floating point operations causing global variable corruption

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

Floating point operations causing global variable corruption

跳至解决方案
1,400 次查看
Bit_0
Contributor I

Hi,

 

I am new to Freescale development. Using a MC9S08DZ60 board for my project. I have created a project in Eclipse 10.1 version using support for IEEE32 type floating point.

 

My project uses a couple of floating point operations and 5 global variables. Whenever I attempt to do a floating point arithmetic operation with integer or character type, the global variables are getting modified unneccessarily.

For e.g. when I try to typecast an integer to float type or add / subtract a float variable with integer / character, my global variables are getting corrupted.

 

Can somebody please guide me where I am going wrong?

 

Here is portion of code, which is causing this behaviour:

 

void HexToASCII(float Slip, char *String){char i;unsigned long intPart, FractPart;float tempfloat;unsigned long templong;tempfloat = Slip;intPart = (unsigned long) Slip;tempfloat = (Slip - (float) intPart); /* This behaviour is observed here after executing this line and all further lines */tempfloat = tempfloat * 10;FractPart = (unsigned long) tempfloat;

 

 

 

 

Thanks..

标签 (1)
0 项奖励
回复
1 解答
1,059 次查看
kef
Specialist I

Software FP operations require a lot of stack space. Probably STACKSIZE specified in prm file is too low for FP and stack overflows. Try increasing it.

在原帖中查看解决方案

0 项奖励
回复
2 回复数
1,060 次查看
kef
Specialist I

Software FP operations require a lot of stack space. Probably STACKSIZE specified in prm file is too low for FP and stack overflows. Try increasing it.

0 项奖励
回复
1,059 次查看
Bit_0
Contributor I

 


kef wrote:

Software FP operations require a lot of stack space. Probably STACKSIZE specified in prm file is too low for FP and stack overflows. Try increasing it.


 

Yes, stack size was culprit. Default stack size was 128 bytes. I increased it to 512 and it got solved. It took little time to find out how to increase the stack size, when developing with eclipse IDE. It is located in CPU component properties.

 

For those new to eclipse:

In the Project window, right click on the CPU under tab - ProcessorExpert.pe->CPUs->Cpu:MC....

Click on Inspector. Then in component inspector window, under stack specification, modify the stack size as required.

 

Thank you very much kef.

0 项奖励
回复