Debounce

amatpicax59

New Member
Google traduction
The problem rebound occurs on push buttons or mechanical contacts

Did you notice advised on one of the following solutions?

1 use the command "pause". What are your experiences on the value to milliseconds

2 put a capacitor in parallel with the pushbutton (Piem has stated in a discussion)
but what value to use when you have a pull-up resistor to ground 10KOhm

3 use the statement "button" but it does not seem very simple, you have examples of program line

The solution of the capacitor pleases me but I await your opinion

Thank you to all
 

Goeytex

Senior Member
There are many ways to debounce a switch. There are various software solutions, hardware solutions and methods that combine both. There is not a "one-size-fits-all" solution. What you use, depends upon the application.

Are you triggering an interrupt? Testing for a switch press in a loop? Using a switch to scroll an LCD menu? Triggering an alarm? Morse Code?

How fast does the Picaxe need to respond to the switch press? Do you want the Picaxe to respond upon the press of the switch or upon the release of the switch?

Tell us what the switch is doing, and perhaps post the code you have done so far, so that we can offer a solution that is appropriate for your application. If you are having a specific problem, tell what that problem is.
 

neiltechspec

Senior Member
'pause 100' works for me as well, in persistence checking a switched input.

But, a clue as to what the switch is doing would help.

Neil.
 

amatpicax59

New Member
Following questions from Goeytex
It will be a picaxe 20M2
The push button is connected to an input
He must there be only one detection each time the button and rebounds do not generate the same result as a number of very rapid button presses
Pa example, each time the button increment a variable without bouncing repeatedly increment

Thank you all for your solutions
 

geoff07

Senior Member
Of the many ways to debounce, the 'best' way is probably the one with the lowest component count i.e. a software delay as suggested. It doesn't have to be as long as 100mS though, 20-50 probably work in most cases, it depends on how small the switch is (internally). If you have access to a 'scope it would be instructive to take a look at the bounce pattern and duration.

A capacitor in parallel with the push button also works (with a pull-up). But why pay for a cap and board space?
 

amatpicax59

New Member
If you take the solution of the capacitor, what value do you use and what you take as the resistance value to be connected to ground?
thank you
 

Goeytex

Senior Member
If you take the solution of the capacitor, what value do you use and what you take as the resistance value to be connected to ground?
thank you
Below is a link to one of the better articles on switch debouncing. On page two there are some circuits to consider. I have found the circuit in figure two to be very effective. If you don't want to do the math, you can use a value of 10K for both resistors and a 100n or 200n capacitor.

http://www.ganssle.com/debouncing.htm
 

westaust55

Moderator
. . . It doesn't have to be as long as 100mS though, 20-50 probably work in most cases, it depends on how small the switch is (internally).
While 100 ms is often quoted ( ie PAUSE 100 at default PICAXE clock speed) for debounce I concur that the delay can normally be considerably shorter.
When I wrote code (assembler and machine/hex code) back in the 1970's the "standard" duration for a debouce pause was 5 ms and I never incurred problems. Then a long hiatus before I returned to microcontrollers (= PICAXE).
Maybe switches these days are more prone to extended contact bounce????

Recall (from the 70's) that a button/switch could be pressed at 40 ms intervals by a nimble fingered person. Doubt I could still get near that timing.
Entended debounce periods may miss a valid button press if someone it pressing a button switch very rapidly.

Keep in mind also how often the program returns to scan the input(s). If after a scan finding a valid input the program proceeds to perform a task and does not return to scan the input for some time then adding a PAUSE command may not be necessary or a smaller duration can be used. At a default M2 clock speed of 4 MHz, each command takes approx 0.25 ms to execute so if there are 20+ BASIC program commands before a new scan of the input pin(s) any debounce has likely finished.
 
Top