TI E2E Community
Temperature Sensors Forum
TMP006 Need a subroutine to calculate object temperature without using fpu
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?
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.
Ian WilliamsLinear Applications EngineerPrecision Analog
Thanks Ian, I will wait for your reply.
Hello Ian, were you able to check with your designer?
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 calculations2. 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.
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?
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.
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.
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 ).
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.
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,
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.
Thanks Ian for the clarification.
I will get back to you if I need anymore clarification. Basically I am planning to do more testing.
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 email@example.com.
I've attached the updated code. You must first agree to a license agreement before the source code and documentation will extract.
All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.
TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs andembedded processors, along with software, tools and the industry’s largest sales/support staff.