Switch de-bounce circuit.

Hi,

Can someone please educate me on the differences between the various circuits (hardware) used to de-bounce input buttons on an arduino? A quick google reveals numerous different ways of doing the same thing....

  • Simple capacitor in parallel with the switch
  • Capacitor & diode combinations
  • Transistor based circuits
  • Op-amp and Schmidt trigger based circuits.

If a simple capacitor will suffice, why are the other circuits ever used? One of them required an additional five components! Isn't this overkill?

Thanks

Not to mention the possibility of doing it in software.

You forgot the best, the RS flip flop.

The point is they only protect for a limited bounce time, the longer that time the more complex is the circuit.

protect for a limited bounce time

I guess the 'bounce time' is a physical characteristic of the switch?

Is it possible to determine the 'bounce time' of a switch (without an oscilloscope) before building a circuit board? I'd prefer to design and build my board with just a single component to do the de-bounce, but I don't want to discover afterwards that I needed one of the more complex options!

Thanks

What you could do, is use this example to count how many pulses you get per closure. I found for example, that a momentary switch I was using was giving me a count of two for almost every single press.

Then use one or other debounce strategy until you get one for one.

I fixed mine in software... that bounce2 library I posted earlier is really simple to use.

I found this reference a good explanation when I was trying to understand the issues involved.

Software is the most reliable method. Just make sure a minumum time passes between two presses.

OhMyCod:
I'd prefer to design and build my board with just a single component to do the de-bounce, but I don't want to discover afterwards that I needed one of the more complex options!

I would suggest using a microcontroller such as a Mega328 as the "single component".

They are the perfect and most reliable solution to the problem. They have the immense advantage that you can adjust them after the board is manufactured to account for whatever oddity you come across.

However if you do do it in hardware an RC low-pass filter into a 74HC14 schmitt-trigger
inverter usually does the trick. However you need 2 resistors, 1 capacitor and one logic
gate per switch, which gets tedious for lots of them.

The switch and pull-up produce a pulse train, the RC filter turns that into
rising/falling exponential decays with a time constant around 10ms or more,
the schmitt-trigger re-converts to a logic signal with lots of hysteresis to ignore
all the analog noise.

There's almost certainly a chip available that does debouncing for many
switches with no external components needed (you can always use another
microcontroller for instance).

Paul__B:

OhMyCod:
I'd prefer to design and build my board with just a single component to do the de-bounce, but I don't want to discover afterwards that I needed one of the more complex options!

I would suggest using a microcontroller such as a Mega328 as the "single component".

The original question was: "Can someone please educate me on the differences between the various circuits (hardware) used to de-bounce input buttons on an arduino?"

To which the correct answer is: None. They're all incorrect.

fungus:
To which the correct answer is: None. They’re all incorrect.

I think you are saying that we are in complete agreement. I just thought I would put it in the most elegant way. 8)

I ended up using an inverted schmitt trigger and a 10 pF capacitor as I seen in a tutorial by jeremy blum and it works pretty well. Needed it for an interrupt input so software debouncing was out of question from the beginning.

magnetman:
Needed it for an interrupt input so software debouncing was out of question from the beginning.

And there's the indication.

If you need to debounce something for an interrupt, clearly you should not be using an interrupt for it. 8)

OhMyCod:

protect for a limited bounce time

I guess the 'bounce time' is a physical characteristic of the switch?

Yes. See it as the contacts rattling, the result of inertia.

A 4093 is a good one.

I've seen variations with two resistors, but I don't know why. It's probably some neurosis vis-a-vis the grave consequences of discharging a 0.01uF capacitor straight to ground, I suppose

Paul__B:

magnetman:
Needed it for an interrupt input so software debouncing was out of question from the beginning.

And there's the indication.

If you need to debounce something for an interrupt, clearly you should not be using an interrupt for it. 8)

Dunno if i was clear in my explanation. The button i debounced is the interrupt trigger, not something that I'm using an interrupt for. And if there is a better way to do it, please teach me or point me to read more on the matter.
Sorry for taking over the thread for this small side discussion, but i considered it better than starting a new thread just for this.

and a 10 pF capacitor

You sure about that capacitor value? A 10pF capacitor will do nothing in a circuit like that. Are you sure it was not 10nF?

That would be precisely the reason for the second resistor, between the 100k and switch, and the capacitor on the gate input.

As I calculate it, the time constant of 100k and 0.1µF is 6 ms but the 4093 thresholds do not correspond to 1/e so it is more like 3 ms. Now since you are directly shorting the capacitor, this time constant applies to the contact opening, not closing, nevertheless this may me somewhat short for comfort. 100k may be somewhat high to account for wiring leakage and interference pick-up though of course the capacitor suppresses the latter. I would tend to be looking at 10k and 1µF.

If I had a reason to do hardware debouncing in the first place, where I was not using a microcontroller. :smiley:


magnetman:
Dunno if I was clear in my explanation. The button I debounced is the interrupt trigger, not something that I'm using an interrupt for.

Then you do not need to debounce it in hardware. Just switch off/ disable the interrupt except when you need it to wake the MCU from sleep.

magnetman:
Sorry for taking over the thread for this small side discussion, but I considered it better than starting a new thread just for this.

Seems entirely relevant to me.

Grumpy_Mike:

and a 10 pF capacitor

You sure about that capacitor value? A 10pF capacitor will do nothing in a circuit like that. Are you sure it was not 10nF?

I just looked now and it’s 10 µF. Should i change it or it’s ok like this? (It works as intended)

Do what you like, remove it and it won't make the slightest differance. You are only 6 orders of magnitude out!

And that's why I'm pedantic.