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.

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.

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.

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 ).

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?

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.

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?

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!

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.