# How to calculate temperature value

1. ## How to calculate temperature value

Hii,

How to calculate temperature value from hexadecimal output. I am using ADXL362 accelerometer(in-built temp.sensor). Getting result of B3 01. Resolution is 12-bit.

There is one equation, Temp.value in degree C = offset+(counts/scale). here count is decimal value of output. Is this right equation? If I used offset value in datasheet,getting higher values.

•

2. ## Re: How to calculate temperature value

Hi,

hex --> Dec
0 --> 0
8 --> 8
A --> 10
F --> 15
10 --> 16
15 --> 21
20 --> 32
A0 --> 160
FF --> 255
100 --> 256
200 --> 512

Hex value from right to left:
the most right has multplier of 16^0 = 1
then 16^1 =16
then 16^2 = 256
then 16^3 = 4096
then 16^4 = 65536
...

Klaus

3. ## Re: How to calculate temperature value

That is easy. Here is th example which you can get from Analog devices web site:

 Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 float ADXL362_ReadTemperature(void) {     unsigned char rawTempData[2] = {0, 0};     short         signedTemp = 0;     float         tempCelsius = 0;       ADXL362_GetRegisterValue(rawTempData, ADXL362_REG_TEMP_L, 2);     signedTemp = (short)(rawTempData[1] << 8) + rawTempData[0];     tempCelsius = (float)signedTemp * 0.065;         return tempCelsius; }

Using your values that would be 28.6 degrees.

1 members found this post helpful.

4. ## Re: How to calculate temperature value

Thanks for your reply. But could you please explain how did you get 28.6 degree (by equation)? I am not expert in programing part.

5. ## Re: How to calculate temperature value

Hi,

In line 8 cfant forms one 16 bit value of the two 8 bit values:
0x01 is shifted 8 bits left to get 0x0100, then 0xB3 is added giving a value of 0x01B3.
= 0 × 4096 + 1 × 256 + 11 × 16 + 3 = 435 ( there is no need to form it to decimal value, because the microcontroller calculates with binarv values. A hex digit is represented directely by 4 binary digits, therefore there is no need to transform.

435 × 0.065 = 28.275 . This value is stored i a floating point variable.

Klaus

1 members found this post helpful.

6. ## Re: How to calculate temperature value

Thank you very much KlausST. I got it. So now I understand that my output is correct. So I think it's time to do "Mark as Solved".

--[[ ]]--