Author Topic: Driving latching relay with attiny85  (Read 10417 times)

0 Members and 1 Guest are viewing this topic.

Offline dadlerTopic starter

  • Supporter
  • ****
  • Posts: 851
  • Country: us
Driving latching relay with attiny85
« on: February 01, 2015, 11:04:14 pm »
Hi all-

I am working on a circuit similar to this:



However, I am concerned about inductive transients when the (single coil latching) relay current pulse abruptly stops.

I guess an H-bridge or equivalent, or something like a ULN2003 would certainly work, but seems like overkill for this application. Trying to keep the parts count/cost minimal. I also considered back to back zeners, but I don't think this will actually protect the inputs.

I contacted the designer of the above circuit, and he claims transient protection is not necessary (didn't give a reason).  I thought maybe he was doing something clever in software, just a guess.

Here is the datasheet for the relay I am using: EA2-5SNJ (single coil latching) http://www.mouser.com/ds/2/283/ea2-1419.pdf

Any input would help--I am a beginner.
« Last Edit: February 01, 2015, 11:07:02 pm by dadler »
 

Offline JoeN

  • Frequent Contributor
  • **
  • Posts: 991
  • Country: us
  • We Buy Trannies By The Truckload
Re: Driving latching relay with attiny85
« Reply #1 on: February 02, 2015, 04:06:57 am »
So you are using pins 6 & 7 basically as an H-bridge, setting one high and the other low and reversing the polarity to drive this relay?  And it works right now? - as in there is enough current and you are not exceeding the ICs current sourcing/sinking specs?  Well, if so that's great.  The one thing is that I have never heard of anyone recommending driving any inductive load off an Atmel microcontroller or any microcontroller that isn't also a motor driver IC (Freescale does some of these) without protection.  I found this and it seems it is the industry standard protection circuit for an H-bridge.  It requires 4 diodes rather than one, but otherwise works in the same fashion.

This is showing a 74LS244 doing the driving but you just substitute your pin 6 for the junction of pin 12 and 14 and pin 7 for the junction of 16 and 18 on that GIF.  This all assuming that your microcontroller's pins are not being overdriven right now.


« Last Edit: February 02, 2015, 04:10:47 am by JoeN »
Have You Been Triggered Today?
 

Offline bktemp

  • Super Contributor
  • ***
  • Posts: 1616
  • Country: de
Re: Driving latching relay with attiny85
« Reply #2 on: February 02, 2015, 10:26:12 am »
It is hard to say if driving an inductive load is within specs or not, but it works. I have done simillar things multiple times without problems. But I would not use it on a product where a failling microcontroller can have expensive results.
Since an AVR is CMOS, it has internal protection diodes on all pins. But the datasheet does not give a maximum current rating for those.
One solution might be using only low and high instead of tristate. To remove power from the coil instead of switching the outputs to tristate, simply drive both pins low. This shorts both coil pins together and gives the stored energy a path to discharge without generating any spikes.
 

Offline linux-works

  • Super Contributor
  • ***
  • Posts: 1999
  • Country: us
    • netstuff
Re: Driving latching relay with attiny85
« Reply #3 on: February 04, 2015, 06:33:58 am »
one of the products I designed uses latching relays (for an audio attenuator).

http://www.amb.org/audio/delta1/

schematic and even code is available (arduino) - maybe that will give you some hints.


Offline JoeN

  • Frequent Contributor
  • **
  • Posts: 991
  • Country: us
  • We Buy Trannies By The Truckload
Re: Driving latching relay with attiny85
« Reply #4 on: February 04, 2015, 05:21:26 pm »
one of the products I designed uses latching relays (for an audio attenuator).

http://www.amb.org/audio/delta1/

schematic and even code is available (arduino) - maybe that will give you some hints.
That circuit uses ULN2003s, which I think is the way to go personally, but the original poster specifically said:

I guess an H-bridge or equivalent, or something like a ULN2003 would certainly work, but seems like overkill for this application.
I think he doesn't want to use a 7 channel IC just for one channel for aesthetic reasons.  Those ICs are certainly cheap enough these days.
Have You Been Triggered Today?
 

Offline linux-works

  • Super Contributor
  • ***
  • Posts: 1999
  • Country: us
    • netstuff
Re: Driving latching relay with attiny85
« Reply #5 on: February 04, 2015, 05:48:47 pm »
my point was to show the 'biasing trick' of keeping both relay lines up close to Vcc and then touching one end to ground (briefly! lots of current flows so it should be a millisecond or so, not very long at all) will latch it.

the ULN was used for easy integration and even though it has more 'lines' than you'd need, its still a small enough chip and cheap enough.  it has the built-in diodes protections and so its really easy to use.

anyway, it was just an example to show how it can be done.  we've been shipping boards and the circuit has been built by hundreds of people (I get email each time the source is downloaded) and so its a proven reliable circuit design.

Offline cosmicray

  • Frequent Contributor
  • **
  • Posts: 308
  • Country: us
Re: Driving latching relay with attiny85
« Reply #6 on: February 04, 2015, 06:01:27 pm »
Here is the datasheet for the relay I am using: EA2-5SNJ (single coil latching) http://www.mouser.com/ds/2/283/ea2-1419.pdf
Single coil latching usually requires a positive voltage to latch, and a negative voltage to unlatch. Another way of thinking is that you reverse the leads to the single coil, as all you really are aiming for is to reverse the voltage across the coil. The datasheet I'm looking at shows both + and - on each connection for a single coil latching example.
it's only funny until someone gets hurt, then it's hilarious - R. Rabbit
 

Offline linux-works

  • Super Contributor
  • ***
  • Posts: 1999
  • Country: us
    • netstuff
Re: Driving latching relay with attiny85
« Reply #7 on: February 04, 2015, 06:26:36 pm »
the trick I used was to keep both wires tied to plus and then touch an opposite side to ground (or the other one to toggle).  this creates a polarity swap, pretty much, and that's the trick.

you could also use an h-bridge but no matter what you do, you have to be sure to pulse the relay and be sure its not left with constant current going thru it.

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9946
  • Country: nz
Re: Driving latching relay with attiny85
« Reply #8 on: February 04, 2015, 06:46:20 pm »
Two 1w 4.5v zeners should work wired back to back.
( you get one zeners breakdown plus the others forward drop. So around 5v and above plus -5v and below the current will go into the zeners.
The avr io can handle 5.5v so there is some room.
Its far from ideal, a uln2003 is best, but the zeners is much better than nothing.
« Last Edit: February 04, 2015, 06:49:11 pm by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline macboy

  • Super Contributor
  • ***
  • Posts: 2254
  • Country: ca
Re: Driving latching relay with attiny85
« Reply #9 on: February 05, 2015, 03:08:46 pm »
Two 1w 4.5v zeners should work wired back to back.
( you get one zeners breakdown plus the others forward drop. So around 5v and above plus -5v and below the current will go into the zeners.
The avr io can handle 5.5v so there is some room.
Its far from ideal, a uln2003 is best, but the zeners is much better than nothing.
Sure it can handle +5.5 V w.r.t. ground, but the inductive kick will be -5.1 V (4.5 + 0.6) w.r.t. ground.

I'd suggest that avoiding the fast turn-off is more appropriate. Adding a capacitor across the coil will accomplish this. The coil's sizable resistance (178 ohm) should dampen the LC circuit to prevent oscillation. The size of the cap depends on the coil. Too big and the voltage will drop too slowly; too small and it will still shoot negative for some time (and might ring as well). When it is just right, the voltage will quickly drop to zero without going negative.

Another alternative is... nothing. The relay's coil has 178 Ohm of resistance, so the current at 5 V is just 28 mA. When you release the drive voltage, this current will keep flowing, and it will be shunted to Vcc or ground (depending on how exactly you drive the coil) via the micro's internal protection diodes. Those diodes can't handle much current, but with only brief 28 mA pulses, they might be just fine.
 

Offline dadlerTopic starter

  • Supporter
  • ****
  • Posts: 851
  • Country: us
Re: Driving latching relay with attiny85
« Reply #10 on: February 25, 2015, 10:23:12 pm »
So I got around to throwing this circuit on the scope. It's the exact circuit in the OP.

The uC is issuing a 5ms pulse, driving one output pin high and the other low.

There indeed is inductive spiking going on, but it seems to actually cause the attiny to sink/source the inductive current down to ground/vcc.

This results in ~-2V potential at the uC output pins, which seems like a bad idea.

This current appears to (dis)charge the linear regulator's output cap, resulting in ringing in the LC tank circuit seemingly formed by the coil's inductance and the 78L05 output cap. At least that's my beginner-level analysis, I am probably wrong.

Here is a shot of one of the events in question:



Either way, the circuit seems to work but I still feel uncomfortable about the inductive behavior.
« Last Edit: February 25, 2015, 10:40:06 pm by dadler »
 

Offline ehud42

  • Newbie
  • Posts: 2
  • Country: ca
    • flying low
Re: Driving latching relay with attiny85
« Reply #11 on: February 05, 2023, 01:09:56 am »
Poking at this thread as I'm working on an 'art' project where I'm taking over control of the simple stepper/coil in a clock. It needs to be driven +ve then -ve. I left the coil attached to the original clock circuit board (with the 32k crystal, etc - but battery removed).

The coil needs less than 10mA to work. So well within what the ATTiny data sheet says it can do.
Since the ATTiny can only source around 10mA, do I need a current limiting resistor? (Presumably I'm driving w/ 2x the voltage, so inducing twice the current?)
And I'm concerned about back EMF - so I tried 2x 3.3V Zeners in opposing series


   +--mmmm--+
   |        |
P0-+-z<-->z-+-+
              |
P2------------+



My limited scope (old 100MHz Tektronix) does not seem to show any spike on the trailing edge - with or without the zeners. Might there be protection in the original clock circuit?


(P1 is the builtin LED on the DigiSpark clone I'm using, and I'm using it as a heartbeat - since I'm toggling the clock coil only once every 8,760 seconds)
 

Online ledtester

  • Super Contributor
  • ***
  • Posts: 3036
  • Country: us
Re: Driving latching relay with attiny85
« Reply #12 on: February 05, 2023, 01:53:31 am »
...
The coil needs less than 10mA to work. So well within what the ATTiny data sheet says it can do.
Since the ATTiny can only source around 10mA, do I need a current limiting resistor?
...

I think the GPIO pins are capable of more than 10mA.

The Electrical Characteristics are presented starting on page 161 of the datasheet:

https://ww1.microchip.com/downloads/en/devicedoc/atmel-2586-avr-8-bit-microcontroller-attiny25-attiny45-attiny85_datasheet.pdf

The footnotes at the end of Table 21-1 state:

Quote
4. Although each I/O port can sink more than the test conditions (10 mA at VCC = 5V, 5 mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed:

1] The sum of all IOL, for all ports, should not exceed 60 mA. If IOL exceeds the test condition, VOL may exceed the related specification. Pins are not guaranteed to sink current greater than the listed test condition.

5. Although each I/O port can source more than the test conditions (10 mA at VCC = 5V, 5 mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed:

1] The sum of all IOH, for all ports, should not exceed 60 mA. If IOH exceeds the test condition, VOH may exceed the related specification. Pins are not guaranteed to source current greater than the listed test condition.

So current above 10mA is not guaranteed but may happen.
« Last Edit: February 05, 2023, 01:55:23 am by ledtester »
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9946
  • Country: nz
Re: Driving latching relay with attiny85
« Reply #13 on: February 05, 2023, 02:12:44 am »
If possible it's best to buy latching relays that have a separate coil for each position.
The kind that require reverse polarity are annoying to drive unless you have an AC supply.
« Last Edit: February 05, 2023, 02:15:09 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4036
  • Country: nz
Re: Driving latching relay with attiny85
« Reply #14 on: February 05, 2023, 02:17:10 am »
So current above 10mA is not guaranteed but may happen.

Especially if you're only sourcing or sinking significant current from one pin (of each) at a time.
 

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3700
  • Country: nl
Re: Driving latching relay with attiny85
« Reply #15 on: February 05, 2023, 07:35:49 am »
So current above 10mA is not guaranteed but may happen.

Especially if you're only sourcing or sinking significant current from one pin (of each) at a time.

Looking at the primitive schematic ehud42 provided, he is using two IO pins to drive the coil in both directions, which means 1 pin is sourcing and the other sinking the same current. At the same time an already on the board present LED is lit on another IO pin, but if it is an SMD LED current will be low.

In this scenario it is more the question what the steady state current of the coil is, when in case of some software issue, one IO pin remains high and the other low. If that current is to high it might fry things.

About the zener diodes I would connect them to ground. This way each pin is limited to +3.3V and negative -0.7V.

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4036
  • Country: nz
Re: Driving latching relay with attiny85
« Reply #16 on: February 05, 2023, 08:04:59 am »
So current above 10mA is not guaranteed but may happen.

Especially if you're only sourcing or sinking significant current from one pin (of each) at a time.

Looking at the primitive schematic ehud42 provided, he is using two IO pins to drive the coil in both directions, which means 1 pin is sourcing and the other sinking the same current.

That would be why I very carefully specified one source pin and one sink pin at the same time. And you might get as much as 60 mA in those conditions.

Quote
At the same time an already on the board present LED is lit on another IO pin, but if it is an SMD LED current will be low.

Could well be 1 mA or less, yes.

Quote
In this scenario it is more the question what the steady state current of the coil is, when in case of some software issue, one IO pin remains high and the other low.

The OP's relay data sheet states that it switches in 1-2 ms, and recommends holding the signal for 10 ms to ensure latching. So the steady state current is zero. It requires 100 mW to switch -- it is available in various coil voltages -- so as the 5V version is being used that is 20 mA.

So, strictly speaking, it is above the per-pin rating of the ATTiny, but it is well below the per-port rating, so it should be fine if it is the only significant load being driven in that 10 ms.

Well, that's the OPs data.

The new thread tickler says their stepper motor needs less than 10 mA, so even better.
« Last Edit: February 05, 2023, 08:09:58 am by brucehoult »
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: Driving latching relay with attiny85
« Reply #17 on: February 05, 2023, 09:47:29 am »
Quote
it is above the per-pin rating of the ATTiny
Which per-pin rating are you looking at?  The footnote mentioned is for the output voltages at a particular output current.Elsewhere the "absolute max" rating is listed as 40mA, and the 22-6 "Pin Driver Strength" tables show pretty reasonable voltages even at 20ma source/drain.

Also, the AVRs are well known to source/sink current substantially above 10mA, especially if you're less worried about maintaining near-rail logic levels.

PROBABLY, the ~10mA reverse current spikes you'd expect from a 10mA relay will be adequately dissipated by the "protection diodes" on the IO pins.  And apparently it's a tested implementation.  But of course it would be safer to double the parts cost of the project by adding some higher current H-bridge drivers and a diode bridge. :-)

(and a ULN2003 is a sink-only driver, and isn't useful for driving one of these "reverse polarity to change state" latching relays.)
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: Driving latching relay with attiny85
« Reply #18 on: February 05, 2023, 09:51:02 am »
Quote
double the parts cost
Well, OK.
It looks like you can get an L9110-like H-bridge driver (with internal diodes as well) from Aliexpress for about $0.10...
 

Offline PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 1542
  • Country: au
Re: Driving latching relay with attiny85
« Reply #19 on: February 06, 2023, 07:06:32 am »
Poking at this thread as I'm working on an 'art' project where I'm taking over control of the simple stepper/coil in a clock. It needs to be driven +ve then -ve. I left the coil attached to the original clock circuit board (with the 32k crystal, etc - but battery removed).

The coil needs less than 10mA to work. So well within what the ATTiny data sheet says it can do.
Since the ATTiny can only source around 10mA, do I need a current limiting resistor? (Presumably I'm driving w/ 2x the voltage, so inducing twice the current?)

What voltage is the stepper coil rated at ?
Current alone is not enough - FWIR, simple stepper clocks run from single 1.5V Alkaline cells ?
If the clock is rated for an end-battery + losses of say 1Volt, you have a 100 ohm coil and you should design the AVR to mimic the design drive conditions.

10mA drive is also a bigger ask at 3.3V supply, than it is at 5V supply.
As an example, if the AVR drops 650mV at each driver at 3.3V Vcc and 10mA, you have 2V to play with, to get the required drive, so an additional 100 ohm series resistor could meet that.
 
 
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: Driving latching relay with attiny85
« Reply #20 on: February 06, 2023, 08:53:31 am »
Quote
What [/size]voltage[/size] is the stepper coil rated at ?
The 5V relay mentioned in the OP has a "must operate" voltage of 3.5V.
Obviously if you want to operate on a 3.3V supply, you wouldn't use the 5V relay (a 4.5 and a 3V version are available.)

There are also double-coil versions of the same relay.  I don't know how things like cost would compare, but if you're actually buying new relays (as opposed to picking something up off the surplus market), it seems to me like the double-coil version would use the same number of pins as the single-coil version, with less "design complexity"

 

Online ledtester

  • Super Contributor
  • ***
  • Posts: 3036
  • Country: us
Re: Driving latching relay with attiny85
« Reply #21 on: February 06, 2023, 09:47:23 am »
Throwing this out here...

This TE app note describes how to drive a a latching relay with a series capacitor. This allows you to use an ordinary relay driver/push-pull output if it can supply the required impulse current:

https://www.te.com/commerce/DocumentDelivery/DDEController?Action=srchrtrv&DocNm=Axicom_AppNote_5&DocType=CS&DocLang=EN

I found it in this Kerry Wong blog post:

http://www.kerrywong.com/2014/12/12/how-to-drive-a-latching-relay/

and he has additional discussion in this video:

How to Drive a Latching Relay -- Kerry Wong
https://youtu.be/cCYUpTyl3BA
 

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3700
  • Country: nl
Re: Driving latching relay with attiny85
« Reply #22 on: February 06, 2023, 09:58:29 am »
For the new question from

......

the capacitor would simplify things. Just a single pin of the MCU and less risk with one pin stuck high and the other low.

It is funny though to see how this resurrection of old threads with new questions leads to answers to the original question.  :-DD


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf