Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

[SOLVED] How to calculate temperature value

Status
Not open for further replies.

Kick

Full Member level 6
Joined
Sep 27, 2010
Messages
341
Helped
15
Reputation
30
Reaction score
15
Trophy points
1,298
Location
India,Bangalore
Activity points
3,137
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.

http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL362.pdf
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
18,076
Helped
4,053
Reputation
8,106
Reaction score
3,968
Trophy points
113
Activity points
119,284
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
 

cfant

Full Member level 3
Joined
Apr 4, 2001
Messages
188
Helped
25
Reputation
50
Reaction score
6
Trophy points
1,298
Location
California, USA
Activity points
1,151
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/tools-software/uc-drivers/renesas/adxl362

Using your values that would be 28.6 degrees.
 
Last edited by a moderator:
  • Like
Reactions: Kick

    Kick

    points: 2
    Helpful Answer Positive Rating

Kick

Full Member level 6
Joined
Sep 27, 2010
Messages
341
Helped
15
Reputation
30
Reaction score
15
Trophy points
1,298
Location
India,Bangalore
Activity points
3,137
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
Joined
Apr 17, 2014
Messages
18,076
Helped
4,053
Reputation
8,106
Reaction score
3,968
Trophy points
113
Activity points
119,284
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
 
  • Like
Reactions: Kick

    Kick

    points: 2
    Helpful Answer Positive Rating

Kick

Full Member level 6
Joined
Sep 27, 2010
Messages
341
Helped
15
Reputation
30
Reaction score
15
Trophy points
1,298
Location
India,Bangalore
Activity points
3,137
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.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top