Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Ds18s20 and cable capacitance

Status
Not open for further replies.

NorthGuy

Well-Known Member
I looked up information and sample circuits of DS18S20 temerature sensors connected to PIC microcontrollers, such as this one. They show the schematics where PIC's pin is connected directly to the sensor with pullup resistor to VDD. There are many and all seem the same, including manufacturer's application notes. They all don't mind using longer wires, sometimes 300 ft or longer, and only recommend using smaller (less resistance) pullup resistors as the cable gets longer.

The problem I see with this is that the PIC's output pins are rated for 50 pF capacitive load, while cables typically have capacitance of 12 pF/ft. So, 30 ft cable that I'm going to use will be 360 pF, maybe more. When connected directly to the pin, it'll be over 7 times the maximum allowable capacitive load, and must be harmful/destructive to the PIC. With 300 ft, you get 3600 pF! Still, everyone connects it that way.

How people can use such long cables without worrying about harmful effects of high capacitive load?
 
What harmful effects of high capacitive load?

The 50pf limit on the PIC pin is the max capacitance the PIC can drive and still get some specified rise/fall time. If you are willing to wait longer, the PIC can source/sink a maximum current (25mA?) which will charge/discharge the cable capacitance, regardless of how large it is. You will just have to wait longer for the line to settle.
 
Last edited:
You can get line driver ic's meant to run long lines.
I have run a ds18b20 over 20 foot with no issues, allthough from what you say it probably runs the pic out of spec.
 
I have few working, but they're all relatively short. The longest, in the garage, is 12 ft, which I only installed recently. It does work, but gives me checksum and "85" error from time to time.

I'm now installing one in the house with 30 ft run upstairs. It didn't work with 4.7k pullups at both ends, so I had to replace one wih 2.2k, so the total pullup resistance is about 1.5k now. This works about 50% of times. That is Ok. It didn't damage the controller during my tests. I measured cable capacitance and it's 1.3nF.

Mike: I hope you're right and these ratings are for speed only. However, some level of capacitance will be harmful. The only reference in their spec sheet I found was 50pF.

dr pepper: It wouldn't be easy to add an IC because I already have the board. I could add a series resistor, but it would form a voltage divider with pullup resistors. If I want to limit current to 4mA (PIC24H spec), I need about 1k resistor. But with 1.5k pullup resistance, it will only pull it half-way down. So, I started looking at what people do, and looks like they don't worry about capacitance and just connect everything directly.
 
Where did you read 4 mA per pin? As far as I can see it's 25 mA per pin.

What speed are you running the I²C at? Have you considered slowing it down? Even below 100 kHz.

Mike.
 
Are you using parasite power or third wire power?
 
Where did you read 4 mA per pin? As far as I can see it's 25 mA per pin.

On the spec sheet. Microchip's document # 70293F on page 283 table entitled "Absolute Maximum Ratings". The 50pF is from the same document, page 294. Table entitled "Capacitive Loading Requirements on Output Pins".

What speed are you running the I²C at? Have you considered slowing it down? Even below 100 kHz.

Thank you Mike. The sensor uses proprietary 1-wire protocol, which is very slow, so speed is not a problem. I'm only worrying that high cable capacitance may damage PIC's pins.
 
The dreaded 85.5 degree error, I had a few sensors that did this even with 3" of wire to the ic.
You can get ds18b20's from china encapsulated in stainless steel tubes with 10 meters of cable attached, so there will be a way.
Could you use a comparator input on the pic, you wouldnt need to wait as long for the capacitance to charge if you had a low threshold voltage.
 
First, I am sure that the PIC doesn't care if it sinks more than 25mA for a few usec. If you are worried about it, this should work:

DF89.jpg
 
Thank you everyone.

I guess I shouldn't worry about cable capacitance, so I'll leave it as it is. If something breaks, I'll redo it with mosfets and separate sensing pin as MikeMI suggested.
 
... If something breaks, I'll redo it with mosfets and separate sensing pin as MikeMI suggested.

The Mosfets M1 and M2 I show in the dashed boxes are not separate components that you buy; they represent the output stages of the PIC and the existing sensor(s). M1 is the NFET inside the PIC's pin driver. M2 is the NFET inside the sensor's driver.

The PIC port pin only drives the bus low (never high). The sensor's output stage only drives the bus low (never high). The only thing that ever drives the bus high is the pull-up resistor R1 . Adding the series resistor R3 limits the current surge as M1 discharges the bus capacitance. C1 is the total cable (and sensor) capacitance. Normal twisted pair has a capacitance of 25 to about 50pF per foot.
 
The Mosfets M1 and M2 I show in the dashed boxes are not separate components that you buy; they represent the output stages of the PIC and the existing sensor(s). M1 is the NFET inside the PIC's pin driver. M2 is the NFET inside the sensor's driver.

Sorry I misread it. I can add a series resistor right now. My pullup is about 1.5K, so I cannot do more than 100 Ohm or so, but I guess it is better than nothing.

Actually, the idea of adding an extra mosfet to drive the line low is good. It will completely isolate PIC from the line. Of course, I cannot use the same pin to sense the line, but I can do it with a separate pin. If I ever do these sensors through a long wire, that's what I'm going to do.
 
... My pullup is about 1.5K, so I cannot do more than 100 Ohm or so...

Are you sure that the sensors can sink enough current to overcome the 1.5K pull-up? The sensor data sheet should specifiy how low you can go...
You may have created a problem by reducing the pull-up from 4.7K to 1.5K?
 
Are you sure that the sensors can sink enough current to overcome the 1.5K pull-up?

That is a good question. Data sheet says the sensor can sink 4mA. At 3.3V 1.5k is only 2.2mA, so should be ok for both the sensor and PIC. 4.7k (even 2 of them, one on each end) do not pull up against the long cable capacitance fast enough, so I had only 5% success rate. It improved when I replaced one of 4.7k with 2.2k.
 
That is a good question. Data sheet says the sensor can sink 4mA. At 3.3V 1.5k is only 2.2mA, so should be ok for both the sensor and PIC. 4.7k (even 2 of them, one on each end) do not pull up against the long cable capacitance fast enough, so I had only 5% success rate. It improved when I replaced one of 4.7k with 2.2k.

That doesn't make sense. Look at the sim. It only takes ~12us for the 2.2K to charge 1500pF. You are likely clocking too fast.
 
Mike, have you looked at the timing for a zero read slot? See fig 2 of https://ww1.microchip.com/downloads/en/appnotes/01199a.pdf

Mike.

Mike, look at page 13 and 14 of the **broken link removed**. The "real" timing is there (not uChip's version). The high period between time slots can be any length up to infinity. The time-constant formed by the pull-up resistor and the bus capacitance is totally non-critical as long as the PIC code is written in the appropriate way. If the OP is having issues related to the rise-time of the bus voltage, then the PIC code is not written properly...
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top