/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / STM32 return float from function corrupted

Username:     
Password:     
             

Forum

# 1   2009-04-02 18:07:43 STM32 return float from function corrupted

The_Todd
Member
Registered: 2008-12-07
Posts: 15

STM32 return float from function corrupted

I have a function which calculates pitch from X and Z readings of an accelerometer:

Code:

//Return Pitch In Radians
float fPitchRad(float X,float Z)
{
    float P;
    
    //Calculate Pitch
    P = atan2(Z,X);   //P properly equals 1.5708 here

    return P;
}

//Test math
void main()
{
     float fPitch, fX, fZ;

     //Test Values
     fX = 0;
     fZ = 1000;

     //Get Pitch
     fPitch = fPitchRad(fX,fZ);   //Should equal 1.5708, but equals 1.07014+e9

}

When testing in hardware using Rlink breakpoints and Ride7, the float value is correct inside the fPitchRad function (P var), but when returned displays improperly on the fPitch var.

Whats going on?

Offline

 

# 2   2009-04-02 19:30:09 STM32 return float from function corrupted

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: STM32 return float from function corrupted

We will check, but I guess that the problem is probably within the visualization of the local variable that has been optimized.

Offline

 

# 3   2009-04-03 11:00:32 STM32 return float from function corrupted

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: STM32 return float from function corrupted

I just checked with fPitch declared as a global variable, and it works fine. As suggested above, I believe that it's a problem of visualization caused by the optimization of the local variables.

Offline

 

Board footer