MCU protection with long cables - Page 1
Forum section: electronics / beginners

author: Lomax
author_rank: Frequent Contributor
timestamp: January 29, 2024, 02:27:08 pm
content: I'm well aware this subject has been exhaustively covered here and elsewhere, but I feel the more I read the more confused I get! If you have the patience, I would greatly appreciate some advice on a protection strategy for the I/O pins on an MCU that will be deployed in an environment where up to 20V may be present and accidentally connected to one of its pins, and where those pins are connected to buttons and logic at up to 5M distance, using shielded twisted pair cable. I'm not looking for anything bulletproof, I just want to be reasonably sure that the device I'm building can survive a connection error.I think perhaps theoutputpins are sufficiently protected by just adding a series resistor of high enough resistance to limit the current @ 20V to well under 40 mA (max pin current on the MCU used) - the other end of these outputs is connected to a 74HC-series logic chip which has very high impedance inputs so virtually no current will flow through those wires; I think I can get away with as much as 1k ohm.But theinputsare connected to a momentary switch and are pulled high pretty hard with a 10k resistor - and I need to avoid a design where the button is unable to pull the pin sufficiently low. I've seen too many different ways of protecting input pins - please forgive me if I've confused things - but here are three options for your consideration:Which of these make the most sense (if any)? Perhaps some combination?

author: wraper
author_rank: Unknown
timestamp: January 29, 2024, 02:54:55 pm
content: First of all I suggest using dedicated ESD protection devices like this onehttps://lv.mouser.com/datasheet/2/389/usblc6_2-1852789.pdf(for slow signals you don't need parasitic capacitance to be this low) or separate TVS diodes, not random diodes or Zeners.Secondly, if I/O doesn't need to be fast, or output significant current, add a resistor in series to the outside world before any other protection, it will limit the current if something wrong is connected to the interface or if it's just an ESD. ESD protection devices must have a very short path to solid GND plane, and signals must go right trough them. ESD is very fast and long traces will diminish protection effectiveness.As of your examples, series resistance should be in kiloohms, unless you have some particular reason to need low resistance. But you can reduce pull-up resistance to say 1k to minimize effect of any currents induced into wires and provide enough wetting current for reliable switch operation. Just be sure that device cannot be easily killed by ESD getting into 5V rail. Polyfuse is not needed and is pretty much useless anyway.QuoteDon't forget there are no dedicated outputs in the vast majority of MCUs, you configure them as such. Consider them as inputs with no power applied and during MCU startup.

author: Manul
author_rank: Super Contributor
timestamp: January 29, 2024, 03:46:47 pm
content: Never use capacitor directly at the input, that is a recipe for massive ringing, because wires have inductance and you get an LC circuit, often with relatively high Q. At least some series resistance must be added before the capacitor.Edit: Nevermind, I've read your schematic backwards, I've glanced for a sec and thought that MCU input is on the right and long wire on the left...

author: Jeroen3
author_rank: Super Contributor
timestamp: January 29, 2024, 03:50:03 pm
content: QuoteYou need to ensure noise immunity, make the input trigger when there is ~5 mA sunk from the input. Eg: turn the pull-up into a 1k resistor.Add sufficient TVS diode for ESD, not slow overvoltage. eg: SMA or SOD footprint. So if you expect miswiring to 20V, use a 24V-ish TVS.You can limit any damage to the MCU pin by adding a series resistor, keep the resistance of this high enough to not exceed current injection limits. Eg: 47k.You can optionally offset the trigger point by pulling the mcu line up as well, do some simulations for this.Don't add a diode to 5V. With a 1k pull-up and 30V inject you get 25mA injected to 5V. Meaning the pull up should be a >0.5W resistor if you it to withstand forever.So, third diagram without polyfuse.

author: Lomax
author_rank: Frequent Contributor
timestamp: January 29, 2024, 04:52:51 pm
content: Quote from: wraper on January 29, 2024, 02:54:55 pmOh dear. My circuit has 12 of the MCU's pins connected to the outside world but only four of them as inputs. If I have to provide the same level of protection on all of them the PCB layout will become anightmare.

author: Jeroen3
author_rank: Super Contributor
timestamp: January 29, 2024, 07:23:50 pm
content: So far for inputs I count 4 components ~1206 size per input and for the outputs you can use a simple 74 series logic buffer (you need to drive the capacitance of the cable).Maybe an ESD diode on the output, I don't see a nightmare?You could opt to go more like plc and enter the 12/24V power domain, then nice chips like Infineon ITS4141N and ST CLT03-2Q3 become a possibility.

author: pcprogrammer
author_rank: Super Contributor
timestamp: January 29, 2024, 07:25:14 pm
content: When you really want to be safe optocouplers are the way to go. Both for the input and the outputs. This way your MCU is completely loose from the outside world and save for voltages up to what the optocoupler can handle as a barrier.5 meters of cable can become a major hazard in case of lightning, and the chance of survival is better with an optocoupler then with a TVS.Add ferrite beads plus capacitors before and after each optocoupler and use ground plane separation with the use of a ferrite bead between the external connections and the MCU part.

author: Lomax
author_rank: Frequent Contributor
timestamp: January 29, 2024, 08:04:02 pm
content: Quote from: Jeroen3 on January 29, 2024, 07:23:50 pmThe "nightmare" was@wraper's comment that I needed to treat every pin as an input, which would mean 12 TVS diodes. I had hoped the outputs could survive without them, but now I'm not sure?Can't a 5V MCU drive the cable without any buffer? The ATMega328 I'm using has a max output current of 40 mA, while the74HC244can deliver 35 mA? I'm probably misunderstanding something again... Impedance?And wouldn't I need to protect a dedicated buffer the same way I'd protect the MCU? It don't matter much if the buffer dies but saves the MCU - the board has still stopped working and my phone will ring...

author: Lomax
author_rank: Frequent Contributor
timestamp: January 29, 2024, 08:30:11 pm
content: Quote from: Jeroen3 on January 29, 2024, 03:50:03 pmI forgot to edit the resistor values in my examples; I was actually planning to put 1k since 16V / 1k ohm = 16 mA and max pin current = 40 mA? The environment where the board is going to be used only has 5V DC, 12V DC (nominal) and 240V AC voltages. There is no physical way for the device to encounter any other voltages, and I don't have to worry about someone connecting it to the AC mains by mistake - if they do they deserve to see the smoke!

author: Manul
author_rank: Super Contributor
timestamp: January 29, 2024, 10:27:44 pm
content: Quote from: Lomax on January 29, 2024, 08:04:02 pmMCU can drive the cable, but in order to avoid ringing and to limit current add at least 56-68 Ohms resistor. You may increase it further, but beware that it will cause slower logic transitions. If the inputs on the other end are not schmitt trigger type, funny bussiness may start happening. 1k and 5 meter cable will not give you a very fast edge. Check the specs of the device on the other end.To save board space, look for arrays, resistor arrays, TVS arrays...Consider using socket for your 328 for quick servicing. And remember, you can't protect against everything, you need to set a clear goal on what is enough. Consider quick prototyping and testing to verify that protection meets your goal.

author: Lomax
author_rank: Frequent Contributor
timestamp: January 29, 2024, 10:39:47 pm
content: Quote from: Manul on January 29, 2024, 10:27:44 pmThanks! Logic speed is not important at all; what I'm doing is I'm outputting a 2-bit value on two pins which represents a value between 0-3. At the other end of the cable is a 74HC138 3to8 decoder which drives four LEDs, representing the four possible 2-bit values. So I'm not sending fast serial data down the line; it's parallel andslow. The purpose is to reduce the number of wires required.Quote from: Manul on January 29, 2024, 10:27:44 pmI'm going for an SMD board so sadly no socket, but I will include an ICSP header.Quote from: Manul on January 29, 2024, 10:27:44 pmSo very true! The main thing I want to protect against is user error, where someone assumes the device is 12V powered, or connects 12V by mistake to one of the terminals. Since this is for an automotive environment 12V DC iseverywhere, and can go as high as 16V at times. So that's what the device needs to tolerate. Some ESD protection will be provided by the TVS diodes on the inputs, and I think I'm going to leave the outputs with just a resistor for protection. Perhaps I can get away with lowering the in-line resistors to 470 ohms...

author: DavidAlfa
author_rank: Super Contributor
timestamp: January 29, 2024, 10:43:25 pm
content: In the cheap, I'd go with a pullup in the pin and then a series diode to the button, so it can only pull to gnd.Ringing is no issue, just make a proper debouncing in software, if your code is like "if(button== low){ do } else{ do }", then it's crap, ignore any changes faster than 20ms.

author: Lomax
author_rank: Frequent Contributor
timestamp: January 29, 2024, 10:45:24 pm
content: Thank you for saying that - I was thinking earlier that a simple diode on the outputs might do but wasn't sure! I always doubt my own ideas, and this one never came up when I was searching for pin protection methods. Best to use a schottky though, to get the voltage down as close to gnd as possible... Doing this would mean I could eliminate the TVS diodes as well, right?Edit: on second (third?) thoughts, I'll stick with the resistor + TVS.

author: Manul
author_rank: Super Contributor
timestamp: January 29, 2024, 11:00:38 pm
content: Quote from: Lomax on January 29, 2024, 10:39:47 pmJust to explain better, the issue with slow transitions is not just speed as such, but glitches during signal transitions between 1 and 0 or 0 and 1. Like imagine if logic state is transitioning from low to high, it may look like this: 000000000|1010|111111111. At the begining it is 0, at the end it is 1, but in the middle of transition it gives glitches. In your case (driving leds) it's not a problem, but if you would drive a counter with a slow transitioning signal it could be a disaster.

author: floobydust
author_rank: Super Contributor
timestamp: January 30, 2024, 01:18:04 am
content: Quote from: Manul on January 29, 2024, 03:46:47 pmA capacitor directly at the input to chassis/PE ground works great, in fact it's essential.This is counter to the EE theory here about the resonant circuit formed causing problems. Do the math on what freq. you end up with, including cable capacitance and inductance- and even then it's small AC. You won't be making a crystal radio or powering a Joule thief.Bulk-current injection testing proves it works fine.Otherwise ESD just arcs across those theoretically helpful input resistors.

author: Manul
author_rank: Super Contributor
timestamp: January 30, 2024, 02:00:05 am
content: Quote from: floobydust on January 30, 2024, 01:18:04 amI can assure it's a real issue, not only theory. In fact, I've seen it causing permanent IC damage. Consider scenario: IC input, pullup resistor, ceramic capacitor to ground + long cable and a switch on the other end (true story, someone thought that's a good idea). The problem is, when switch closes, it dumps the capacitor through the long wire, peak current can get very high. And then at first ring that high current causes massive negative transient to the IC. I argue, that damping resistor before the capacitor is almost a rule if you have low impedance switching on the other end of long cable.

author: floobydust
author_rank: Super Contributor
timestamp: January 30, 2024, 02:56:30 am
content: What value do you have in mind for a damping resistor?First I use 2.2-10nF 100V, usually 4.7nF to shunt RF (except for that peak) as itgreatly attenuates ESD,stops arcing across resistors and PCB traces. For a damping resistor - you don't want ESD arcing across it. A 0603 1k gets killed here, becomes an open circuit.

author: Manul
author_rank: Super Contributor
timestamp: January 30, 2024, 04:57:38 pm
content: Quote from: floobydust on January 30, 2024, 02:56:30 amBasically calculate series RLC damping factor. Depends on cable and capacitance. Ballpark for 4.7n and some piece of cable could be like 50-100 Ohms.

author: S. Petrukhin
author_rank: Super Contributor
timestamp: February 02, 2024, 09:18:59 am
content: The best solution for transmitting and receiving signals "in the fields" is optical isolation - an optocoupler.They isolate from external potentials, are not fast enough to transmit needles, and do not load the power supply circuits with external interference, even in 0.4kV harnesses.Circuits with a simple resistor at the input of the optocoupler and a pull-up/down resistor at the output work perfectly steadily.