1-Wire Parasitic Power

If anyone has problems getting their Maxim/Dallas DS18B20 or DS18S20 temperature sensors working using parasitic power you might be interested in this. For shorthand I will use sensor = DS18B20/DS18S20.

There a two ways to run a 1-wire sensor: power the Vdd pin (with say 5 volts), or use parasitic power.

The 3 wire solution (ground, data line (DQ), and Vdd) is straight forward, and requires a 4.7K ohm resistor between DQ and Vdd (known as a 'weak' pull-up). Software-wise the Convert and Read Scratchpad commands are seperated either by a.) the temperature conversion time (Tconvert) which varies according to measurement resolution for the DS18B20, typically 750ms for 12 bit resolution, and for the DS18S20; b.) after the Convert command, the device should respond by transmitting 0 while the temperature conversion is in progress and 1 when the conversion is done. Method b.) can't be done in parasitic mode.

The 2 wire/parasitic power solution (aka 1-wire) uses ground and DQ. DQ still requries the 4.7K ohm weak pull-up resistor. However things change between issuing the convert command and the read scratchpad command. The sensor now requires a voltage of value Vdd (e.g. 5 volts) applied to the DQ pin for a period Tconvert (which is 750ms - see aboe), 10us after the convert command was issued. After 750ms the voltage is removed and the scratchpad command issued. During the 750ms a capacitor is charged on the chip and provides the power for the reading the temperature and storing it EEPROM. This may require a peak current of 1.5ms.

Now if you ignore this and just have the 4.7K ohm pull-up, it won't work. Measuring the voltages across the pull-up (Vr) and DQ ((Vdq) gives (actual measurements here):

Vdd = Vout from mbed board = 4.8V

Vr max = 2.96V gives Vdq = 1.84V     Vr min = 0.26V gives Vdq = 4.54V

max current = 0.63mA    min current = 0.055mA

As you can see in practice, current drawn is a lot less, but enough to drop Vdq down to 1.84V. This voltage is the pull-up supply voltage (Vpu), and for parasitic power this should be between 3 and 5.5 volts. Clearly this won't work.

To get 3 volts across the DQ line, 4.8 - 3 = 2.8 volts should be dropped across the pull-up resistor. With a typical current of 0.63mA, this give a value of 2.8/0.63 = 2.9K ohms. The nearest E12 series resistor is either 2.7K or 3.3K ohms.

Using a 3.3K ohm pull-up  we get:

Vr max = 2.15V / Vdq = 2.65V   Vr min = 0.18V / Vdq = 4.62V

with current approx. as above.

Now this should still be too low but I've found using a 3.3K ohm pull-up works, and is enough for parasitic power operation.This is not spec sheet compliant but does for the curious who want to get their breadboard model working.

Final thoughts:

1. Don't use parasitic power. Go ahead and go crazy and run a whole extra wire out to your temperature sensor. Its easier.

2. For breadboarding parasitic power try a 3.3K ohm or 2.7K ohm pull-up rather than the 4.7K ohm recommended. I've found both work. Don't forget to add a 750ms wait between the covert and read scratchpad commands (note: the wait period is same for non-parasitic if you are not reading the bus to see when it goes high).

3. If you are serious about using parasitic power for whatever reason, find a transistor circuit to apply Vdd to the DQ line for the required period. This will of course require another output pin on your processor to trigger it. The spec sheet mentions a MOSFET. As 5V x 1.5mA (max) = 7.5mW is disappated, the MOSFET is overkill.


22 comments

31 Dec 2009

Hello Petras,

 

Thanks for sharing the OneWire program. I own a DS 18S20 and I compiled your software. Everything went smoothly but I get strange T results. Here are the value I get from DEBUG. Did I miss something ? I am using the rugular 3 wire with a 4.7kO

My iniy is :

 

DS18S20 device( 0,0, 0, p25);

LOG :

 

read = 78 1 4b 46 7f ff 8 10 51

TEMP_READ: 188.000000

Temperature: 188.250000

read = 77 1 4b 46 7f ff 9 10 6f

TEMP_READ: 187.500000

Temperature: 187.687500

read = 78 1 4b 46 7f ff 8 10 51

TEMP_READ: 188.000000

Temperature: 188.250000

read = 78 1 4b 46 7f ff 8 10 51

TEMP_READ: 188.000000

Temperature: 188.250000

read = 78 1 4b 46 7f ff 8 10 51

TEMP_READ: 188.000000

Temperature: 188.250000

read = 78 1 4b 46 7f ff 8 10 51

TEMP_READ: 188.000000

Temperature: 188.250000

read = 77 1 4b 46 7f ff 9 10 6f

TEMP_READ: 187.500000

Temperature: 187.687500

read = 78 1 4b 46 7f ff 8 10 51

TEMP_READ: 188.000000

Temperature: 188.250000

read = 77 1 4b 46 7f ff 9 10 6f

TEMP_READ: 187.500000

Temperature: 187.687500

read = 77 1 4b 46 7f ff 9 10 6f

TEMP_READ: 187.500000

Temperature: 187.687500

read = 77 1 4b 46 7f ff 9 10 6f

TEMP_READ: 187.500000

Temperature: 187.687500

read = 77 1 4b 46 7f ff 9 10 6f

TEMP_READ: 187.500000

Of course the temp in my office is not 188°C.
Thanks in advance !
Stephane

31 Dec 2009

Hi Stephane,

I've see readings like that for  a). parasitic power with the wrong pull-up resistor (i.e. too high a value) - however that's not what you are doing, or b). regular (non-parasitic) mode, but the Vdd pin was not connected to 5 volts (I'd put the 5 volt wire on the wrong place on the breadboard).

I'll run a quick test later today with the code compiled for DS18S20 device( 0,0, 0, p25), just to check however, and let you know.

All the best

Petras

 

31 Dec 2009

Hi Stephane,

Just re-compiled with device (0,0,0,p25) and its working ok with the DS18S20. So please check the wiring again.

Petras

31 Dec 2009

Thanks,

Wire is quite simple. I have unplugged everything and started again. Same result. I changed p25 to p21 and the value received is a bit different. I was receiving 200 on p25 and get 194 on p21 with no change in room temp.

Any idea ?

31 Dec 2009

Ok this has got me puzzled. Try compiling with DS18S20 device( 0, 0, 1, p25). This will now run with a 750ms delay between the convert command and the read scratchpad command (as if for parasitic power). See if the readings change for the better. Possibly the convert and read commands are being issued to close together, and this will introduce a delay.

Petras

31 Dec 2009

Sorry ;-)

 

Same result with parasitic TRUE, I get a 194 value

31 Dec 2009

By the way, my unit is a DALLAS 18B20 0940C4 +493AH

31 Dec 2009

I know nothing about these parts, but as a stab 194 / (2^3) = 24.5; Could this be a 9-bit vs. 12-bit resolution problem?

31 Dec 2009

Hi Simon,

I was reading Petras code and I came upon the same thinking. On line 132, there is :

int read_temp = (data[1] << 8) + data[0];

I am reading the unit documentation to see how the two first byte should be read.

31 Dec 2009

Ahhh - 18B20, yes different conversion routine from the 18S20, so yes you are correct. The good news is I just received a couple of 18B20s yesterday, and I was intending to write some code for it over the weekend to update my 1-wire code, due to this issue.  If you can't wait, try the code posted at http://mbed.org/forum/topic/101/?page=1#comment-356 which is for an 18B20.

All the best

Petras

 

31 Dec 2009

Thanks Petras,

Dividing by 16 does the job in line 141. I get 24.7°C now. It there an offset somewhere because this value is about 2°C above the real temp (I have 3 other thermometers to check...)

03 Jan 2010

Stephane,

I have used these devices in the past and found the same as you, approximately 2 degrees above actual.

What I found was that the active current during conversion is a lot larger than the idle current, so I presumed that the device was self heating. As I was doing conversions as fast as possible the device was taking the max current all of the time. I changed the conversions to once per minute and the device operated as per the data sheet, accurate to +/-0.5 degree.

As you have discovered the DS18S20 is 9 bit but the data sheet tells you how to increase the resolution from 0.5 to 0.1 degrees.

03 Jan 2010

I've got my DS18B20 running in a 2 second loop, and it's 0.2 deg C out from that measured by my multimeter temperature probe. Running in a 1 minute loop didn't make much difference, though for a more accurate measurement I would agree on a longer time between readings is better for the reasons stated.

However, the positioning of the multimeter proble is critical. If the probe is positioned below and slightly away from the device, its two degrees out. Postioning it between the mbed processor and the device and the reading is close. My opinion is that the DS18B20 (etc) is sensitive to radient heat (as I found when I put my mug of tea six inches away and the temperature shot up). As I'm running on a breadboard with the device pretty near the processor I guess this is the explanation for the discrepency.

Anyway - further experiments required!!! I need to get the probe maybe 12 inches away and see what happens, and play around more with the interval between measurements.

03 Jan 2010

Just to confirm I now have a DS18B20 placed 6 inches (15 cm) away from the mbed board (and the pull-up resistor) - just three wires running out to it, and I am now reading ambient temperature correctly (DS18B20 - 19.5625 on 12 bit resolution, multimeter temperature probe - 19.6, Zeon Tech 'weather station' 19.8 deg C). 5 seconds between readings.

03 Jan 2010

Petras

I had 2 devices ( both DS18S20) socketed on strip board 2cm apart and about 60cm from processor or any other source of heat. Both devices did a conversion at the same time and were both read, results being displayed on an LCD display. Running at max speed they tracked within 0.1 deg C of each other all the time. After some time, 45 mins to 1 hour, they still showed similar results, within 0.1 of each other, but were higher than ambient by about 2 deg C. I rerun my test with one running at 1 sample per minute and the second as fast as it would go. As before, after some time the fast sampled device was approx 2 deg above ambient whilst the 1/min device was showing close to ambient. Both were run at 1/min sample rate and still tracked within 0.1 deg C of each other. These tests were run several times with the same results every time.

I did not run any tests at any other sample rates as once per minute was sufficient for what I was going to be using them for. So 5, 10 or 20 second intervals may have shown the same results.

As you state I also noticed that they were very sensitive to radient heat so this was taken into account as best as I could - they were always run 60cm from processor board and about 90cm from me.

I was under the assumption that the internal circuit of the B and S variants were the same, only difference being how the data is presented in the registers. The S variant presenting the data the same as the original DS1820 so that it could be used as a direct replacement in existing circuits, but not recommended for new designs.

03 Jan 2010

Thanks,

I figured that self heating was the reason for the 2°C above real temp. How ? In the morning when I start the mbed, the first values are correct, then the unit shift slowly but surely. Errr... I was calling the device every second ;-)

09 Jan 2010

I have a question,

Why don't you use LM35 from national semiconductor for temperature measurement. It has an analog output between 0-5V with 10mV/C and 0.5C accuracy. Mbed has 12 bit ADC. LM35 is cheaper and much more easier to use.

DS18B20 is generally used in motherboards because processors and motherboard controllers(generally) do not have analog inputs. Do you have a specific reason for using DS18B20?

09 Jan 2010

Well... not really, got the DS18B20 for €2.5 so I did not imagine there was something cheaper than that ;-)

09 Jan 2010

LM35 is 1.22£ and DS18B20 is 3.14£ at farnell.co.uk

Well it is not ten times cheaper but it is cheaper ;)

09 Jan 2010

I think people use 1-wire thermometers for a number of reasons, one being that its an easy way to get into trying out the 1-wire bus. The second issue is possibly analog noise, especially when using a breadboard, and being able to implement a suitable ground plane. For one off, experimental use, a few £ difference in price is not a big issue. The main reason I use them is just to play around with the technology. Having said that I'll probably try out a LM35 some day for future reference.

09 Jan 2011 . Edited: 10 Jan 2011

Hi Petras,

Great library; has certainly saved a lot of developing time!
I've been playing around with the DS18S20 (which I think I'm right in thinking only runs on parasitic power as it has no vdd?)
I've been playing around with different pull-up resistor values and 2.7K seems too high still (getting the default 128 degrees output), around 2.4K seems to produce results around those expected. I'm putting this down to my VU being slightly less than the 5V expected; I'm quite new to mbed and the DS18S20, do you know if reducing my pull-up resistor value will produce any ill effects?

21 Aug 2011

Hi Petras,

I kept looking for the most critical part of using DS18S20's in parasitic mode on your statements above and never did see it, so I thought I would add my 2 cents (and 13 years experience using these devices).

To properly work in parasitic mode, the VDD pin of the DS18S20 must be connected to ground. This was not the case for the original version, but is certainly the case for any manufactured after about 1999. It is covered in the spec sheets or app notes somewhere.

Also, I would recommend a pullup resistor iof 1K5 for the DQ line. Works much better.

Regards,

Mitch

You need to log in to post a comment