8

I am building a simple engage/bypass switch for musical (e.g. electric guitar) effects. The signal switching will be done by a single coil (bistable) latching relay, such as the Panasonic TQ2-L-5V. The user interface is a momentary SPST footswitch. Between the footswitch and the relay is small microcontroller (e.g. ATtiny13), which is responsible for recognizing the switch press, and in turn toggling the relay state (and a status indicator LED).

The single coil (bistable) latching relay works by applying a short current pulse (e.g. 3ms) at a specified voltage (e.g. 5v in the case of the TQ2-L-5V). The direction of the pulse is used to distinguish desired relay state (i.e. if the relay is "on" or "off").

There are examples of this available on the web, e.g:

My concern with these kinds of circuits is that the microcontroller's IO pins are direct-connected to the relay coil. Here is a simplified schematic:

 +------------------+
 | microcontroller  |
 +------------------+
  |                |
gpio-1           gpio-2
  |                |
  |                |
  +--[relay coil]--+

Basically, to set the relay to one state, gpio-1 goes high, and gpio-2 goes low for a short duration. And vice-versa to set the other state.

The question is, should additional circuitry be added to protect the MCU from effects of the relay coil's collapsing field? For example, an H-Bridge?

This circuit certainly works. I have successfully implemented it for several microcontrollers; not to mention the examples above and countless others. But I am concerned about long-term reliability/longevity. Might the (theoretical) infinite voltage temporarily seen by the MCU pins after relay state change (due to the coil's collapsing field) shorten the lifespan of the MCU?

Matt
  • 185
  • 4

4 Answers4

9

There is much room for improvement in your design. It may appear to work with some MCUs but it might really not. Loads that are this heavy and inductive should really not be driven directly from IO pins even if you add protection.

The 5V coil is said to have a 250 ohm coil resistance, so it is a 20mA inductive load.

And data sheet recommends a 10ms pulse at rated coil voltage, so in your case of driving a 3ms pulse with weak IO pins that can't reach rated voltage under 20mA load may not always work.

For your example of ATTiny13, while the absolute maximum IO pin current is 40mA, it means a fault state such as short circuit. The rated current is 20mA, where voltage may be as low as 4.2V instead of 5V on the high side, and what's worse there can be as high as 0.7V on the low side instead of 0V.

So there will not be 20mA over the coil as the IO pins can't provide 5V to that load. Fortunately the relay is rated to only need 3.75V to successfully work, and it only needs about 15mA for that. The ATTiny13 pins are barely rated to provide 15mA at 3.75V to coil under varying temperature conditions, so it may work at room temperatures but not at elevated temperatures. And does not assume any tolerance or deviation down on the 5V supply voltage.

And in fact the IO pins are push-pull outputs, and so they already do count as a H-bridge that drives the coil. It's just that those IO pins are quite a weak as a H-bridge so they can barely drive the coil.

And when you asked if IO pin protection is needed, well, the IO pins of the ATTiny13 already have internal clamping diodes as protection. They just are not meant to be used on purpose for that job so every circuit that relies on them by design is a bad circuit. As there is no other mention how much clamping current they tolerate, likely they can handle the absolute maximum of 40mA, and they withstand voltages up to 0.5V above supply and 0.5V below ground.

So actually, when current flows in the coil, and you set both IO pins low to stop driving the coil, the 20mA still needs to decay down, and while one IO pin sinks it to ground or almost down to 0V through NFET, the other IO pin must source current and it will be clamped to -0.5V by the coil pulling 20mA through protection diode from the other IO pin.

The other option to stop driving the coil is to set both IO pins into high impedance mode. In this case, the coil current needs to decay from the initial value, and so the rated 20mA must flow through IO pins. It will be limited by the internal clamping diodes to about 6V, because one IO pin can be pushed up to 5.5V and the other pushed down to -0.5V by the coil and the current might end up out of the MCU supply pins and it will try to push the supply voltage higher. This must be catched by capacitors or zeners or something before supply rises too much to damage the MCU, limit being 6V for ATTiny13.

So in reality, you should add four schottky diodes to clamp voltages to about 0.3V above supply and 0.3V below ground. And preferably use external FETs or some IC to drive the relays instead of using the IO pins directly.

Justme
  • 127,425
  • 3
  • 97
  • 261
  • 1
    You're right, adding protection at the MCU is a bit pointless. An external driver circuit should be used. – LordTeddy May 11 '23 at 20:19
  • *"you set both IO pins low to stop driving the coil .. other IO pin must source current and it will be clamped to -0.5V by the coil pulling 20mA through protection diode from the other IO pin."* - If the pins are still set to outputs, the current will flow through the MOSFETs and not through the protection diodes. – jpa May 12 '23 at 07:23
  • @jpa So, do you mean that when IO pin is set from high to low, the NFET will conduct current in reverse from GND to output instead of clamp diode? – Justme May 12 '23 at 08:19
  • @Justme Yeah, FETs conduct in both directions equally as long as the gate-source voltage (coming from the IC internally) is above the threshold. There may be a short dead time during switching, which could potentially cause voltage spikes that the protection diodes would clamp. – jpa May 12 '23 at 08:54
  • Some caution is required in interpreting the datasheets. 3.75V is adequate **if** the coil temperature never exceeds 20°C. If your application has to work in 70°C ambient you will need more like 4.5V (and the CMOS drive will get weaker at higher temperatures on top of that). That's one way that unreliable products can happen. – Spehro Pefhany May 14 '23 at 15:32
5

Assuming both outputs are always set to push-pull the 30mA or whatever was going through the relay coil will be conducted by the MOSFETs in the two outputs (one in reverse and one forward). If the voltage drop is more than a few hundred mV through the MOSFET it's possible the internal protection circuit will conduct. This can have unpredictable effects (for example, it could disrupt an ADC conversion by adding noise) but probably will not cause failure. Even if you switched one of the outputs to high-Z the protection networks would likely prevent failure provided there's good supply bypassing near the chip.

As well as the inductance, that's a relatively high current to be switched directly by the MCU.

I have seen this done in a successful and reliable commercial product, however the designer used CMOS ex-or gates, if memory serves, with more drive capability and keeping it off the MCU (that also allowed 'n' bistable relays to be driven with n+1 GPIO lines, one used as a strobe).

If you want more belt-and-suspenders protection you could use two dual Schottky SOT23 diodes such as BAT54 for each coil (to the supply rails- so good supply bypassing with a decent bulk capacitor nearby). Because they are Schottky junctions they will prevent the internal protection networks from conducting (much).

Spehro Pefhany
  • 376,485
  • 21
  • 320
  • 842
2

In general it's a bad idea, but the MAS Effects example you posted isn't a general use case. It's a specific use case with a PCB optimized for minimal foot print and minimal component count.

It's exploiting the ESD protection in the Attiny85 and Attiny13, and doesn't exceed the max DC current per pin. It works fine, there are countless thousands of these in the world, and zero issues.

With different design constraints (e.g. in every other MAS Effects product), there are different microcontrollers and they all use proper drivers and flyback diodes.

  • See [this post on PedalPCB forum](https://forum.pedalpcb.com/threads/flyback-diodes-and-relays.3576/post-28437) which elaborates on the "exploiting ESD protection" idea. – Matt May 31 '23 at 16:26
0

This can indeed potentially create voltage spikes that could damage those IO pins. You haven't run into it yet, but just when you relax it will let the magic smoke out.

I would use a bi-directional 5 V TVS diode in parallel with the coil to suppress this.

You could also use back-to-back 5 V zeners in a pinch.

evildemonic
  • 8,698
  • 2
  • 25
  • 44
  • 1
    How would they help? Assuming one IO pin is always driven low by MCU, and the other driven from high to low to stop driving the coil. Where would there be 5V in this case? – Justme May 11 '23 at 20:10
  • @Justme I guess I am NOT assuming on IO pin is ALWAYS driven low and the other ALWAYS driven high. I don't recommend designing in using internal clamping diodes. TVS are dirt cheap insurance. – evildemonic May 11 '23 at 20:17
  • OK, but then your answer is missing how the TVS will work if it's just in parallel with the coil, or two back-to-back zeners for that matter. How to drive the IO pins to not pass current through internal clamp diodes? – Justme May 11 '23 at 20:21
  • @Justme I was thinking in a case where both IO went hi-Z or both to the same state suddenly while the coil was energized, when the coil voltage subsequently exceeds 5 V most of the ensuing current would circulate through the TVS and coil until dissipated. I must be missing something... – evildemonic May 11 '23 at 20:26
  • 2
    OK, in case both pins go hi-z, the TVS can work, but it must clamp before 6V or MCU clamp diodes conduct. If both pins go to same state, e.g. low, then there won't be anywhere near 5V over coil even if 20mA flows. One IO pin still sinks 20mA through NFET to 0V, ideally it will be 0V. The other pin must still source the 20mA, which means, coil will push the pin voltage down to -0.5 and the clamp diode conducts the 20mA. – Justme May 11 '23 at 20:32
  • 3
    @Justme Ok, now I see what you were getting at. Thank you for explaining it that way. – evildemonic May 11 '23 at 20:37
  • 1
    I tend to use drivers like TC1411 with internal clamp diodes rated for this purpose. – John Doty May 13 '23 at 13:20