Author Topic: MCU: How to deal with common mode noise on input pin?  (Read 8906 times)

0 Members and 1 Guest are viewing this topic.

Offline ranger81Topic starter

  • Contributor
  • Posts: 16
  • Country: de
MCU: How to deal with common mode noise on input pin?
« on: February 28, 2017, 01:29:08 pm »
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 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.
Wire with open end? Yes, normally there is a sensor connected, but the user might unplug the sensor...

I assume the (common mode) noise has something todo with the (cheap) power supply I'm using. Nevertheless, it's not a solution to replace this psu, because it's mounted in the ceiling. My circuit has to deal with it.

Here is a quick video demonstration of the behavior: https://youtu.be/QMgDTJJYQGg

I tried to solve this interference 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...

I would like to know, if the approach (fixing it with a cap between gpio+gnd) is correct? Or how would you get rid of these interferences?

Any comments are greatly appreciated!
Thanks
 

Offline Delta

  • Super Contributor
  • ***
  • Posts: 1221
  • Country: gb
Re: MCU: How to deal with common mode noise on input pin?
« Reply #1 on: February 28, 2017, 01:36:46 pm »
Are you *sure* you are using a 4k7 resistor and not 470k?

4k7 should be strong enough to prevent that kind of crap.
 

Offline ranger81Topic starter

  • Contributor
  • Posts: 16
  • Country: de
Re: MCU: How to deal with common mode noise on input pin?
« Reply #2 on: February 28, 2017, 01:40:09 pm »
Yes I'm sure. I even tried with 1k5 and 1k. It was not "stable" enough. Then I tried a 220R, this was finally stable enough to keep the pin high even if I touch the open end wire. I was also impressed "how low" I had to pick the pull up....

PS: In the video above I'm demonstrating the issue without pullup and with an Arduino. The real application is an ESP8266 working with 3.3v and the mentioned pullups.
« Last Edit: February 28, 2017, 01:42:07 pm by ranger81 »
 

Offline S13

  • Contributor
  • Posts: 45
  • Country: nl
Re: MCU: How to deal with common mode noise on input pin?
« Reply #3 on: February 28, 2017, 02:58:02 pm »
So i assume its a digital i/o level that you would like to maintain?

You need to know that as long as the injected electric signal is of greater magnitude than your own digital io line will permit, you will always get interference. Perhaps you need to approach this from another angle? Like:

- First make sure your input circuit can handle the injected signal. This means making sure it doesnt violate absolute minimum/maximum specs of the GPIO pin. Sometimes the internal clamping diodes of the GPIO pin are sufficient, other times external heavier duty clamping diodes are required (especially when you have external board signals connected to the GPIO).

- Then make sure you filter out all unwanted frequencies, which is usually done with a typical low pass filter. High frequency noise is injected most easily so that will take care of some of the noise.

- If your noise is in the same frequency range as your digital signal, and your signal is just too damn weak to overcome the noise, then you need to solve the problem on the other end; where the signal is generated. Either lower the output impedance of the signal, or prevent the high noise from injecting in the first place! The last one meaning that you cannot touch the signal and that it has enough shielding.

Also your system could be adapted to cope with the noise (which is good practice anyway). Since its just garbage thats being received, the receiving system should be able to detect this and ignore the signal while its being overrun with noise. Most digital protocols have some sort of error detection for this purpose anyway.

So there are a few options to choose from. But i guess what is most practical depends on the current implementation of your project.
 
The following users thanked this post: ranger81

Offline Delta

  • Super Contributor
  • ***
  • Posts: 1221
  • Country: gb
Re: MCU: How to deal with common mode noise on input pin?
« Reply #4 on: February 28, 2017, 03:19:47 pm »
You must be doing something wrong with your scope probing technique and / or PSU configuration.  There is no way RMI could induce 4Vpp of crap across 4k7. Have you got a decoupling cap across the supply rail and ground? Is your scope ground connect to the circuit's ground?
 

Offline ranger81Topic starter

  • Contributor
  • Posts: 16
  • Country: de
Re: MCU: How to deal with common mode noise on input pin?
« Reply #5 on: February 28, 2017, 04:04:27 pm »
You must be doing something wrong with your scope probing technique and / or PSU configuration.  There is no way RMI could induce 4Vpp of crap across 4k7. Have you got a decoupling cap across the supply rail and ground? Is your scope ground connect to the circuit's ground?

The device I'm talking about is a Sonoff. The power supply schematics are available here on page 2: https://www.itead.cc/wiki/images/f/f8/Sonoff-Schmatic.pdf

I don't know what I'm doing wrong with my scope. The ground of the scope is connected to ground of the Sonoff board (secondary side) and the probe is actually connected with the GPIO. As you can see in the video, Vpp is approx. 4v. I also don't believe my eyes.
My scope is battery powered. If I connect earth ground (from the mains plug) to the secondary sides ground, the noise is also gone...

Edit:
I have created a second video to quickly explain my issue. Could you please have a look at it?
https://youtu.be/BBb1hH1n32U


Thanks
« Last Edit: February 28, 2017, 04:19:32 pm by ranger81 »
 

Offline Delta

  • Super Contributor
  • ***
  • Posts: 1221
  • Country: gb
Re: MCU: How to deal with common mode noise on input pin?
« Reply #6 on: February 28, 2017, 04:37:37 pm »
Try putting a 0.1uF ceramic cap between Vcc and Gnd. Basically decouple the top of your pull-up resistor to Gnd.
 

Offline ranger81Topic starter

  • Contributor
  • Posts: 16
  • Country: de
Re: MCU: How to deal with common mode noise on input pin?
« Reply #7 on: February 28, 2017, 04:48:32 pm »
Try putting a 0.1uF ceramic cap between Vcc and Gnd. Basically decouple the top of your pull-up resistor to Gnd.

I have done that on my breadboard. Did not change anything.
Nevertheless on the Sonoff board itself there are already a few 100nf between vcc and gnd.
Or did I connect it false? Attached is a picture.
 

Offline Benta

  • Super Contributor
  • ***
  • Posts: 5840
  • Country: de
Re: MCU: How to deal with common mode noise on input pin?
« Reply #8 on: February 28, 2017, 05:10:53 pm »
You've just demonstrated how well your body works at picking up stray fields (eg, 50 Hz) from your surroundings.

 
The following users thanked this post: Frost

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4208
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: MCU: How to deal with common mode noise on input pin?
« Reply #9 on: February 28, 2017, 05:14:50 pm »
You've just demonstrated how well your body works at picking up stray fields (eg, 50 Hz) from your surroundings.

This ^^^

The simple answer is, don't touch wires connected to MCU input pins. Use a connector which makes doing so difficult. Attach the male connector to the sensor and the female to the MCU.

Offline ranger81Topic starter

  • Contributor
  • Posts: 16
  • Country: de
Re: MCU: How to deal with common mode noise on input pin?
« Reply #10 on: February 28, 2017, 05:36:53 pm »
Sure I won't make it easy to grab the wire, but you all know end users, they might do stupid things and I just need to make sure, that my microcontroller does not do stupid things. What about my possible solution (adding a 100n between gpio and gnd) mentioned in my first post? Is this an acceptable way to filter the noise ?
 

Offline S13

  • Contributor
  • Posts: 45
  • Country: nl
Re: MCU: How to deal with common mode noise on input pin?
« Reply #11 on: February 28, 2017, 06:18:32 pm »
I think you need to realize that your system should be able to cope with garbage digital signals. The digital protocol should handle it.
Just make sure your GPIO pin cannot be damaged by the injected interference and you are good to go.
« Last Edit: February 28, 2017, 06:42:18 pm by S13 »
 

Offline ranger81Topic starter

  • Contributor
  • Posts: 16
  • Country: de
Re: MCU: How to deal with common mode noise on input pin?
« Reply #12 on: February 28, 2017, 06:26:42 pm »
Yes in the meantime my firmware can detect a floating input and disabled/ignores the interrupts.
Regarding input protection I need to implement clamping diodes, right? But shouldn't they be already inside of the MCU?

Thanks
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4208
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: MCU: How to deal with common mode noise on input pin?
« Reply #13 on: February 28, 2017, 06:28:36 pm »
What about my possible solution (adding a 100n between gpio and gnd) mentioned in my first post? Is this an acceptable way to filter the noise ?

You always need to know the characteristics of the noise you're trying to filter, and the signal you don't want to significantly affect.

Touching the wire typically injects a relatively high voltage, high impedance signal at 50 Hz (plus some higher harmonics). You'll see the effect if you touch a scope probe tip, and hear it if you touch a line level input to an audio amplifier.

The impedance of a 100n cap @ 50 Hz is given by Xc=1/2(PI)*50*100n = 31.8 kOhms. This is quite high compared to the 4k7 resistor you already have, so no, I don't think it's likely to help much.

I think a better solution is to prevent physical access to the pin by careful connector choice, coupled with software which is robust enough to recognise and ignore noise with these characteristics. You might also consider adding additional ESD protection to the pin too.

Offline Gyro

  • Super Contributor
  • ***
  • Posts: 9410
  • Country: gb
Re: MCU: How to deal with common mode noise on input pin?
« Reply #14 on: February 28, 2017, 06:31:17 pm »
You've just demonstrated how well your body works at picking up stray fields (eg, 50 Hz) from your surroundings.

On the contrary, you are showing what happens when your body is the only ground and you have significant leakage current from your power supply!.

You are using a battery powered floating scope so your body forms the only ground path when you touch the input. You need to check the magnitude of leakage through the PSU, it must be significant if it is generating valid logic levels across 4k7 or less!

Power off, perform resistance tests primary side to secondary. If satisfactory (ie. capacitive noise coupling only). Then grounding the secondary side is your logic 0V is the only reliable solution.

Be safe!
Best Regards, Chris
 
The following users thanked this post: Jeroen3

Offline ranger81Topic starter

  • Contributor
  • Posts: 16
  • Country: de
Re: MCU: How to deal with common mode noise on input pin?
« Reply #15 on: February 28, 2017, 06:35:33 pm »
What about my possible solution (adding a 100n between gpio and gnd) mentioned in my first post? Is this an acceptable way to filter the noise ?

You always need to know the characteristics of the noise you're trying to filter, and the signal you don't want to significantly affect.

Touching the wire typically injects a relatively high voltage, high impedance signal at 50 Hz (plus some higher harmonics). You'll see the effect if you touch a scope probe tip, and hear it if you touch a line level input to an audio amplifier.

The impedance of a 100n cap @ 50 Hz is given by Xc=1/2(PI)*50*100n = 31.8 kOhms. This is quite high compared to the 4k7 resistor you already have, so no, I don't think it's likely to help much.

I think a better solution is to prevent physical access to the pin by careful connector choice, coupled with software which is robust enough to recognise and ignore noise with these characteristics. You might also consider adding additional ESD protection to the pin too.

Thanks for your answer, in my latest try I have removed the 4k7 resistor again and only have a 100n between the pin and GND. This seems to solve all my issues. No more noise, but the sensor is still working (if connected). Even touching the wire does not induce any noise.

So actually this helps a lot and solved the issues I'm having. But is this solution robust and acceptable? I'm an electronics newbie and I would just like to confirm that I'm not doing something completely stupid...
 

Offline S13

  • Contributor
  • Posts: 45
  • Country: nl
Re: MCU: How to deal with common mode noise on input pin?
« Reply #16 on: February 28, 2017, 06:45:21 pm »
So now you dont have any pull up at all?
Dont you need a pull up for a default level?
 

Offline ranger81Topic starter

  • Contributor
  • Posts: 16
  • Country: de
Re: MCU: How to deal with common mode noise on input pin?
« Reply #17 on: February 28, 2017, 06:50:02 pm »
So now you dont have any pull up at all?
Dont you need a pull up for a default level?

It seems not, without sensor connected the pin stays low and with sensor connected (and the PIR is triggered) the pin is high.
Everything seems to be stable so far, even without pullup or pulldowns.  :-//
 

Offline S13

  • Contributor
  • Posts: 45
  • Country: nl
Re: MCU: How to deal with common mode noise on input pin?
« Reply #18 on: February 28, 2017, 06:58:15 pm »
Regarding input protection I need to implement clamping diodes, right? But shouldn't they be already inside of the MCU?

Possibly the internal diodes of the chip will suffice. But a more robust external clamping diode could be added if needed without adding too much to your BOM. That will at least protect your GPIO pin from damage from induced noise and such.

But know that for ESD pulses you could need something more than that. For ESD, high frequency filtering and/or transient suppressors are most often a must-have. But this one is tricky to verify. Just use a very robust over-done transient protection solution and assume you are "safe", or go the route of testing and verifying with an ESD gun (which is fun btw!)
 

Offline ranger81Topic starter

  • Contributor
  • Posts: 16
  • Country: de
Re: MCU: How to deal with common mode noise on input pin?
« Reply #19 on: February 28, 2017, 08:08:09 pm »
I guess when using the 100n between the pin and gnd any additional protection seems to be obsolete. As I said, even if I touch the wire, there are no more spikes visible on the scope.

Since the microcontroller board is already a commercial product (Sonoff) it's pretty hard or impossible to add any components to the circuit board itself.
 

Offline S13

  • Contributor
  • Posts: 45
  • Country: nl
Re: MCU: How to deal with common mode noise on input pin?
« Reply #20 on: March 01, 2017, 08:00:48 am »
You could still add a protection circuit between your sensor and the Sonoff board, if required. Of course its up to you to decide how robust you would like to make this circuit. If its just a one-off home project and it works according to your own requirements, then leave it as it is. If you make this for a commercial application and it works according to applicable standards, then also leave it be (but this would require a bit more rigorous testing of course).
 

Offline ranger81Topic starter

  • Contributor
  • Posts: 16
  • Country: de
Re: MCU: How to deal with common mode noise on input pin?
« Reply #21 on: March 01, 2017, 09:11:15 am »
Regarding the protection circuit between Sonoff and Sensor board. What would you suggest?
I found the attached protective circuit. What kind of diodes should be used? And the series resistor should be picked to limit the current to the max. my input pin is capable to handle, right?

Thanks!
« Last Edit: March 01, 2017, 09:16:37 am by ranger81 »
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4208
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: MCU: How to deal with common mode noise on input pin?
« Reply #22 on: March 01, 2017, 09:17:29 am »
If your pin is a digital input, it'll be high impedance provided the pin voltage is within the CPU's supply rails. If it goes outside the rails, then you can expect the current to increase dramatically, and that's a condition to be avoided.

I typically use one of two techniques. Either:

a) a TVS diode with an appropriate rating connected to the pin, which limits the range of voltages on the pin by virtue of its own design, or
b) a pair of Schottky diodes to VCC and GND, which limit the range of voltages on the pin to whatever VCC and GND happen to be, plus or minus their own forward voltage (which is typically small enough not to be a problem).
 
The following users thanked this post: ranger81

Offline S13

  • Contributor
  • Posts: 45
  • Country: nl
Re: MCU: How to deal with common mode noise on input pin?
« Reply #23 on: March 01, 2017, 01:47:33 pm »
Regarding the protection circuit between Sonoff and Sensor board. What would you suggest?
I found the attached protective circuit. What kind of diodes should be used? And the series resistor should be picked to limit the current to the max. my input pin is capable to handle, right?

Thanks!

Yes that is a suitable circuit. You could opt to place the resistor in front of the clamping diodes and possibly add a capacitor to GND to create a low pass filter (the cuttoff frequency should of course be higher than the frequency of your signal). This would protect the clamping diodes better for ESD pulses for example. This is especially true when not using a TVS. Clamping diodes, resistors and capacitors are cheap, TVS devices are expensive.
The downside is that leakage current of the clamping diode could become more of an issue because you are adding more input impedance over which an undesired voltage drop could form (just something to be aware of).

For clamping diode you could try the simple BAT54, or perhaps a BAS40-04 (this one has a dual configuration inside a SOT23 package). But there are other suitable schottky diodes both in SMD and through-hole to be found. 
 
The following users thanked this post: ranger81

Offline danadak

  • Super Contributor
  • ***
  • Posts: 1875
  • Country: us
  • Reactor Operator SSN-583, Retired EE
Re: MCU: How to deal with common mode noise on input pin?
« Reply #24 on: March 01, 2017, 04:57:24 pm »
The scope shot shows you are picking up 10 Mhz ? If so whats in
your lab putting out RF, 10 Mhz.

Is it a clock/crystal on the board and board grounds are damaged
in the area the crystal is located ....?

Or 10 Mbs Ethernet transceiver clock somehow not terminated/grounded correctly ?


Regards, Dana.
« Last Edit: March 01, 2017, 04:59:29 pm by danadak »
Love Cypress PSOC, ATTiny, Bit Slice, OpAmps, Oscilloscopes, and Analog Gurus like Pease, Miller, Widlar, Dobkin, obsessed with being an engineer
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf