Problem reading negative temps. using DS18B20
Posted: Sun Apr 07, 2013 7:43 pm
Hi - I cannot figure out what the problem is reading negative temperatures reliably using the DS18B20.
Positive temps. work just fine, but when trying to read negative temps. there is something erratic going on.
Looking at the DS18B20 data line, I notice that when readings appear to be correct, I see nice bursts spaced 1 second apart (routine is called once per second). When I spray freeze mist on the sensor, the data seems to go crazy for a while when very cold and then as it warms up the spacing is once again at nice 1 second intervals and the negative readings seem OK. Also when erratic I see the 16 bits of data from the sensor held at all 1's (65535) for a while. All 1s should only be present just as the temperature dips negative from 0C at which point any further lowering of temperature would show numbers lower than 65535.
Here is what I do:
Choose sensor from multiplexer (there are 4 more sensors)
Start conversion
Get scratchpad contents
Read temp.
Check bit 12 to see if negative - if so, flip bits, add 1 for 2s complement - output to display with correct format
If positive - output to display with correct format
Processor clock is 8Mhz and macro DisplayRem is called from the mainline every second.
I have disabled everything except this routine to try to isolate the problem.
Does anyone have alternative code I could try? Any help would be greatly appreciated.
Positive temps. work just fine, but when trying to read negative temps. there is something erratic going on.
Looking at the DS18B20 data line, I notice that when readings appear to be correct, I see nice bursts spaced 1 second apart (routine is called once per second). When I spray freeze mist on the sensor, the data seems to go crazy for a while when very cold and then as it warms up the spacing is once again at nice 1 second intervals and the negative readings seem OK. Also when erratic I see the 16 bits of data from the sensor held at all 1's (65535) for a while. All 1s should only be present just as the temperature dips negative from 0C at which point any further lowering of temperature would show numbers lower than 65535.
Here is what I do:
Choose sensor from multiplexer (there are 4 more sensors)
Start conversion
Get scratchpad contents
Read temp.
Check bit 12 to see if negative - if so, flip bits, add 1 for 2s complement - output to display with correct format
If positive - output to display with correct format
Processor clock is 8Mhz and macro DisplayRem is called from the mainline every second.
I have disabled everything except this routine to try to isolate the problem.
Does anyone have alternative code I could try? Any help would be greatly appreciated.