AnsweredAssumed Answered

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

Question asked by Rastislav Matula on Dec 12, 2009
Latest reply on Dec 15, 2009 by Stefan-Teodor Craciun

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.

Outcomes