Latching relay & PIC buffer question

Started by Ethan, November 22, 2005, 10:26:29 AM

Previous topic - Next topic

Ethan

Most PICS can sink or source up to 25mA.  Most single coil, low signal, latching relays require only 20mA.  So why do you need a buffer?
-ethan

R.G.

(a) the total current in the PIC package has to be less than 100ma, so the relay(s) and any other loading have to be lower that that total
(b) relays have inductive spikes when turned off that can kill a PIC. It's simple to isolate the spikes with a separate driver. A $0.04 transistor is cheaper to replace than a PIC.
R.G.

In response to the questions in the forum - PCB Layout for Musical Effects is available from The Book Patch. Search "PCB Layout" and it ought to appear.

Peter Snowberg

I don't know how they are today, but I was never able to kill a PIC I/O pin with a little relay. The only protection I use is a reverse 1N5818 across the coil.

I used the 2N4401 as a relay driver because we had lots of them around the shop. 2N3904 & 2N2222 also work great.
Eschew paradigm obfuscation

The Tone God

I bet that 25ma is an absolute max rating and not constant supply. That is probably at the top end of the supply (5v ?). As the power supply voltage lowers so does the uC abilty to deliver current. I would also suspect that it can only supply that on a per pin basis before the uC complete max suggest at 100ma.

As for the protection of the pin(s) I bet there are clamping diodes on the pin. PIC are REALLY hard to kill. That being said that doesn't mean you should be lazy with your protection. Use driver circuit. Then you can drive higher current and voltage relay coils. If you need you can use an IC like the uln2004 for a relay driver to save space and building time.

As always the datasheet is the bible so read it and I bet some of those fancy graphs will give I/O pin current capabilties.

Andrew

Peter Snowberg

With a PIC16C57, I had a board pulling  about 40ma out of each of four I/O pins for months (powering LEDs). No failure, it got thrown away with other "trash".  :icon_confused:
Eschew paradigm obfuscation

Ethan

Actually, I have been using the following driver cicuit:
http://putfile.com/pic.php?pic=11/32516224952.jpg&s=x12

The zener's clamp the spikes down quite a bit.  I actually scoped the spikes at more than 200 volts! The 4.7v zener's clamped these down to about 12v. I don't know why it isn't clamped to 4.7vz but that's another story.  ANyway, the relay is actuated fine and the pic is fine, but I do get some clicking noise and I thought maybe using a transistor driver would help with that.  Or maybe it's the cheap NAIS relay's I got for $1.50.
-ethan.

R.G.

That was kind of my point. Inductive spikes are nasty things, and sneaky. I've never killed a PIC either, and I abuse them daily. But there's no point in building in a point of failure.

I looked, and I was correct - the pin current limit is 25ma for I/O pins, and 100ma for power or ground, as several of us recalled.

In your circuit, I believe that the voltage is limited to the power supply plus the zener voltage, so I can see almost 10V OK. I don't know how it's getting to 12, but like I said, inductive discharge is sneaky.

A driver transistor set up as I did for my latching relay circuits is not just a current switch. It's a rise/fall time slower downer to keep the sudden voltage across the coil from being coupled to the audio path as a click. (I seem to type this in every time someone mentions relays.)

The transistor circuit with a resistor in series with the base and a capacitor from the collector to base acts like a saturated switch when there is no transition. When the voltage on the base drive resistor changes, the inverted amplified voltage on the collector opposes the movement of the base. The cap can't supply current forever, so what it does is integrate the drive pulse into a ramp up or down, following the input waveform, just like an opamp integrator. The relay coil then sees a rising ramp of voltage.

In a latching relay you can't slow this down too much or it won't switch, but you can get up to ramps of a few milliseconds, and that's usually enough to keep it out of the audio.

As parting shot, I believe you can drive the relay coil from one of the uP pins in series with a capacitor. I can't remember who posted that here. It seems to work.  That would let you run up to three switches and three relays from the PIC.
R.G.

In response to the questions in the forum - PCB Layout for Musical Effects is available from The Book Patch. Search "PCB Layout" and it ought to appear.

jrem

howbout inrush current on inductive loads like filimants, transformers, coils, etc?  the resistance is zero for a short time, so you're going to suck all the current out of the pin until the emf rises.

don't know if that means much, but that's the same reason you use slow-blow fuses on tube amps . . .   

Transmogrifox

Quote from: jrem on November 22, 2005, 06:11:09 PM
howbout inrush current on inductive loads like filimants, transformers, coils, etc?  the resistance is zero for a short time, so you're going to suck all the current out of the pin until the emf rises.

don't know if that means much, but that's the same reason you use slow-blow fuses on tube amps . . .   

"Inrush current" would be more of a capacitive problem.

For inductive loads you want to avoid changing the current quickly.  If you have a tube amp output transformer energized at the tube's bias current, then instantly blow a fuse, there is a bunch of energy stored in the transformer coil, and the fluid flow just stopped.  It's going to react by developing a very high voltage across its terminals, thus subjecting everything connected to its power supply to up to thousands of volts and it will either deliver its energy to whatever circuit is connected to the power supply, or keep rising in voltage until something blows.

With a slow-blow fuse the power and low impedance path through the power supply to ground is not instantly removed, so the energy can be somewhat absorbed over a longer period of time. 

Here's an  analogy:
If there's a train passing through and you want to get on, you get in the train car, the locomotive powers up and accelerates you to 50 mph and your body is perfectly intact and there is no problem with you traveling along at 50 mph.  Now suppose your friendly neighborhood villain built a big brick wall in the middle of the tracks.  When you in the train hits that brick wall, you go from 50 to zero in seconds and your head "asplode".

If the villain was a kind villain, he would make a big wall of fluffy (not spun or packed) wool, so though you would stop abrubtly, it would be slowly enough that there wouldn't be conditions that would exceed your absolute maximum acceleration ratings.

Another analogy would be the same as accelerating in a race car  to 200 mph vs. strapping a jet engine to your back and accelerating to 200 mph.

Therefore, pulling the power plug on your amp would be like shutting the engine off on the train--after some time all the stored kinetic energy in the train would be dissipated and it would coast to a stop.  Likewise, all the stored electrical energy is slowly dissipated through the input transformer coil.

Blowing a fuse disconnects this coil, or at least does not allow that return to ground to be low impedance by any means, so this is like building a stone wall in the middle of the tracks by analogy.  The energy has to go somewhere, and an inductor responds by trying to deliver it very quickly if you shut off its power supply.  A professor of mine made a door-knob shocker on this principle.  He used a high-voltage rated MOSFET for a switch, an inductive coil, diode, and capacitor.  Turn on the FET and get some current in the inductor, then quickly shut it off.  The inductor kicks and charges the cap through the diode.  When the cap is connected to a doorknob, a guy would about get kicked on his but to try to open the door :icon_twisted: :icon_twisted:

DISCLAIMER:  Don't make one of these unless you know what your doing and you really really really know what is well within safety range for the human body.  A device such as this can be fatal if you use a capacitor  and inductor that are too large and store more energy than what a person can handle in a given time period.  I recommend that you don't do this to your buddies.  Tazers have killed people, and they are even very well designed to supposedly be "safe".
trans·mog·ri·fy
tr.v. trans·mog·ri·fied, trans·mog·ri·fy·ing, trans·mog·ri·fies To change into a different shape or form, especially one that is fantastic or bizarre.