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.

TMP006 Need a subroutine to calculate object temperature without using fpu

Hello,

I am having difficulty in calculating the object temperature without using the floating point operations.

Can you please help me in writing a c routine which calculates the object temperature without using floating point operations?

Thanks

  • Hi Preetham,

    This is something the designer was working on. Let me check with him and see if we have any fixed-point math that we can share.

    Best regards,

    Ian Williams
    Linear Applications Engineer
    Precision Analog 

  • Thanks Ian, I will wait for your reply.

    Regards,

    -Preetham.

  • Hello Ian, were you able to check with your designer?

    Thanks.

  • Hello Preetham,

    Sorry for the delay.

    I have attached the current version of the fixed-point code. However, let me qualify this a bit:

    1. The code does not check for errors such as invalid inputs or out-of-range calculations
    2. The code is only optimized for a 32-bit microcontroller

    In other words, it is functional but mainly suited as a starting point for development. A little polish is needed to make it suitable for use in a final product.

    Best regards,

    Ian Williams 

  • Thanks Ian.

    But just a few clarifications.

    1. Does TMP006_Calculate() return target object temperature in kelvin?

    2. The Input to TMP006_Calculate() is a 16 bit register values of sensor voltage and ambient temperature right?

  • Hello Ian,

    Any comments?

    I verified the api that you provided me,

    For,  SENSOR_VOLTAGE=0xff26 and AMBIENT_TEMP=0xd00, 

    the target object temperture that I am seeing is  3227. (i.e return value from TMP006_Calculate())

    I am not able to make out much from the comment sections either.

    It would be really helpful if you could explain a bit on the fixed math formula.

    Thanks.

  • Hello Preetham,

    I did not author the code so I'm not sure how the output is formatted or whether the result is in Kelvin or degrees Celsius. I have contacted the author and should have a response within 24 hours.

    Best regards,

    Ian Williams

  • Hi Preetham,

    The output of TMP006_Calculate is a two's complement binary number, where 1 LSB = 0.03125°C.

    As for the code, it's performing the same function as the standard floating-point code, but with a lot of extra overhead in order to handle the fourth-root. 

    Best regards,

    Ian Williams

  • Hello Ian,

    Thanks a lot for the reply.

    But I am still bit concerned with the Fixed point math

    The value returned by TMP006_Calculate() and the value returned by the excel sheet attached here differ a lot. (This excel sheet was initially attached by you in one of the posts in this forum ).

    0245.TMP006 Calculator.xls

    Example 1:

    For,  SENSOR_VOLTAGE=0xff26 and AMBIENT_TEMP=0xd00,

    TMP006_Calculate() returned a value 3227 => 3227  *  0.03125°C = 100.84 °C

    If we enter the same value in the excel sheet we are seeing a value of 25.64 °C which looks correct because it's the room temperature that we are measuring currently.

    Example 2:

    For,  SENSOR_VOLTAGE=0xff3f and AMBIENT_TEMP=0xd1c,

    TMP006_Calculate() returned a value 3363 => 3363*  0.03125°C = 105.09 °C

    If we enter the same value in the excel sheet we are seeing a value of 25.96 °C

    Can you please explain to us why we are seeing such differences?

    Thanks & Regards,

    -Preetham.

  • Hi Preetham,

    Sorry for the confusion. I just checked back with the designer, and there is one extra step. You must first perform a right shift of 2 bits on the result before multiplying by 0.03125°C. This gives a much better result of 25.2°C.

    Best regards,

    Ian Williams

  • Thanks Ian for the clarification.

    I will get back to you if I need anymore clarification. Basically I am planning to do more testing. 

    Best Regards,

    -Preetham.

  • I have been having issues with the fixed point code not outputting the same answer as the floating point method, this specifically seems to be an issue when the sensor voltage is positive.  For instance when ambient reads 0x0D14 and Sensor Voltage reads 0x014C, TMP006_Calculate outputs 0x67C which is 12.968 degress C.  When I enter those values into the floating point algorithm it outputs 37.68 degress C. 

    I have typedef'd TMP006_INT16 to a 16 bit unsigned int and TMP006_INT32 to 32 bit signed int.  I have tried changes these typedefs but it hasn't made things any better.

    I am using a 16-bit microcontroller(PIC24EP256GU810) rather than a 32-bit microcontroller, could this have something to do with the issue?

    Thanks.

  • Hello Colin,

    We will address this question offline. Also, in the future please create a new thread rather than posting on an old thread, as our system gives higher visibility to new threads and we want to get a response to you as quickly as possible. Thanks!

    Best regards,

    Ian Williams

  • I've temporarily removed the current version of the fixed-point code from this thread. If you wish to receive the new version of the code, please e-mail me at ian@ti.com.

    Best regards,

    Ian Williams

  • I've attached the updated code. You must first agree to a license agreement before the source code and documentation will extract.

    Best regards,

    Ian Williams

    TMP006_Fixed_Point_Source_Code.zip