Hardware debouncing questions

Hi all,

I learned a great deal about debouncing from this extremely useful thread here...
http://forum.arduino.cc/index.php/topic,14397.0.html

I even implemented his "revised circuit" with great success on my own magnetic reed switch circuit.

So, my questions are:

1. What is the significance of choosing the values 470 (R1) and 10k (R2)? I think it has something to do with how fast the capacitor charges/discharges but what is the math behind those values?

2. I have seen other examples of hardware debouncing that only use one capacitor and one resistor. Basically, they get rid of R1 below and instead of D1 it is just a straight shot to the interrupt pin.How does this circuit compare to the one below? Advantages/disadvantages of each are... ??? (Besides the obvious "fewer components.")

{{{photo credit to author of post in link above}}}

The 1 resistor cap method is used because it's obviously cheaper and quicker to build, essentially without the cap/resistor what will happen is the IC or MCU's job is to detect the button being pressed, in a split moment in time that IC at the very moment in time you push to make 2 pieces of metal come together can touch, de touch, touch a few thousand times , so the basic role of the circuit is to fill the capacitor very very quickly giving a nice clean waveform so instead of seeing the quick succession of off's and on's while the contacts are making contact, we see a full "on" voltage to defeat the dreaded "debouce" issue... or (Delay(100) will for me) ... either circuit will do that.

oh yes, i forgot, the role of the resistor to ground is simply to bleed off the voltage so the MCU see's LOW again (higher the resistor value, the longer it takes to drain the cap)

dtp1:

{{{photo credit to author of post in link above}}}

After looking at this Circuit for a minute or so , I got the role ..

Ok what's happening is that it's essentially the circuit I just talked about but backwards, the idea is the capacitor is constantly filled high let's say 5v, when the button presses, the 5v high is passed to the arduino where it's shortly discharged to ground giving a low.

This would circuit would give a sharp pulse high and stay low, the other circuit would stay high until you release the button......

Switch not pressed, C1 is kept discharged by R1 and R2, so the voltage at the Interrupt is 5V.

Press the switch, the capacitor charges very quickly through D1, pulling the Interrupt to 0.7V and then R1 finishes charging C1 to 5V and so Interrupt is finally at 0V.

Let off on the button, and the capacitor discharges through R1 and R2. R1 is necessary because the diode is reverse biased at this point.

I'm not really certain why D1 and R1 are necessary for this.

polymorph:
Switch not pressed, C1 is kept discharged by R1 and R2, so the voltage at the Interrupt is 5V.

Press the switch, the capacitor charges very quickly through D1, pulling the Interrupt to 0.7V and then R1 finishes charging C1 to 5V and so Interrupt is finally at 0V.

Let off on the button, and the capacitor discharges through R1 and R2. R1 is necessary because the diode is reverse biased at this point.

I'm not really certain why D1 and R1 are necessary for this.

C1 is kept discharged how exactly? GND only connects via the button?

C1 is discharged by R1 and R2. That is a complete path around C1. Discharged does -not- mean ground. Discharged means no voltage across the capacitor, no charge on it.

The other way to debounce is to get rid of all that stuff and just do it in software.
Use the internal pullup, and have the switch connect to Gnd.
When the switch is closed, capture the time.
Then do not accept another switch closure for action until some time has passed.

``````void loop(){
if ( (digitalRead(button) == 0) && ( (millis() – buttonPressTime) >=debounceDuration) ) {  // somebody pressed the button
// and it’s been long enough since prior button press
buttonPressTime = millis();  // start new debounce timer, time elements are unsigned long
buttonPressed = 1;                // and note that a button press was accepted
}
If (buttonPressed == 1){
// take some action
buttonPressed = 0; // clear the button press
}
} // end void loop
``````

Thanks everyone for your help. I was hoping to find out the actual math behind choosing a 104 cap and the 10k and 470 values of R1 & R2. However, the explanations are indeed helpful.

I have tested the other circuit that uses only a resistor and a cap (I'm using 10k-ohm and again a 104 capacitor) and this is working just fine. Again, what is the math behind these being the "magic values" when dealing with +5v input?