Author Topic: MCU protection with long cables  (Read 1285 times)

0 Members and 1 Guest are viewing this topic.

Offline LomaxTopic starter

  • Frequent Contributor
  • **
  • Posts: 565
  • Country: eu
  • Minimalist
MCU protection with long cables
« on: January 29, 2024, 02:27:08 pm »
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 the output pins 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 the inputs are 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?
 

Offline wraper

  • Supporter
  • ****
  • Posts: 16865
  • Country: lv
Re: MCU protection with long cables
« Reply #1 on: January 29, 2024, 02:54:55 pm »
First of all I suggest using dedicated ESD protection devices like this one https://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.
Quote
I think perhaps the output pins 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
Don'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.
« Last Edit: January 29, 2024, 03:02:52 pm by wraper »
 
The following users thanked this post: Lomax

Offline Manul

  • Super Contributor
  • ***
  • Posts: 1109
  • Country: lt
Re: MCU protection with long cables
« Reply #2 on: January 29, 2024, 03:46:47 pm »
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...
« Last Edit: January 29, 2024, 03:55:56 pm by Manul »
 
The following users thanked this post: Lomax

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4078
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: MCU protection with long cables
« Reply #3 on: January 29, 2024, 03:50:03 pm »
Quote
But the inputs are 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.p

You 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.

« Last Edit: January 29, 2024, 03:56:53 pm by Jeroen3 »
 
The following users thanked this post: Lomax

Offline LomaxTopic starter

  • Frequent Contributor
  • **
  • Posts: 565
  • Country: eu
  • Minimalist
Re: MCU protection with long cables
« Reply #4 on: January 29, 2024, 04:52:51 pm »
Consider them as inputs with no power applied and during MCU startup.

Oh 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 a nightmare.
« Last Edit: January 29, 2024, 05:07:47 pm by Lomax »
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4078
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: MCU protection with long cables
« Reply #5 on: January 29, 2024, 07:23:50 pm »
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.
 
The following users thanked this post: Lomax

Offline pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: MCU protection with long cables
« Reply #6 on: January 29, 2024, 07:25:14 pm »
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.

Offline LomaxTopic starter

  • Frequent Contributor
  • **
  • Posts: 565
  • Country: eu
  • Minimalist
Re: MCU protection with long cables
« Reply #7 on: January 29, 2024, 08:04:02 pm »
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?

The "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 the 74HC244 can 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...

« Last Edit: January 29, 2024, 08:07:00 pm by Lomax »
 

Offline LomaxTopic starter

  • Frequent Contributor
  • **
  • Posts: 565
  • Country: eu
  • Minimalist
Re: MCU protection with long cables
« Reply #8 on: January 29, 2024, 08:30:11 pm »
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.

I 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!
 

Offline Manul

  • Super Contributor
  • ***
  • Posts: 1109
  • Country: lt
Re: MCU protection with long cables
« Reply #9 on: January 29, 2024, 10:27:44 pm »
The "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 the 74HC244 can deliver 35 mA? I'm probably misunderstanding something again... Impedance?

MCU 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.
 
The following users thanked this post: Lomax

Offline LomaxTopic starter

  • Frequent Contributor
  • **
  • Posts: 565
  • Country: eu
  • Minimalist
Re: MCU protection with long cables
« Reply #10 on: January 29, 2024, 10:39:47 pm »
MCU 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.
Thanks! 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 and slow. The purpose is to reduce the number of wires required.

Consider using socket for your 328 for quick servicing.
I'm going for an SMD board so sadly no socket, but I will include an ICSP header.

And remember, you can't protect against everything, you need to set a clear goal on what is enough.
So 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 is everywhere, 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...
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: MCU protection with long cables
« Reply #11 on: January 29, 2024, 10:43:25 pm »
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.
« Last Edit: January 29, 2024, 10:47:53 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: Lomax

Offline LomaxTopic starter

  • Frequent Contributor
  • **
  • Posts: 565
  • Country: eu
  • Minimalist
Re: MCU protection with long cables
« Reply #12 on: January 29, 2024, 10:45:24 pm »
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.
« Last Edit: January 29, 2024, 11:11:33 pm by Lomax »
 

Offline Manul

  • Super Contributor
  • ***
  • Posts: 1109
  • Country: lt
Re: MCU protection with long cables
« Reply #13 on: January 29, 2024, 11:00:38 pm »
MCU 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.
Thanks! 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 and slow. The purpose is to reduce the number of wires required.

Just 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.
 
The following users thanked this post: Lomax

Offline floobydust

  • Super Contributor
  • ***
  • Posts: 7000
  • Country: ca
Re: MCU protection with long cables
« Reply #14 on: January 30, 2024, 01:18:04 am »
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...

A 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.
 

Offline Manul

  • Super Contributor
  • ***
  • Posts: 1109
  • Country: lt
Re: MCU protection with long cables
« Reply #15 on: January 30, 2024, 02:00:05 am »
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...

A 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.

I 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.
 

Offline floobydust

  • Super Contributor
  • ***
  • Posts: 7000
  • Country: ca
Re: MCU protection with long cables
« Reply #16 on: January 30, 2024, 02:56:30 am »
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 it greatly 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.
 

Offline Manul

  • Super Contributor
  • ***
  • Posts: 1109
  • Country: lt
Re: MCU protection with long cables
« Reply #17 on: January 30, 2024, 04:57:38 pm »
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 it greatly 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.

Basically 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.
 

Offline S. Petrukhin

  • Super Contributor
  • ***
  • Posts: 1146
  • Country: ru
Re: MCU protection with long cables
« Reply #18 on: February 02, 2024, 09:18:59 am »
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.
« Last Edit: February 02, 2024, 09:25:28 am by S. Petrukhin »
And sorry for my English.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf