powf() problem - unpredictable changing the variables not used in this function...

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

powf() problem - unpredictable changing the variables not used in this function...

Jump to solution
1,966 Views
RastislavMatula
Contributor I

Hello,

 

I searched a few posts on this forum (especially about powf()), but it seems, that nobody had similar problem like me. I am not professional, so it can be some basic mistake which I am not aware about...

 

I am using the MCU - MC9S08JM60, with OpenSource BDM, CodeWarrior IDE v5.9.0 - Build 2830 (install file CW_MCU_V6_2_SE.exe, downloaded from feescale), Processor Expert v3.06 for freescale HC(S)08/RS08/CFV1, CW plugin IDE v4.26.

 

Until I am using powf() function, everything working fine. But when I call the powf function, it unpredictably change variables outside this function. I found it out by stepping the program in debugging mode. I have included  #include <math.h> and I added an ansifs.lib to my project since without it there was some errors about not defined float (or something...).

 

I am trying calculate altitude, so it have to be accurate:

 

    .
    .
    .   
#include <math.h>
    .
float           altitude;
unsigned int    cislo;
unsigned int    pressure_value;
    .
    .
    .
    case 2:               //Altimeter:
      menu_Altimeter();
      for(;;)
      {
        i2c_SelectSlave(ADC_I2C_ADDR); 
        i2c_RecvBlock(i2c_data_r,3,i2c_cnt_r);              // I2C recieve data ffrom I2C

        pressure_value=i2c_data_r[0];
        pressure_value=pressure_value<<8;
        pressure_value=pressure_value+i2c_data_r[1]+32767;  // 0-65535 -> 40-116kPa

        // equation dividied in parts
        altitude = 34720 + pressure_value;
        altitude = powf(altitude, 0.190263236508);     // There is the problem...
        altitude = ((-5.08604881782 * altitude) + 44.33076923)*10000;
        cislo = altitude/1;
       
        NumberToString(cislo, ConvertedLong);   // convert cislo to string
        LcdGotoXYFont(2, 5);
        LcdStr(FONT_1X, ConvertedLong);         // display on LCD
        LcdUpdate();
          
       
        if(menu_H!=2)
        {
        goto StartOfMenu;
        }
      }
      break;
     
    case 3:               //Pressure:
      menu_Pressure();
      for(;;)
      {
       .
       .
       .

 

 There is showed the function which causing the problem and I skipped varibles and definition which are not urgent in this case...

 

After powf() calculate the altitude, it change not only the altitude value, but it change also another variables, but I have no Idea why, I was trying computing it in steps with help of another variables, but the result was the same after powf() function...

 

there is the screen from debuger debuger.png

 

If is there anybody with some clue what could be wrong, I would really appreciate help! Thanks for any advice and sorry about my English.

Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
864 Views
CompilerGuru
NXP Employee
NXP Employee

Sounds a lot like a stack overflow.

increase the STACKSIZE parameter in the prm file.

 

Daniel

View solution in original post

0 Kudos
Reply
3 Replies
865 Views
CompilerGuru
NXP Employee
NXP Employee

Sounds a lot like a stack overflow.

increase the STACKSIZE parameter in the prm file.

 

Daniel

0 Kudos
Reply
864 Views
RastislavMatula
Contributor I

Thank you for quick response... that was the problem, now is everything working fine. :smileyhappy:

 

But can I ask you, Is there any way to set this value in something like "project settings" inside the CW? Every time I am adding beans and PE is rebuilding those files, STACKSIZE is set back to default value. I wasn't able to find such settings.

 

 

And there is one more (Out topic) question. Is there any way to save the Debugger windows layout? I am able to save new layout, but not like default. So everytime I start the debugger, I have to load my saved layout. It begins to be bothering me, when there is some problem, and I have to after every small change in code set the windows back to my settings.

 

Once again thank you very much for help :smileyhappy:

0 Kudos
Reply
864 Views
Navidad
Contributor III
You should go to Processor Expert -> View -> Inspector. In the component inspector, go to the
"Build options" tab and under "Generate PRM file"->"Stack specification" you can set the stack size. At least this is how it works with CW for HC08 v6.3.
0 Kudos
Reply