# [SOLVED]How to calculate temperature value

Status
Not open for further replies.

#### Kick

##### Full Member level 6
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.

#### KlausST

##### Super Moderator
Staff member
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

#### cfant

##### Full Member level 3
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
{
unsigned char rawTempData[2] = {0, 0};
short         signedTemp = 0;
float         tempCelsius = 0;

signedTemp = (short)(rawTempData[1] << 8) + rawTempData[0];
tempCelsius = (float)signedTemp * 0.065;

return tempCelsius;
}

Using your values that would be 28.6 degrees.

Last edited by a moderator:
Kick

### Kick

points: 2

#### Kick

##### Full Member level 6
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.

Last edited:

#### KlausST

##### Super Moderator
Staff member
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

Kick

### Kick

points: 2

#### Kick

##### Full Member level 6
Thank you very much KlausST. I got it. So now I understand that my output is correct. :smile: So I think it's time to do "Mark as Solved".

Status
Not open for further replies.