Anyone help me with a simple de-bounce idea?
Moskog
Posts: 554
Hello, I have a push button in a simple counter, counting one number upwards each time button is pressed and starting from 1 again after reaching 5.
Like this:
Like this:
number := 1 repeat if ina[button] == %0 number := (number + 1) if number == 6 number := 1 waitcnt(clkfreq/100 + cnt)But my problem is de-bounching and I would appreciate if anyone know a simple solution and will help!
Comments
Actually, what I think is best is to first wait to detect the key down, then wait for the key to go up, and then wait a while after that for the bouncing to go away...
Your waitcnt should be indented. Like so:
Bruce
It counts seconds, and performs the debounce on the 5 buttons.
Massimo
edit: it runs on a separate cog, stores the keypress and returns the reading in the main code when asked to.
After reading the button you should "clear" it.
Additionally, you may want to have the routine after waiting for bounce to settle, make an additional delay and retest as a "Yes, the switch was really pushed" to separate accidental from deliberate presses of the switch.
The method always runs ms milliseconds. If you want an early exit, replace the else clause (db := 0) with quit.