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.

lm95172 with negative temperatures

Hello,

I am having some trouble understanding the formatting of temperature values below 0. My conversion for positive numbers is fine, I just seem to be off in the negative range.

I understand that bit-15 is for sign. is it correct that if bit-15 is 1, I should then flip all remaining bits and then use the same conversion I would as if bit-15 was 0, and treat that result as a negative?

thanks,

Bruce 

  • Hi Bruce,

    I'm sorry for the delay. I will look into this, and get back to you soon.

    Aaron

  • Hi Bruce,

    The temperature data reading back from the LM95172 is 16-bit, so the bit 15 is a sign temperature: 1 = negative and 0 = positive. When the temperature data is returned, I usually check if the first bit of the MSB is equal to a “1”. Here is how I wrote in the past; however, there are many ways to implement the sign bit.

    //tempData is contained the temperature value

    //tempData is a dummy variable

    int tempData = 0;

    int tempData2 = 0;

    //two’s complement sign bit

    If (tempData & 32768) == 32768)

                    tempData2 = ((((tempData & 32767)^32767) + 1) * -1);

    else

                    tempData2 = tempData;

    return (tempData2/128);

     

    Hope this helps. Please let me know if you have any question.

    Aaron