ESD causing false switch readings on a uController - Page 1
Forum section: electronics / beginners

author: Tompa
author_rank: Newbie
timestamp: January 23, 2025, 02:28:47 pm
content: Hi,I have a gas generator powering my laptop, which has a microcontroller connected through with a USB cable, and that microcontroller is reading a switch in a metal case.On one occasion, I touched the case, not pushed the switch, and I guess ESD triggered a false switch reading on my microcontroller.The microcontroller was a stock Raspberry Pi pico. It's reading a pin state, debouncing it, and if the state is low, it sends an action through the USB connection.It's ground wasn't connected to the metal case from the switch.Now, I'm not sure about what exactly happened and how to prevent that in the future.I'm working on a another PCB that would have ESD protection on all it's pins, a dedicated IC with a Schmitt trigger for debouncing, but not sure if that would solve the problem if the grounds are "floating".One possible solution I think would be to connect the generator's metal rod to the ground, and also connect the PCB ground to the case. So it has a solid ground reference and a ESD discharge path.But is it even possible to have this work properly without connecting the rod in the ground?What else can I do to make the system more safe from false readings?Thanks.

author: Peabody
author_rank: Super Contributor
timestamp: January 23, 2025, 03:09:17 pm
content: I'm not clear on what the existing connections are, particularly inside the metal case. Is the metal case connected to either of the switch terminals in any way? How are the GPIO line and the MCU's ground connected to the switch?

author: PGPG
author_rank: Frequent Contributor
timestamp: January 23, 2025, 04:41:43 pm
content: Input schematic could help.For example at input there can be a capacitor that charged by ESD needs some ms to get back to stable state and this time is longer than debouncing assumes.

author: Tompa
author_rank: Newbie
timestamp: January 24, 2025, 07:46:28 am
content: I attached the schematic and a pic from the case. There's some extra wires now not shown on the schematic that is part of hardware debouncing I was trying out. But at that time it wasn't inside.The metal case was in no way connected to the microcontroller. As you can see on the picture, it's sitting on a plastic part, the usb cable it keeping it positioned, and other part of the board is heat shrinked.

author: PGPG
author_rank: Frequent Contributor
timestamp: January 24, 2025, 12:21:44 pm
content: Quote from: Tompa on January 24, 2025, 07:46:28 amI don't know what is hardware debouncing here. If its task is to make all pulses long enough than may be it changes short ESD pulse into long enough and software can't recognize it from valid pressing the button. To react/ not react on too short pulses is a simple task for software and not hardware. Hardware should have protection against input getting latch-up as software can't do nothing if it happens.I was writing about schematic of the whole way from switch to microcontroller pin.What is in Raspberry Pi at input I don't know.About Raspberry Pi I know only these: Something about 10..15 years ago someone asked us if we can design something with it. I was searching for its documentation but was not able to find even exact dimensioned picture of it. Only what I found was some picture taken by someone by just measuring it with caliper. Then there were a connector that was said being the display output and I also was not able to find any documentation of it. We said: It is not possible (for us) to do anything with something being not documented.

author: Peabody
author_rank: Super Contributor
timestamp: January 24, 2025, 04:07:51 pm
content: Are you able to reproduce this event? Will you be able to know whether grounding the box improves things?It's not clear to me what is happening that would cause the MCU to detect that the switch has closed. Your touch could be either lowering the GPIO input voltage, or raising ground. But I just don't know whether tieing the metal box to the MCU circuit ground would make things better or worse.Things that might help: Add a low-value external pullup resistor to the GPIO pin. Change software so the switch has to be closed for some minimum time period before you recognize it as closed.

author: xvr
author_rank: Frequent Contributor
timestamp: January 24, 2025, 04:12:37 pm
content: Don't rely on the RPi Pico's internal pull-up for the input switch - it's too weak and will absorb all sorts of noise (not to mention ESD).Also, input protection for the input switch is highly desirable - ESD will easily kill the RPi's input.QuoteThe RPi is very well documented now. Both the RPi and RPi Pico are very different - the former is an SBC, the latter is a microcontroller-based module.

author: PGPG
author_rank: Frequent Contributor
timestamp: January 24, 2025, 08:57:05 pm
content: Quote from: xvr on January 24, 2025, 04:12:37 pmI believe. I don't check.

author: I wanted a rude username
author_rank: Frequent Contributor
timestamp: January 25, 2025, 01:58:54 am
content: Connecting PCB ground to the enclosure generally just makes ESD problems worse.Connecting the USB shield to the enclosure may help, but it depends on a lot of variables, so no guarantee.Connecting the USB shield to PCB ground is also generally discouraged.This photo of a Raspberry Pi Picoshows it has such a connection, via two traces. Far be it for me to suggest that the Raspberry Pi Foundation made a mistake, but if you try grounding the USB shield you can also try cutting those traces.

author: Tompa
author_rank: Newbie
timestamp: January 27, 2025, 09:40:12 am
content: Yeah, I meant is filtering, not debouncing. I attached a pic with a schematic.

author: Tompa
author_rank: Newbie
timestamp: January 27, 2025, 09:42:00 am
content: Quote from: Peabody on January 24, 2025, 04:07:51 pmMy thinking was raising the ground too.

author: xvr
author_rank: Frequent Contributor
timestamp: January 27, 2025, 11:20:38 am
content: QuoteThis is better, but still 2 points to note:10K as pull up could be too much. Reduce to 1KAdd small resistor in series with button (100R will be enough) to limit capacitor discharge current. Now your button directly discharge capacitor through itself without any limitation. This can lead to reduced life time of button

author: Tompa
author_rank: Newbie
timestamp: January 28, 2025, 11:40:37 am
content: Quote from: xvr on January 27, 2025, 11:20:38 am1K so that it doesn't mess up the internal microcontroller pullup?Adding a series resistor could be useful, even tho it's a heavy duty switch.

author: xvr
author_rank: Frequent Contributor
timestamp: January 28, 2025, 01:00:01 pm
content: QuoteBoth of them are pull-ups, so they will cooperate at any valueBut internal pull-up have resistance somewere in range 50-100K (in general). 10K of additional pull-up is not enough. Buttons have requirement for minimal current to operate - at least some mA (and up to hundreds of mA - it depends on button). Value of pull up also directly influence the noise immunity - the less the better.

author: PGPG
author_rank: Frequent Contributor
timestamp: January 29, 2025, 03:32:28 pm
content: Quote from: Tompa on January 27, 2025, 09:40:12 amYour schematic shows exactly the situation I have mentioned 23.01 in my first answer in this thread.I supposed I was clear enough that if you know schematic (you didn't show us those time) you will understand what is going on.ESD Human Body Model contains 100pF capacitor so if charged to 25kV and then by ESD discherged into 100nF you get 25V at 100nF.So imagine negative ESD changing voltage at 100nF by -25V. RPi reads it as 0 until voltage at 100nF will get back to 3V3. This pulse may be long enough to be indistinguishable from the user pressing a button.This design is ESD protected in sense ESD doesn't destroy circuit but it is wrong design as ESD pulse can be read as user pressing the button.You have to design it in other way. The best is to make no change at RPi input from ESD at all.

author: Tompa
author_rank: Newbie
timestamp: January 31, 2025, 07:15:37 am
content: Quote from: PGPG on January 29, 2025, 03:32:28 pmI think I'll just use a debounce IC like max6816.Maybe that will just make my life easier.Thanks for the tips!