This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

HDC2010: Handling Negative values

Part Number: HDC2010
Other Parts Discussed in Thread: LM75B

Hello,

 

I am using HDC2010 sensor. I have gone through SNAA312 and I have few queries.

 

1) How to handle negative values. Whether negative values are in Two’s compliment and if I copy into int16_t will it be taken care automatically ?

 

int16_t i16TempActData = 0;

memcpy(&i16TempActData, &p8Data[0], 2); // Low and Higher byte of temperature

 

2) Humidity will be between 0 to 100. So there won’t be any negative value. Still it can have decimal part, so that whether we need to handle positive number with decimal part ?

 

Thanks & Regards

Vishnu Beema

  • Dear Vishnu - 

    you should get back two bytes each for each measurement type, so that would be 0x00 0x00 to 0xFF 0xFF (which would equate to 0d to 65536d)

    then to do the math (inside your MCU) for each type of reading, and you would get range from 0% to 99.998%RH for humidity and from -40C to 124.9975C for temp

  • Thank you. Now I got. In some chips, value greater than '0x80 00 00 00' (MSB as 1) will represent Negative value in 2's Compliment. Whereas here, its just a uint16_t and '-40' in formula will take care of negative temperatures.

  • Great - 

    Vishnu - 

    i am not sure where the 2's complement is being used by you. 

    the formula for converting the humidity is: 

    RH% = (decimal value of hex output from HDC20x0 I2C / 65536) * 100

    from this equation, no negative number can be derived, as 0 divided by anything is 0 and 0 multiplied by anything is also 0, therefore the lowest value possible is:

    0x00 0x00 (from humidity registers) = 0d

    then doing the math operations: 

    0/65536 = 0

    0 * 100 = 0%RH

  • Thank you for your inputs.

    For your reference, LM75B Digital temperature sensor will use 2's Compliment for Negative temperatures.

  • Thanks - the HDC devices do not use the 2's complement.

    the calculation for temp from this device is: 

    temp = ((temp value in decimal, from hex values returned / 65536) * 165) - 40