DS18B20 thermostat - Page 1
Forum section: electronics / projects

author: wicket
author_rank: Contributor
timestamp: December 08, 2014, 03:28:51 pm
content: I've build a thermostat using PIC18F4520 and DS18B20 temperature sensor.My problem - every once in a while an incorrect temperature gets calculated. For example: temperature is 25.0 °C and in approx. 95% of the time the incoming value is correct. Other 5% of the time, i get random values from 0.00 °C to 99.9 °C, which is annoying if you try to control something.I suspect the problem might be a timer interrupt, which I use to update a 3-digit 7-segment display. Maybe the interrupt breaks the 18B20 temperature calculation routine, where precise timing is cruical?How can I disable a timer interrupt within one cycle (while processing the temperature)? Or is there an easier workaround, where I could somehow ignore incorrect values?

author: Galenbo
author_rank: Super Contributor
timestamp: December 08, 2014, 03:32:16 pm
content: Quote from: wicket on December 08, 2014, 03:28:51 pmThere sure is, if you do some error checking on the value.If you read out at 1 HZ, let's say it's impossible to have a value that is more than 5degC different from the previous one.You can also log the incorrect values, often their LSB's are always the same, make a filter on that.What does the CRC error correction say when there are wrong values?The trouble I had was reading out all serial numbers when there were more than 6 sensors in the network.

author: leppie
author_rank: Frequent Contributor
timestamp: December 08, 2014, 03:46:18 pm
content: Quote from: wicket on December 08, 2014, 03:28:51 pmInterrupts can mess with the time.Why not set some state when with with the 18B20 that you can check for in expensive interrupts?

author: wicket
author_rank: Contributor
timestamp: December 08, 2014, 05:29:13 pm
content: I've made a comparison of current temp. value and temp. from previous cycle. If there is more than 1 °C difference, I skip the program etc.It works, but I find it somehow MacGyverish...

author: mikerj
author_rank: Super Contributor
timestamp: December 08, 2014, 05:36:17 pm
content: Quote from: wicket on December 08, 2014, 03:28:51 pmUndoubtedly.Quote from: wicket on December 08, 2014, 03:28:51 pmWhy do you need to disable interrupts within a single cycle? You only need to disable interrupts for the duration of a single 1-Wire bit read or write (or bus reset). The protocol will tolerate variable time between bit reads and writes.

author: DmitryL
author_rank: Regular Contributor
timestamp: December 08, 2014, 05:37:58 pm
content: Quote from: wicket on December 08, 2014, 03:28:51 pmEvery man and his dog should read DS1820 datasheet and see how to use CRC checks. Though CRC system in these DS18xx are slightly flawed, because CRC initial value is 0. So, if you have your 1-wire bus shorted to teh ground, you will always get a correct valueIn my version of a similar thermostat I never get wrong values (at least, I never observed them). To do these, I ensure that:- if I use parasitic power mode, I need to supply enough current during temp. conversion (strong pull-up, see datasheet)- don't ask sensor to make temp. conversion too often (see datasheet)- check that the bus is not shorted to the ground or power- check data crc (see datasheet)- perform "high level sanity checks", like the temperatrure should be in range -20...+90 CIf you don't understand why you get incorrect values, this is too bad. Imagine that in a month time something changes somewhere and your system start getting bad reading in 50% of the cases, or 80%...

author: Mr Smiley
author_rank: Frequent Contributor
timestamp: December 09, 2014, 11:32:00 pm
content: "- don't ask sensor to make temp. conversion too often (see datasheet)"Why

author: DmitryL
author_rank: Regular Contributor
timestamp: December 10, 2014, 10:21:14 am
content: Quote from: Mr Smiley on December 09, 2014, 11:32:00 pmBecause if someone read a datasheet, he can find there something like:AC ELECTRICAL CHARACTERISTICSTemperature Conversion Time (Max) 750msAlso, there is such thing as sensor-self heating. During temp. conversion it consumes 1.5 mA that converts to heat and can skew measurements.

author: Galenbo
author_rank: Super Contributor
timestamp: January 06, 2015, 12:48:53 pm
content: Quote from: wicket on December 08, 2014, 05:29:13 pmMost of my programs include McGyverism.It comes in when wanting to make an already working program, relyable.Often there are simply too many possible exceptions, unfrequent glitches, that would take too much time and effort to investigate.I build mostly every program like a state machine, with selfmonitoring of incoming data and other states.When something is wrong it returns to state zero: Init.