Problem reading negative temps. using DS18B20

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
krimles
Posts: 8
Joined: Wed Jul 04, 2012 4:10 pm

Problem reading negative temps. using DS18B20

Post 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.
Attachments
emcon_Apr2.fcf
DS18B20 temperature reading
(87.17 KiB) Downloaded 194 times

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times

Re: Problem reading negative temps. using DS18B20

Post by JohnCrow »

Hi
Have you tried searching the forums for DS18B20, there are quite a few posts and example programs on here.
1 in 10 people understand binary, the other one doesn't !

krimles
Posts: 8
Joined: Wed Jul 04, 2012 4:10 pm

Re: Problem reading negative temps. using DS18B20

Post 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.

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: Problem reading negative temps. using DS18B20

Post 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?
Attachments
TC74 Themometer 16F877A V1.fcf
(12.53 KiB) Downloaded 242 times
Martin

krimles
Posts: 8
Joined: Wed Jul 04, 2012 4:10 pm

Re: Problem reading negative temps. using DS18B20

Post 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.
Attachments
DS18B20 Thermometer.fcf
DS18B20 Thermometer
(15 KiB) Downloaded 310 times

Post Reply