2017-06-19 11:00 AM
We're using the LIS2HH12 accelerometer and there's a temperature sensor listed in the datasheet accessible via the temp_L and temp_H registers (16 bits).
However the numbers I get don't make any sense.
The datasheet mentions 'Temperature sensor output change vs. temperature' of 8 digit/�C
11-bit resolution, -40 to 80C range and that the it uses two's complement, but I can't find a way to make the readings return any meaningful value.
What do these
temp_L and temp_H numbers really mean? Thank you.
#lis2hh12 #temperature-sensorSolved! Go to Solution.
2017-06-20 11:52 PM
I think Jose is asking for the data interpretation. I would also appreciate a more detailed description in the datasheet.
TEMP_H:TEMP_L is the raw sensor output - a signed 16-bit number, stored as two's complement.
At 25 centigrades, the output is 0. For every centigrade, the sensor output value changes for 8 LSBs, meaning 1 LSB is a 0,125 centigrades change (2 LSBs 0,25 centigrades, 4 LSBs 0,5 centigrades etc.).
So the basic formula is: TEMP_H:TEMP_L + temp_offset_25_centigrades = measured_temperature
(Please note that negative TEMP_H:TEMP_L value doesn't necessarily mean a negative temperature.)
I personally display 2 decimal digits in my applications, but use integer variables to keep the code fast and clean, so I read the sensor output data like this:
int16_t tempHex = (temp_h << 8) | temp_l;
and then do the following computation: multiply the sensor output value by
TEMP_FRACTION_MULTIPLIER =
125 and divide it withTEMP_FRACTION_DIVIDER =
10. This way the value stored in the temperature register contains temperature value multiplied by a hunded (12.34 centigrades is stored as 1234 etc.).TEMP_OFFSET = 2500 (for 25.00 centigrades).
int32_t temperature = ((tempHex * TEMP_FRACTION_MULTIPLIER) / TEMP_FRACTION_DIVIDER) + TEMP_OFFSET;
Or you can just divide TEMP_H:TEMP_L by 8 (shift by 3 positions to the right), discard the decimal points and use only the round value of centigrades. (You still need to add the offset of 25 centigrades.)
Hope this helps a bit.
2017-06-20 02:07 AM
The temperature sensor can be used to measure temperature variations.
It isn't suitable to return absolute temperatures measures. The value represents difference respect to a reference not specified value.2017-06-20 11:52 PM
I think Jose is asking for the data interpretation. I would also appreciate a more detailed description in the datasheet.
TEMP_H:TEMP_L is the raw sensor output - a signed 16-bit number, stored as two's complement.
At 25 centigrades, the output is 0. For every centigrade, the sensor output value changes for 8 LSBs, meaning 1 LSB is a 0,125 centigrades change (2 LSBs 0,25 centigrades, 4 LSBs 0,5 centigrades etc.).
So the basic formula is: TEMP_H:TEMP_L + temp_offset_25_centigrades = measured_temperature
(Please note that negative TEMP_H:TEMP_L value doesn't necessarily mean a negative temperature.)
I personally display 2 decimal digits in my applications, but use integer variables to keep the code fast and clean, so I read the sensor output data like this:
int16_t tempHex = (temp_h << 8) | temp_l;
and then do the following computation: multiply the sensor output value by
TEMP_FRACTION_MULTIPLIER =
125 and divide it withTEMP_FRACTION_DIVIDER =
10. This way the value stored in the temperature register contains temperature value multiplied by a hunded (12.34 centigrades is stored as 1234 etc.).TEMP_OFFSET = 2500 (for 25.00 centigrades).
int32_t temperature = ((tempHex * TEMP_FRACTION_MULTIPLIER) / TEMP_FRACTION_DIVIDER) + TEMP_OFFSET;
Or you can just divide TEMP_H:TEMP_L by 8 (shift by 3 positions to the right), discard the decimal points and use only the round value of centigrades. (You still need to add the offset of 25 centigrades.)
Hope this helps a bit.
2017-06-21 02:10 AM
I would like to add that the TEMP_OFFSET is not guaranteed to be 25
centigrades. There is certain level of uncertainty so please don't expect high precision of the temperature measurement.
2017-06-21 10:00 AM
On the other hand, assuming that the temperature value output is linear in sensor's working conditions, the TEMP_OFFSET can be measured using a known calibrated thermometer and adjusted as a constant in a firmware later. This approach creates quite a reliable output (I personally do this with prototypes). However, needs to be done with every sensor, which is always not possible or meaningful.
2017-11-13 05:39 AM
So what the '11-bit resolution' means in chapter 2.3 of the datasheet ?
Cause I receive strange values according to your method ( TEMP_H : 0xFA, TEMP_L : 0xA0 for example).
2017-11-13 08:11 AM
11-bits resolution means the value in encoded in the highest 11 bit of the 16 bit value (TEMP_H, TEMP_L).
Temperature sensor output change vs. temperature is 8 digit/°C which means 1LSB = 0.125
°C.
The value is encoded as two's complement.
So your example means -11.375°C (difference respect to a reference value).
2017-11-13 09:23 AM
I don't understand how you find -11.375°C, for tempHex, i have 1111 1010 1010 0000 (FAA0), what do you do after ?
2017-11-13 09:58 AM
1111 1010 1010 0000 (0xFAA0) ... 16-bit value
111 1101 0101 ... 11-bit value, the value is left adjusted
2005 ... conversion to decimal value
2005 - 2048 = -43 ... conversion from
https://en.wikipedia.org/wiki/Two%27s_complement
-43 / 8 = -5.375
°C ... conversion to °C (8 digit/°C which means 1LSB = 0.125
°C)
I'm sorry, I did a mistake in conversion in my previous post.
2018-02-27 11:01 AM
Txs for the complete answer
Batek.Miroslav
.It was not that intuitive to read the temp value from the sensor. Cheers