This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/TMS320F280049: Equation evaluation result came wrong !

Part Number: TMS320F280049

Tool/software: Code Composer Studio

Hi Team,

I am new to CCS, while running the code shown below I got the results for my variable R_rtd and Cabin_Temp came wrong after calculation. What might be gone wrong here. All I see a not so complex calculation. 

int32 r1                = 0x00000000;
int32 r2                = 0x00000000;
float32 Cabin_Temp; // Cabin Temperature
float32 R_rtd; // Resistance of RTD

This is the declaration part and following is the calculation part 

                r1                                  = SpiaRegs.SPIRXBUF;
                r1                                  = SpiaRegs.SPIRXBUF;
                r1                                  = r1<<8;
                r2                                  = SpiaRegs.SPIRXBUF;
                r1                                  = r1|r2>>8;
                R_rtd                               = (r1*1080)/(4194304*16);    // RTD resistance, R_rtd = (r1*R_ref)/(2^22*Gain)
                Cabin_Temp                          = ((R_rtd/100)-1)/(0.00385); // Cabin temperature, Cabin_temp = ((R_rtd/RO)-1)/alpha

I am expecting an answer R_rtd close to 100 and Cabin_Temp close 0.2, instead it is showing random negative values.

Please help me out

Best Regards,

Vineeth N

  • Are you aware this expression ...

    Vineeth N said:
    (r1*1080)/(4194304*16)

    ... is computed entirely in 32-bit integer math?  In particular, the division truncates.  Only the integer part of the division result is kept.  The rest is ignored.  After this complete integer expression is computed, it is then converted to float for assignment to R_rtd.  Does this behavior explain the problem?

    Thanks and regards,

    -George

  • Hi George,

    Thank you for your response. 

    Sorry for the delay, I think what you said might be the issue. Also I think my calculation is exceeding the limits of accumulator. Is there is any chance for it ?. My variable Cabin_Temp is a 32 bit variable. If i perform multiplication or division I will be requiring a 64 bit accumulator right? is this thought correct ?

    Best Regards,

    Vineeth N

  • To understand the limits of the floating point types, please search the C28x compiler manual for the sub-chapter titled Data Types.

    Thanks and regards,

    -George