Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

[SOLVED] How to calculate temperature value

Status
Not open for further replies.

Kick

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

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

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
 

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;
}



https://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
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:

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
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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top