Page 1 of 1

Problem reading negative temps. using DS18B20

Posted: Sun Apr 07, 2013 7:43 pm
by krimles
Hi - I cannot figure out what the problem is reading negative temperatures reliably using the DS18B20. :o
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.

Re: Problem reading negative temps. using DS18B20

Posted: Sun Apr 07, 2013 8:12 pm
by JohnCrow
Hi
Have you tried searching the forums for DS18B20, there are quite a few posts and example programs on here.

Re: Problem reading negative temps. using DS18B20

Posted: Sun Apr 07, 2013 10:08 pm
by krimles
Yes, I have looked over those posts but none help my problem. Still stuck.
Positive temps. work just fine but negs. don't. Were the one-wire macros tested with DS18B20s and neg. temps? It's almost like there is a bug somewhere or I'm really thick.
The original reason I purchased Flowcode was to use this temperature sensor figuring it would be easy. I have been at this for 4 days now with no solution. I really need help here! Thanks.

Re: Problem reading negative temps. using DS18B20

Posted: Sun Apr 07, 2013 11:05 pm
by medelec35
I know its not the same device but I created a flowchart for TC74 which displays negative temperatures correctly.
There is a small possibility the calculations may work for you as well?

Re: Problem reading negative temps. using DS18B20

Posted: Tue Apr 09, 2013 6:47 pm
by krimles
Thanks for all your help guys - it is now running just fine!
Problem was due to my programming error and also a partially damaged temp. sensor. It would read positive temps. OK and negative temps. only down to -10C. This really threw me for a loop :shock:
Attached is the program for the D18B20 sensor in case anyone needs to do this in the future.