Adapt MELABS DS18B20 example to show negative temperatures?
Hello.
I'm using the melabs sample code for DS18B20 and it works fine.
However, as it states:
Code:
OWOut DQ, 1, [$CC, $44] ' Start temperature conversion
waitloop:
OWIn DQ, 4, [count_remain] ' Check for still busy converting
If count_remain = 0 Then waitloop
OWOut DQ, 1, [$CC, $BE] ' Read the temperature
OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]
' Calculate temperature in degrees C to 2 decimal places (not valid for negative temperature)
temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
What should be fixed there to display negative temperature properly?
As I've read DS18B20 datasheet, negative temperature output will always have 4 MSB bits set to 1111. But what's wrong with the above conversion formula?
Re: Adapt MELABS DS18B20 example to show negative temperatures?
Re: Adapt MELABS DS18B20 example to show negative temperatures?
I just had no idea same can be applied to DS18B20 readings :D
Re: Adapt MELABS DS18B20 example to show negative temperatures?
Quote:
What should be fixed there to display negative temperature properly?
As I've read DS18B20 datasheet, negative temperature output will always have 4 MSB bits set to 1111. But what's wrong with the above conversion formula?
you may have read the DS18B20 datasheet but you are using code for a DS18S20 so the first step is work out what you really have and then use the correct method
Re: Adapt MELABS DS18B20 example to show negative temperatures?
Well I have it running with DS18B20 and it displays positive temperatures just fine...
Re: Adapt MELABS DS18B20 example to show negative temperatures?
I also used this:
https://melabs.com/samples/LABX1-16F...emp_DS1822.htm
But it is much slower.
And I don't need high precision, this is just room temperature thermometer, 1C precision is ok.