+ Post New Thread
Results 1 to 6 of 6

27th May 2015, 11:59 #1
 Join Date
 Sep 2010
 Location
 India,Bangalore
 Posts
 341
 Helped
 15 / 15
 Points
 3,261
 Level
 13
How to calculate temperature value
Hii,
How to calculate temperature value from hexadecimal output. I am using ADXL362 accelerometer(inbuilt temp.sensor). Getting result of B3 01. Resolution is 12bit.
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.
http://www.analog.com/media/en/techn...ts/ADXL362.pdf...VIPU (Very Important Person in Universe) ...lol

Advertisement

27th May 2015, 15:33 #2
Awards:
 Join Date
 Apr 2014
 Posts
 15,765
 Helped
 3590 / 3590
 Points
 77,800
 Level
 68
Re: How to calculate temperature value
Hi,
you are asking about calculating form hex into decimal?
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

27th May 2015, 20:48 #3
 Join Date
 Apr 2001
 Location
 California, USA
 Posts
 188
 Helped
 25 / 25
 Points
 4,634
 Level
 16
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; }
http://wiki.analog.com/resources/too...enesas/adxl362
Using your values that would be 28.6 degrees.Last edited by BradtheRad; 28th May 2015 at 05:19. Reason: Added code tags
1 members found this post helpful.

28th May 2015, 05:10 #4
 Join Date
 Sep 2010
 Location
 India,Bangalore
 Posts
 341
 Helped
 15 / 15
 Points
 3,261
 Level
 13
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.
Last edited by Kick; 28th May 2015 at 05:18.
...VIPU (Very Important Person in Universe) ...lol

28th May 2015, 06:15 #5
Awards:
 Join Date
 Apr 2014
 Posts
 15,765
 Helped
 3590 / 3590
 Points
 77,800
 Level
 68
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.

28th May 2015, 06:40 #6
 Join Date
 Sep 2010
 Location
 India,Bangalore
 Posts
 341
 Helped
 15 / 15
 Points
 3,261
 Level
 13
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".
...VIPU (Very Important Person in Universe) ...lol
+ Post New Thread
Please login