sheetanshkaushik

POSSIBLE LOSS OF DATA-CODEWARRIOR

Discussion created by sheetanshkaushik on Apr 11, 2013
Latest reply on Apr 14, 2013 by Colin Howard

Hi! Please consider the following code:

 

unsigned int  beta;

unsigned int theta;
unsigned int m = 4;
unsigned int c = 986;
unsigned int Rpre = 49900;

 

unsigned int getUAnalog(unsigned char channel) // to get the PT1000 Signal

{

    unsigned int result;

    unsigned int f_temp;

    //select channel and initiate conversion

    ADCSC1 |= (channel & 0b11111);

   

    //wait until conversion is complete

    while(!ADCSC1_COCO);

   

    f_temp = ADCRH;

    f_temp <<= 8;

    f_temp += ADCRL;

   

    beta = (((f_temp) / (4096*28))*1000); // warning: possible loss of data.

    theta = ((((beta)*(Rpre))/(1-beta))*1000);

    result = (theta-c)/(m);

    return result;

  

}

 

I am using MC9S08DZ60 (http://www.freescale.com/files/microcontrollers/doc/data_sheet/MC9S08DZ60.pdf) with PT1000-Temperature Sensor on CodeWarrior version 5.9.0 . This function is meant to calculate the temp and return "result". But the "beta" and "theta" values remain 0. No Change.

Also i get the warning as C2705: Possible Loss of Data.  The value of "result" is not right. PLease help as i dont have clue of what going wrong!!

 

Thanks in advance!

Outcomes