Floating point operations causing global variable corruption

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

Floating point operations causing global variable corruption

Jump to solution
910 Views
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..

Labels (1)
0 Kudos
Reply
1 Solution
569 Views
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.

View solution in original post

0 Kudos
Reply
2 Replies
570 Views
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 Kudos
Reply
569 Views
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 Kudos
Reply