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 

  • In reply to Ian Williams:

    Thanks Ian, I will wait for your reply.

    Regards,

    -Preetham.

  • In reply to Preetham C:

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

    Thanks.

  • In reply to Preetham C:

    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 

  • In reply to 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?

  • In reply to Preetham C:

    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.

  • In reply to Preetham C:

    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

  • In reply to 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

  • In reply to 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.

  • In reply to Preetham C:

    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