Protecting MCU / MOSFETs from relay in a small space - Page 1
Forum section: electronics / beginners

author: GiantGnome
author_rank: Contributor
timestamp: November 12, 2023, 06:16:17 pm
content: Hi allI have recently taken up the hobby again, and I'm trying to get my head around how to deal with inductance from a relay. I have a bag of Omron G6KU-2F-Y 5V latching signal relays, and eventually I would like to control them from a MCU (Attiny13A).The relay is using a single, bidirectional coil, and works on a 10ms in both directions. The relay takes around 21 mA to operate, and while Attiny13A has maximum of 40mA from a pin, I would like to operate it through an H-bridge of sorts, to avoid straining the MCU too much.I have googled the hell out of this one and come up with the circuit attached. I have made push-button switches instead of an MCU for simplicity's sake. It uses two p-channel and two n-channel mosfets, in an h-bridge configuration. There is schottky clamping diodes around the relay, and the switch is pulled down with a resistor (10k) and the gates of a mosfet pair is connected through individual 10k resistor to the switch. The other side of the switch is connected directly to 5 voltsMy idea is that both p-channel mosfets will be conducting when nothing is pressed, and both n-channels will be off. When one of the buttons are pushed, the p-channel on the button side is turned off, and the n-channel is turned on. This will cause current to flow through the relay. The button on the other side will cause the current to flow in the other direction. If both buttons are pressed, both p-channels will be off and no current will flow through the relay (but will flow through the pull-down).So my first question is: Is this level of protection good enough, ie. would I kill some of the components (or a MCU) quickly?My next question is: Is this level of protection too much, are some components redundant? Are the schottky diodes necessary, or are the mosfet body diodes enough? Which parameters do I use to evaluate this question?And some follow-up: Do the resistors at the gates of the mosfets (R1, R2, R4, R5) make sense to use, are the pull-downs (R3, R6) enough?Sorry for the long post, I hope it makes sense

author: Thunderer
author_rank: Regular Contributor
timestamp: November 12, 2023, 06:37:18 pm
content: If the mosfets have the internal diode, there is no need for additional ones.If the ATTiny does only this relay switching, maybe other protections are not needed.Though, if the switching noise (only during the switchover) is not taken care of in PCB design, you may have micro-controller unwanted resets. So, good separation of grounds (one single point of connection between relay circuit and the ATTiny circuit, can be done via a ferrite bead rated for the ATTiny consumption), and good decoupling at the ATTiny level.I would use P+N mosfets in SOIC8 or SOT-23-6 packages for a compact solution.

author: MarkT
author_rank: Frequent Contributor
timestamp: November 12, 2023, 06:51:03 pm
content: If you are happy with surface mount you can use a single QSBT40 to implement the diodes for two relays and just drive from the MCU pins. Schottky diodes protect the internal protection diodes of the MCU.

author: jwet
author_rank: Frequent Contributor
timestamp: November 13, 2023, 02:23:54 pm
content: At these kind of currents, you can get away with driving this from the micro or a HCMOS buffer ('240, etc).The most clever circuit that I ever saw for operating single coil latching relays was this. Tie one side of the coil to a port pin or logic output that can sink and source 21 mA required. (CMOS can be safely paralleled). Put diodes on this pin to both supply rails to be conservative though modern CMOS has a latch-up threshold over 50 mA, so there isn't much danger. On the opposite side of the coil, simply put a .1 uF ceramic cap to ground. The relay will close on rising edges of the port pin and open on falling, there is no quiescent. Try it with your particular relay to make sure you have enough oomph stored in the cap.I must give credit for this to Wayne Burdick of Elecraft Ham Radio for this. Its used in a very lower power antenna tuner for QRP operations. This gadget had 16 small latching relays in it and this was so elegant. Lasted a year on a 9V battery.Good luck.

author: Siwastaja
author_rank: Super Contributor
timestamp: November 13, 2023, 02:33:53 pm
content: I would proudly drive it from IO pins directly*; IO pins are internally half-bridges, so using two IO pins you get CMOS full bridge with zero external components! Further, IO pins when set as outputs, always gives you freewheeling; you simply write the output register bits to opposite level. Choose IOs from the same PORT, and then the register write to the two bits will be atomic and they switch very closely in time.*) if for no other reason, it would make some other people uneasyCurrent isn't problem: AVR IO pins can take 21mA from two IO pins (so 42mA total for a port)indefinitely, continuously - shorter pulses of course are piece of cake. When you want to terminate the pulse, you can drive the pins to the same state (e.g., zero).If you feel unsure about driving inductive load from the IO pins directly, why not look at the pin voltages with a scope to verify that freewheeling using the IO structures internal transistors work as expected.As always, power supply bypassing is important, and becomes more important when the IO pins drive larger loads. 1uF MLCC close to the pin, paralleled with 10uF or larger electrolytic or other high-ESR construction, possibly further away, won't go wrong.

author: Siwastaja
author_rank: Super Contributor
timestamp: November 13, 2023, 02:38:20 pm
content: Quote from: Thunderer on November 12, 2023, 06:37:18 pmNo, no, no and definitely no. This "ground bounce generator" is going to be an EMI disaster, or spurious reset generator.

author: Ian.M
author_rank: Super Contributor
timestamp: November 13, 2023, 02:50:14 pm
content: I agree with Siwastaja: Direct drive is certainly a valid choice here and will be the lowest board area solution.Seehttps://forum.microchip.com/s/topic/a5C3l000000MPQQEA4/t327794

author: Thunderer
author_rank: Regular Contributor
timestamp: November 13, 2023, 09:53:54 pm
content: Quote from: Siwastaja on November 13, 2023, 02:38:20 pmYou'd have to fight first TI over this configuration (see the SLOA089, page 17-9, section 17.3.3). Anyway, it worked for me, specifically in motor applications driven by PIC (no resets), but also in PCBs for USB/DAC/Audio.

author: GiantGnome
author_rank: Contributor
timestamp: November 14, 2023, 08:30:02 am
content: I actually have had a PCB made with direct drive, but it has other stupid mistakes, requiring more than a few dirty fixes, so I never bothered building it up. It may not have the proper bypassing for the MCU (only room for one lone 0805 cap). I will try and see if I can make it work with a 1uF and the regulator bypass. Thanks.Otherwise, I'll continue with the H-bridge design. I was also thinking about trying one of those Padauk micros or building it up with a flip flop and some hardware debouncing (which is the only thing the micro is doing at the moment) - which is why I was thinking about a design less reliant on AVR magic.Ground separation is a complete mystery to me, but maybe this will be a "learning opportunity"