Go Down

Topic: filtering button noise with a capacitor? (Read 3076 times) previous topic - next topic

matteosistisette

Hi,

Starting from a simple push button circuit such as the one depicted at http://arduino.cc/en/Tutorial/ButtonStateChange,

I thought I would be able to change the circuito so as to avoid "bouncing" in hardware rather than doing software debounce.

I thought that simply putting a capacitor in parallel to the resistor would do: this way, pushing and releasing the button would charge and discharge the capacitor respectively, thus reducing the probabilities of observing bounces on transitions.

However, when I press or release the button, often the arduino resets. What am I missing? I am using a 4.7uF capacitor and a 10k resistor.

I don't see what may be causing any sort of voltage or current peak that may be causing the arduino to reset. I must be missing something very trivial :$

thanks
m.

Terry King

Hi,

At the moment you push the button you connect the capacitor directly from +5V to Ground on the Arduino.  There is a momentary current spike of (lots!) probably in the tens of amps.

If you connect another resistor in series with the switch, MAYBE this can work... Try 470 ohms or so...

This then presents a rising R-C voltage to Arduino. Because Arduino Digital Inputs have a small amount of Hysteresis it's likely that there will be no "bounced" digital value.

Sorry don't have time to look at this with an oscilloscope now.   Anyone??
Regards, Terry King  ..On the Red Sea at KAUST.edu.sa
terry@yourduino.com  LEARN! DO! (Arduino Boards, Sensors, Parts @ http://yourduino.com

Grumpy_Mike

Sorry but that tutorial is a bit rubbish. You need to connect the button from the input to ground then the resistor from the input to +5. then putting a capacitor across the button will reduce the contact bounce

Terry King

#3
May 25, 2011, 07:54 am Last Edit: May 25, 2011, 08:21 am by Terry King Reason: 1
Hi, As much as I hate to disagree with any guy with 4 Gold Stars and a gray beard,

I believe:

Connecting any capacitor directly across a switch with no current limiting resistance is highly likely to damage the switch over time and creates high spike currents in the discharge circuit, whatever it may be.

There are two paths in getting a smoothly-varying monotonic voltage for Arduino to see: A discharge path through the switch and a charge path through the pullup or pulldown resistor.

SO: 
- If you simply use the usual 10K pullup or pulldown and switch for a button-input to Arduino
and
- You add, across the switch, a series Resistor-Capacitor combination of 470 ohms and 4.7 uF (Or other appropriate combination)

When you press the button, you will have a discharge time constant of 2.2 ms during which Arduino will 'see' the transition with it's input circuit, which has a small amount of hysteresis and it should get a clean single, 'debounced' value.  When you release the button, you will have a charge time constant of 50 ms, which is fast enough that you can't push the button again 'too soon'. Unless you have a 20 Hz finger, in which case you could be a drummer with U2.


Agree/Disagree??
Regards, Terry King  ..On the Red Sea at KAUST.edu.sa
terry@yourduino.com  LEARN! DO! (Arduino Boards, Sensors, Parts @ http://yourduino.com

Grumpy_Mike

Terry - While I would not disagree with the theory of what you said in practice I don't think you need to go to the bother of adding a charge and discharge time constant.

First off excess current through the switch when you discharge. For the size of capacitors we are talking about I simply don't see this as an issue. It is a mechanical connection and as such will not be stressed like an electronic component. I have never seen this raised as a reliability issue, it is the mechanical flexing of a switch that is likely to cause failure through metal fatigue that will "get" a switch way before this effect, if it occurs at all.

If you think about contact bounce it happens on both edges. However this can be tackled completely with one slowed edge, in this case the rising edge. A button is pressed discharge of capacitor (almost) instantaneous and input sees a logic 0. Button bounces, releases the short input starts to rise but does not reach the logic threshold before the bounce closes again. Press issue sorted.
Button is released, input starts to rise but bounce occurs before the logic threshold is reached thereby resting to zero and starting the rise again. Bouncing stops and logic threshold is reached reading a logic one. Again job done no bounce seen.

Terry King

#5
May 25, 2011, 11:56 am Last Edit: May 25, 2011, 12:01 pm by Terry King Reason: 1
Mike, I know this can be a real problem. Switches suddenly become "Stuck" and need to be replaced. The contacts have become welded together by a capacitive-discharge spot welder.

I first saw this in Broadcast equipment which had numerous tape machines with remote control boxes. They were switching 24 VDC relays, and at some point the manufacturer added .1 uf capacitors across all the switches due to some RF interference problems. (There was lots in stations located close to an AM transmitter tower). After 1 to 6 months, switches started to "Stick On".  I got a calls like "I pushed stop on tape 2 and as soon as I let go of the stop button it starts again."  The manufacturer sent out (remember mail?) a service bulletin telling customers to cut all the caps off, and add caps in 2 places in the circuitry. This was a .1uF cap soldered right across the switch contacts and charged to 24VDC. I bet the spike current was 100 amps or more.

Since then, I designed control panels for testers with 100's of switches.  When I was using conventional switches, I learned some IBM manual showed how you needed an RC and not just a C across switches. In some equipment those went on a circuit board, not physically on the switch.  I heard then of designers having problems with this who hadn't heard the suggestion.  I still have some of the IBM Part Number little things with the R-C covered with shrink tubing.

These days, if you get deep into the manuals from Omrom etc. they do talk about the problem. I'm digging....

OK: Omron:


and here they say what NOT to do:


OK, I've been burned by this in the past, and it's easy to do right and easy to ADD to an existing typical pull-up or pull-down switch going into Arduino..  

Flakey, intermittent and hard-to-find problems are the worst!  

I'll try to get time to get scope photos some time.  Realistically, um, July.. I'm about to pack up a lot of my Arduino stuff to ship to Italy, and some will come back to USA for the Summer.  But I might not spend 50 hours a week on this stuff if I get my boat running ..  8)



Regards, Terry King  ..On the Red Sea at KAUST.edu.sa
terry@yourduino.com  LEARN! DO! (Arduino Boards, Sensors, Parts @ http://yourduino.com

Grumpy_Mike

OK thanks good to know. This is something I have never come across in the digital set top box industry where we use 5V and make many millions of boxes.

tastewar

But who uses the buttons on set top boxes? ;-)

Bobnova

Bit of a difference in arcs between 5v and 24v.

Go Up