Author Topic: Did I do this pull-up capacitor right?  (Read 8565 times)

0 Members and 1 Guest are viewing this topic.

Offline SlowBroTopic starter

  • Regular Contributor
  • *
  • Posts: 137
  • Country: us
Did I do this pull-up capacitor right?
« on: January 13, 2018, 02:35:11 am »
I've got an external push button installed on an enclosure, as well as two reed switches, that are all connected to an RPi. The button has about 10cm of about 24 gauge stranded wire and the reed switches are on about 3m of 22 gauge solid core unshielded twisted pair. When this button or these reeds are activated they pull low a GPIO pin to send a signal to the RPi.

I am being paranoid about my design producing extraneous emissions (and pass the FCC unintentional radiator lab measurements) so I wanted to put on a low-pass filter on these to prevent stray noise leaking from the RPi to the outside world. The board has some 100 kHz I2C devices and I could see there being a potential for at least the reed switches turning into antennas. [Edit: This did say 400 kHz but I found that 100 kHz is sufficient.]

So I designed all three connection ports like the attached picture. The values of the capacitor and resistor should filter out any noise above about 100Hz, as well as conveniently debounce the connection a bit. (Though the software has sufficient debounce.)

Is this correct? I ask because I've never heard of a pull-up capacitor and I didn't find what I was looking for with Google. But it seems right to me.
« Last Edit: January 14, 2018, 03:10:17 am by SlowBro »
 

Offline riyadh144

  • Supporter
  • ****
  • Posts: 111
Re: Did I do this pull-up capacitor right?
« Reply #1 on: January 13, 2018, 05:55:28 am »
I really don't think think you can pull a signal up using a capacitor since that 3.3V is seeing an open circuit, as capacitors block DC current, so that point is a virtual ground and you are better of putting that capacitor in parallel with your resistor to filter any noise.

But I don't believe you would have any noise in the first place and you are just over paranoid.
 
The following users thanked this post: SlowBro

Offline SlowBroTopic starter

  • Regular Contributor
  • *
  • Posts: 137
  • Country: us
Re: Did I do this pull-up capacitor right?
« Reply #2 on: January 13, 2018, 06:05:03 am »
A two cent capacitor vs $500 an hour for lab time ^-^
 

Offline SlowBroTopic starter

  • Regular Contributor
  • *
  • Posts: 137
  • Country: us
Re: Did I do this pull-up capacitor right?
« Reply #3 on: January 13, 2018, 06:11:00 am »
you are better of putting that capacitor in parallel with your resistor to filter any noise.

Like this?
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2523
  • Country: us
Re: Did I do this pull-up capacitor right?
« Reply #4 on: January 13, 2018, 09:03:27 am »
I would do something like this (with or without R1):
  where C1 would prevent button bounce and noise.

You should recognize this as the suggested configuration for rotary encoders. R1 and C1 are the low pass filter and R2 the pull-up for the switch.
 
The following users thanked this post: SlowBro

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: Did I do this pull-up capacitor right?
« Reply #5 on: January 13, 2018, 09:38:04 am »
OMG  :palm:

Easy: resistor to VCC, capacitor to GND. Like this:

http://coder-tronics.com/switch-debouncing-tutorial-pt1/
 

Offline IanMacdonald

  • Frequent Contributor
  • **
  • Posts: 943
  • Country: gb
    • IWR Consultancy
Re: Did I do this pull-up capacitor right?
« Reply #6 on: January 13, 2018, 10:09:31 am »
The last thing you want is a lo-Z capacitor shorted by the switch. OP's circuit is better.

Look up how Marconi did his radio experiments.  :o
 

Offline Twoflower

  • Frequent Contributor
  • **
  • Posts: 735
  • Country: de
Re: Did I do this pull-up capacitor right?
« Reply #7 on: January 13, 2018, 10:20:24 am »
The problem having a cap parallel to a switch is that the current while switching might be rather high and can cause excessive wear or even fuse the contacts together. At least a current limiting resistor would be useful.
 

Offline SlowBroTopic starter

  • Regular Contributor
  • *
  • Posts: 137
  • Country: us
Re: Did I do this pull-up capacitor right?
« Reply #8 on: January 13, 2018, 06:00:00 pm »
OMG  :palm:

Apologies, I mistook this for the beginner's forum. In a beginner's forum some dumb or obvious questions may get asked.

Easy: resistor to VCC, capacitor to GND. Like this:

http://coder-tronics.com/switch-debouncing-tutorial-pt1/

Not looking to debounce. Unless those instructions also filter emissions coming from the board to the wires.
« Last Edit: January 13, 2018, 06:05:58 pm by SlowBro »
 

Offline SlowBroTopic starter

  • Regular Contributor
  • *
  • Posts: 137
  • Country: us
Re: Did I do this pull-up capacitor right?
« Reply #9 on: January 13, 2018, 06:05:20 pm »
Do you need the line value to be logic 1 on the exact moment of power up? If not, you can connect the capacitor across signal line and ground. Ground is usually much cleaner than VCC in terms of EMI noise. By decoupling signal line to VCC, you can well bring VCC noise to external.
If you do need the line to be high upon powering up, you can consider a reset delay circuit to allow the ground coupled capacitor to charge before the RPi exits reset and samples the data line.

Trying to wrap my head around what you're saying. No I don't need it to be logic 1 on power-up, just need to ensure no excess noise from the board leaks onto the line and out into space. If the cap connects signal to ground won't that register as low, and signal to the RPi that the switch is turned on?

I was reading here that the way this is typically handled is with either common-mode filters or ferrite chokes. I could put some chokes on but I don't know what value I need. Suggestions welcome.
 

Offline SlowBroTopic starter

  • Regular Contributor
  • *
  • Posts: 137
  • Country: us
Re: Did I do this pull-up capacitor right?
« Reply #10 on: January 13, 2018, 06:10:54 pm »
I would do something like this (with or without R1):
  where C1 would prevent button bounce and noise.

You should recognize this as the suggested configuration for rotary encoders. R1 and C1 are the low pass filter and R2 the pull-up for the switch.

So that configuration reduces emissions coming from the board out to the wires? Debounce is not a goal here; software looks for the switch to be active for at least 1 second.

Also, the RPi has pull-ups, so would the pull-up there be required?
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9886
  • Country: us
Re: Did I do this pull-up capacitor right?
« Reply #11 on: January 13, 2018, 06:39:24 pm »
Do you have any reason to believe that there are emissions on the wire?  Do you have a way to measure the effect? 

If the wire is long, I would worry more about external influences coming in through the wire.

When you short a capacitor with a switch, you run into the capacitor equation:

i = C dv/dt  -- the current (i) is related to the size of the capacitor (C - in farads) and the rate of change of the capacitor voltage (volts per second).

But dv/dt can be quite high when you throw a crowbar (essentially 0 Ohms) across a capacitor.  In theory (only), dv/dt approaches infinity.  Therefore, the current i approaches infinity.  The only thing limiting the current is the internal resistance of the capacitor, the resistance of the switch contacts and the resistance of the wire.  These are surprisingly small.

I guess I would put the capacitor between the pin and ground with a series resistor of around 100 Ohms to the switch.  I wouldn't necessarily use the internal pull-up because it won't flow enough current to make a reliable connection through a switch (burning through oxidation, for example).  The capacitor actually helps in this case because it provides a brief spike of higher current that the pull-up resistor can't provide.

I would probably think in terms of a 1k to 10k pull-up resistor at the pin.  Check the datasheet for the nominal internal pull-up resistance.  It is often on the order of 100k or more.  High enough to pull up the internal logic but not high enough to provide switch current.
 

Offline SlowBroTopic starter

  • Regular Contributor
  • *
  • Posts: 137
  • Country: us
Re: Did I do this pull-up capacitor right?
« Reply #12 on: January 13, 2018, 07:51:42 pm »
Do you have any reason to believe that there are emissions on the wire?  Do you have a way to measure the effect?

No, just trying to be careful. There is a 400kHz I2C clock on the same board that a couple 3m wires are on. Don't want excess emissions.


If the wire is long, I would worry more about external influences coming in through the wire.

(..)

Check the datasheet for the nominal internal pull-up resistance.  It is often on the order of 100k or more.

Yes, it is about 50k.

So will the attached schematic help reduce EMI coming from the board? Similar to MarkF's design.
« Last Edit: January 13, 2018, 08:04:01 pm by SlowBro »
 

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3781
  • Country: de
Re: Did I do this pull-up capacitor right?
« Reply #13 on: January 13, 2018, 08:05:28 pm »
I hope you do realize that sticking a cap to a non-schmitt trigger equipped input is a good recipe for having the input start to oscillate due to the very slow transition. May not affect your EMI test but could well break the functionality of the device.
 

Offline SlowBroTopic starter

  • Regular Contributor
  • *
  • Posts: 137
  • Country: us
Re: Did I do this pull-up capacitor right?
« Reply #14 on: January 13, 2018, 08:26:42 pm »
I hope you do realize that sticking a cap to a non-schmitt trigger equipped input is a good recipe for having the input start to oscillate due to the very slow transition. May not affect your EMI test but could well break the functionality of the device.

Even MarkF's design, or the one I just posted in the previous comment?

Oh and the software does the debouncing. It expects at least 1 second for each connection.
« Last Edit: January 13, 2018, 08:44:07 pm by SlowBro »
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2523
  • Country: us
Re: Did I do this pull-up capacitor right?
« Reply #15 on: January 13, 2018, 11:09:19 pm »
When you short a capacitor with a switch, you run into the capacitor equation:

i = C dv/dt  -- the current (i) is related to the size of the capacitor (C - in farads) and the rate of change of the capacitor voltage (volts per second).

But dv/dt can be quite high when you throw a crowbar (essentially 0 Ohms) across a capacitor.  In theory (only), dv/dt approaches infinity.  Therefore, the current i approaches infinity.  The only thing limiting the current is the internal resistance of the capacitor, the resistance of the switch contacts and the resistance of the wire.  These are surprisingly small.

Are we really going to start worrying about shorting a 10nF capacitor?  Even a 100nF capacitor for that matter. :scared:

I'm thinking of a 10nF capacitor and 4.7K resistors. 
Since you're doing switch debounce in software, I would only use a pull-up resistor chosen to switch approx. 1mA.
 
The following users thanked this post: SlowBro

Offline cdev

  • Super Contributor
  • ***
  • !
  • Posts: 7350
  • Country: 00
Re: Did I do this pull-up capacitor right?
« Reply #16 on: January 13, 2018, 11:23:06 pm »
Try using a clip on choke, suppose you have a pair of wires, Wrap the wires - together, side by side, around the open choke as many times as will fit, then close it. If you are using a ribbon cable you use a different kind of clip on choke, a flat one. The most common material they are constructed with is #43. You could also use a toroid, again to eliminate common mode signals, all the wires have to go through the choke and follow the same path.
I was reading here that the way this is typically handled is with either common-mode filters or ferrite chokes. I could put some chokes on but I don't know what value I need. Suggestions welcome.

You likely already have some lying around as they commonly come with electronic equipment.
"What the large print giveth, the small print taketh away."
 
The following users thanked this post: SlowBro

Offline SlowBroTopic starter

  • Regular Contributor
  • *
  • Posts: 137
  • Country: us
Re: Did I do this pull-up capacitor right?
« Reply #17 on: January 14, 2018, 12:58:18 am »
How about this? For the long reed switch wires I added L_Core_Ferrite, which is this component. Its impedance is 998 ohm at 100 MHz.
« Last Edit: January 14, 2018, 01:02:38 am by SlowBro »
 

Offline SlowBroTopic starter

  • Regular Contributor
  • *
  • Posts: 137
  • Country: us
Re: Did I do this pull-up capacitor right?
« Reply #18 on: January 14, 2018, 01:17:35 am »
This may be better. Uses the internal 50k ohm pull-ups on the Pi with the 1uF cap for a 0.05 RC time constant for a nice long debounce. Uses the aforementioned ferrite bead for noise choking. (Noise leaving the board.) And the 1k ohm limits the current from the cap.
« Last Edit: January 14, 2018, 01:19:14 am by SlowBro »
 

Online wraper

  • Supporter
  • ****
  • Posts: 16796
  • Country: lv
Re: Did I do this pull-up capacitor right?
« Reply #19 on: January 14, 2018, 01:28:01 am »
First of all, switch should never be connected directly in parallel with capacitor as it may reduce switch life and produce inductive kickback. Therefore capacitor should be on the other side of 1K resistor. Adding ferrite as shown is a borderline with ridiculous. Relying on internal pull-up is not reliable solution. Also I cannot find any info about raspberry pi having Schmitt trigger on it's GPIO, if that is the case, just adding capacitor does more harm then good. Just in case, debauncing can be done in software without any external circuit.
If you just want ir for radiated EMI and not debounce, then sure that EMI won't come from GPIO which is configured as input. I would rather care what is happening with the ground.
« Last Edit: January 14, 2018, 01:37:14 am by wraper »
 

Offline SlowBroTopic starter

  • Regular Contributor
  • *
  • Posts: 137
  • Country: us
Re: Did I do this pull-up capacitor right?
« Reply #20 on: January 14, 2018, 01:43:23 am »
By the way I found that 100kHz is fast enough for my needs so I stepped down the speed.


First of all, switch should never be connected directly in parallel with capacitor

It's not. The connector for the switch is on the right, the label on the left goes to the RPi.


Adding ferrite as shown is a borderline with ridiculous.

Could you explain why? Newbie here.


Relying on internal pull-up is not reliable solution.

Again, please explain why.


Also I cannot find any info about raspberry pi having Schmitt trigger on it's GPIO

It does not.


if that is the case, just adding capacitor does more harm then good.

Again, please explain why.


Just in case, debauncing can be done in software without any external circuit.

It is.


If you just want ir for radiated EMI and not debounce

EMI is the main emphasis.


then sure that EMI won't come from GPIO which is configured as input.

Couldn't it come from coupling from elsewhere on the board?


I would rather care what is happening with the ground.

Such as what? Help please.

Thanks!!  :)
« Last Edit: January 14, 2018, 01:47:38 am by SlowBro »
 

Online wraper

  • Supporter
  • ****
  • Posts: 16796
  • Country: lv
Re: Did I do this pull-up capacitor right?
« Reply #21 on: January 14, 2018, 01:55:50 am »
Quote
Adding ferrite as shown is a borderline with ridiculous.

Could you explain why? Newbie here.
I thought it was connected directly to raspberry pi. You said it's opposite, then it makes more sense. However I don't think there will be any effect from it anyway.
Quote
Relying on internal pull-up is not reliable solution.

Again, please explain why.
Too low current, regardless of noise susceptibility, it's too low to guarantee reliable switch operation. Both for contact wetting current and operating normally if switch becomes a little bit conductive in off position which is not rare for tact switches.
Quote
Also I cannot find any info about raspberry pi having Schmitt trigger on it's GPIO

It does not.
then you shouldn't do it like this.  Read this. http://www.ti.com/lit/an/scba004d/scba004d.pdf

Quote
I would rather care what is happening with the ground.

Again, please explain why.

Thanks!!  :)

Because sloppy ground is what can potentially became the worst EMI offender.
 

Offline SlowBroTopic starter

  • Regular Contributor
  • *
  • Posts: 137
  • Country: us
Re: Did I do this pull-up capacitor right?
« Reply #22 on: January 14, 2018, 02:11:04 am »
So you said that GPIO inputs won't radiate and I asked about possible coupling from elsewhere. Is that a concern or am I over-thinking it?


Because sloppy ground is what can potentially became the worst EMI offender.

I oopsed and asked why then corrected myself to say, could you give more details about that.
 

Offline SlowBroTopic starter

  • Regular Contributor
  • *
  • Posts: 137
  • Country: us
Re: Did I do this pull-up capacitor right?
« Reply #23 on: January 14, 2018, 02:46:16 am »
then you shouldn't do it like this.  Read this. http://www.ti.com/lit/an/scba004d/scba004d.pdf

Sorry, my head is hurting after reading that... seems like too much. All I want to do is read some reed switches on the end of a 3m wire and ensure little EMI escapes the board.

Assuming you are correct about input GPIOs not radiating, wouldn't the attached do the job? Don't think I need any hardware debounce, and the fast reaction time means it won't stay floating for long.

(Edited because I forgot the input protection resistor.)
« Last Edit: January 14, 2018, 02:55:56 am by SlowBro »
 

Online wraper

  • Supporter
  • ****
  • Posts: 16796
  • Country: lv
Re: Did I do this pull-up capacitor right?
« Reply #24 on: January 14, 2018, 03:00:27 am »
With such long wires, you should really add some ESD protection for reliability. I've seen a lot of RPi with blown GPIO. I'm not going to draw any circuits now because I'm going to sleep, 5AM here LOL.
 
The following users thanked this post: SlowBro


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf