Electronics > Microcontrollers

switch software debounce

(1/3) > >>

BlogRahul:
Hi
I am just trying to understand switch software debounce  let's say if TACT switch has maximum bounce time of 5-8ms then it is stable. How many successive reading  need to consider switch is in stable state ? At what time interval should we take readings ?

pqass:
A very good read on switch debouncing can be found here:  http://www.ganssle.com/debouncing.htm
You'll find your answer under "Debouncing in Firmware" in Part 2.

BlogRahul:
If I am understanding the information given in the tutorial correctly counting algorithm. Switch is being read every 5ms. Two successive reading show that switch is pressed and debounced. 20 successive reading show that switch is released and debounced     

pqass:

--- Quote from: BlogRahul on September 11, 2021, 04:00:51 am ---If I am understanding the information given in the tutorial correctly counting algorithm. Switch is being read every 5ms. Two successive reading show that switch is pressed and debounced. 20 successive reading show that switch is released and debounced   

--- End quote ---

Yes.

Keep in mind that the DebounceSwitch1() function is constantly being called every 5ms in a timer interrupt.
Your code elsewhere can just check the value of a local copy (pointed to by *Key_pressed parameter) knowing that the value is debounced.

AaronLee:
I didn't spend time to read the link, so probably what I'm about to say was already covered.

What I generally do is just have a debounce timer that counts down in a timer interrupt function. I like to use 50ms for the debounce timer, which is probably excessive, but I've yet to have any issues with that value. I typically can just poll the keys, and detect if there's a difference in the value of any key between the read value, and if so, set the debounce timer. Once the debounce timer has expired (and sets the appropriate flag), it means there's been no change in any of the keys for that period of time, and in the key polling task I check that flag and then process any pressed keys. None of my applications need to work with n-key rollover or multiple keys being pressed at one time, so one debounce timer is sufficient.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version