MCU: Strong interference/ripple when touching a wire connected to a GPIO

Thread Starter

ranger81

Joined Feb 28, 2017
3
Hello,

I have a microcontroller (ESP8266 or Atmega328p) which has one GPIO pin configured as "INPUT" with external 4k7 pullup resistor.
If I check the voltage of this pin using an oscilloscope I can see that it's near VCC (5v) with very low ripple/noise.
A 10cm wire with open end is connected to this GPIO pin. Once I touch the open end of this wire, the GPIO pin "goes crazy".
The oscilloscope shows very high noise (peak to peak approx. 4v) and this behavior continues as long as I'm touching the wire.

This also causes an interrupt (which is enabled on this GPIO) to trigger continously, which is my problem I need to solve.
I need to "harden" my circuit, that even touching the open end of the wire does not bring any (or very low) interference into the circuit.
But why do I have a wire with an open end? Well, under normal circumstances I do not have this situation.
A sensor is connected to this wire, but maybe the user unplugs the sensor from the cable and touches the wire.
This is why my circuit has to deal with this situation.

Here is a quick video demonstration of the behavior:

I tried to solve this by putting an 100n capacitor across the GPIO pin and GND. The oscilloscope showed, that there is no more interference.
As an alterantive, I found out, that a very strong pullup of 220R also solves the issue, but of course the quiescent current is way too much...

The microcontroller is powered by a switching power supply. With a different power supply the issue does not occur! Only with the (cheap) power supply which is installed in my ceiling.
The problem: I'm forced to use the cheap power supply... The schematics of this cheap power supply is here: https://abload.de/img/psuxzlte.png

I would like to know, is the approach (fixing it with a cap between gpio+gnd) correct, it even works without the pullup resistor? And why does touching the open end of the wire cause a pulled-up GPIO pin to go crazy? Is this an EMI issue related to the power supply or whats the explaination for this?

Any comments are greatly appreciated!
Thanks
 

AlbertHall

Joined Jun 4, 2014
12,345
If the sensor is disconnected then the circuit will not work. The fact that it still won't work if the wire is touched seems to be a problem not worth fixing.
 

LesJones

Joined Jan 8, 2017
4,174
I suspect that the PSU has noise on it's output with respect to local ground potential. You will probably find that if you also get hold of the negative rail of your circuit the noise will be much less. You will also probably find that connecting the negative rail of your circuit to mains ground that it will reduce the noise.

Les.
 

ericgibbs

Joined Jan 29, 2010
18,766
hi,
I would agree with Albert, its not a problem.

If you repeat the test, increase the scope scan rate to approx 20mSec per X division and I would say you will see a 50/60Hz sinusoidal waveform.
Your body is acting as an aerial.

E
 
Last edited:

Thread Starter

ranger81

Joined Feb 28, 2017
3
I can confirm that this seems to be power supply related. If i touch the GND with my other hand the noise is much less.

Nevertheless my circuit needs to continue running. Reading the sensor is not it's main purpose, it's just an additional feature. But if there is something wrong with the sensor wire/connection, this should not lead into a total malfunction of my device.

What about the mentioned "solution" with a 100n across the GPIO and GND. As far as I can see, there is no more noise on the pin. Is this a real solution for this problem or what would you suggest how to deal with the issue?
 

DickCappels

Joined Aug 21, 2008
10,152
You should probably protect that input from electrostatic discharge. A TVS diode or even a pair of 1N5711's can help a lot. If you leave the pin exposed then someday somebody might touch it and damage the input.

upload_2017-2-28_20-53-42.png

Maybe the best solution is not to "harden" the input (beyond the ESD protection described above) but to make your firmware sense when the input device is not present and to either disable the interrupts or cause the interrupts to return without doing anything that would disrupt your firmware execution.
 

MrChips

Joined Oct 2, 2009
30,720
Use a physical method of detecting when the senor is unplugged.

Put your sensor on a plug and jack that has a built in switch. When the sensor is disconnected, use the switch to connect the input pin to GND.






or
 

JohnInTX

Joined Jun 26, 2012
4,787
You should probably protect that input from electrostatic discharge. A TVS diode or even a pair of 1N5711's can help a lot. If you leave the pin exposed then someday somebody might touch it and damage the input.

Maybe the best solution is not to "harden" the input (beyond the ESD protection described above) but to make your firmware sense when the input device is not present and to either disable the interrupts or cause the interrupts to return without doing anything that would disrupt your firmware execution.
I agree and would do both. Disconnecting a sensor should not leave the bare pin exposed to the ugly world - as you've seen. I like the TVS and series resistor too if it works for your sensor.

You have also identified a firmware issue and that should be addressed since despite your best protection efforts, a hardware failure can hang your code and as you correctly indicate, that must be addressed. Consider using a timer to measure the time between interrupts and flag a bad sensor if you get too many or too few. The test and timer maintenance should be done inside the interrupt routine. If done in the main code, repeated interrupts may starve the testing and you hang.

But I'm liking the way you think about reliability and robustness! Well done.
 

ErnieM

Joined Apr 24, 2011
8,377
Almost a milliamperes out of your fingertip seems rather high to me.

Have you used an ohmmeter to confirm the pull up resistor is truly connected? Correct value?
 

Thread Starter

ranger81

Joined Feb 28, 2017
3
Thanks for all your answers.

Yes I have verified a hundred times, that my pullup value is correct. Really, I have tried 4k7, 1k5, 1k, 10k as well as 220R as pull ups. Nothing (except the 220R as stated in my first post) worked.

Thanks to DickCappels and JohnInTX for pointing out my firmware issue. I agree with your arguments and in the meantime I have fixed this issue in firmware. It now detects a floating pin and returns the interrupt without anything to do. Now it seems to be a bit more stable.
One problem persists, when I touch the wire or at some point the MCU might restart itself. I guess this might be a voltage spike on the input pin.

Another problem is, that the microcontroller board I'm talking about is already a commerical board (called Sonoff). This means adding clamping diodes, TVS, etc. is actually not easy, because the board is already done...

Again, regarding my 100nf "solution" between the input pin and gnd. When I place this cap, there is no more interference visible on the scope. Even if I touch the wire, there is not any noise. I think fixing my firmware together with placing that cap between the input pin and gnd solves all my issues.

I just would like to have a confirmation that "placing a cap to this pin" is not something completely stupid. As you might already know, I'm an electronics beginner and not completely sure what I'm doing. Try-and-Error got me placing the cap between the input pin and gnd and it looked like I solved the issue.

Why does nobody recommend me in placing the cap to the input pin? Is there any reason why I should not do this?
(I'm aware of the fact that this will "slow down" my input pin detection, but my sensor is very slow (HR-SC501 PIR)

Edit: They are even suggesting the cap on the input pin: https://www.digikey.com/en/articles/techzone/2012/apr/protecting-inputs-in-digital-electronics


Thanks again! I greatly appreciate all your comments and support!
 
Last edited:
Top