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 ?
I think it is a bit of over optimism to look at the maximum bounce time of a switch. It varies too much switch by switch
[1]. Besides, if you are going to tap your fingers on the table top, you would have a hard time reaching 15 taps a second. I believe it would be rarer than hen's teeth to find a person who can do even 15 taps/second
[2].
Say you agree with what I just said above, 15 key presses is more than one can expect unless you go with a machine to auto-press the switch. That 15/second translates to 33 ms between key presses.
MCU speed varies too much, so the best would be to actually first get a sense of your MCU binary I/O read time. I suspect 1 or 2 ms would likely be enough, but just to be complete, let
say your MCU takes T seconds to do a binary read. So you wait (33ms-T) and do the read. Any switch that is still bouncing after that should probable be thrown away. Say you are still uncomfortable, wait (33ms-3T), take 3 readings and majority rule. For me, I am a bit lazy. Rather than doing all that testing,
I would just pick 30ms wait, and read the darn thing.
Now about the 1st paragraph, there are backings to my claims (this is really for if you need to justify to your boss and need some backing):
[1] Switch bounce time varying too much (30ms-ish is enough):One may be able to find even worst, the worst bounce I have been able to find is 157 ms by the article already cited by previous reply: The Ganssle Group. They tested 18 switches. The 157ms is the worst, and second worst is 11.3ms.
The rest of the 16 out of 18 bounced average at 1.557ms. Worst in this group of 16 was 6.2ms.
So, two bad switches in my book, and if it bounce more than 20ms (about 3x the tested worst in the 16 "good" switch), it probably should be considered a bad switch for the garbage bin.
This same article also shows 3.3ms to trigger the display, so reading the binary switch open/close would certainly have T<3ms.
[2] Is 15 taps per second really the human limit?Interestingly, there is a study by the University of Houston (Texas, USA) about that subject. "Decoding repetitive finger movements with brain activity acquired via non-invasive electroencephalography" published 2014.
In this study of 5 young adults (25+-2 years old, 4 males, 1 female), with each trial being 3 taps (or other movements defined by the test) in a row. Repeated finger tap exhibits an EEG brainwave of 0.1Hz to 3Hz (see table 1 in the study). So nothing in any of the movement involved in doing a tap was happening faster than 0.1Hz (10 per second), even if extending the finger or palm is included. So my take is in their study group of five, max they could tap would not exceed 10 per second.
It is of course difficult to extend 5 individuals to the entire button pressing humans. 15 taps may not be the human limit but looks like a reasonable upper limit for average button-pressing users.
Link to actual article: Decoding repetitive finger movements with brain activity acquired via non-invasive electroencephalography. March 2014, authors: Andrew Y. Paek, Harshavardhan A. Agashe and José L. Contreras-Vidal; Laboratory for Non-invasive Brain-Machine Interface Systems,
Department of Electrical and Computer Engineering, University of Houston, Houston, TX, USA
https://www.frontiersin.org/articles/10.3389/fneng.2014.00003/full