Michael Park wrote: > As I prepare to try my hand at debouncing a switch input, I'm curious to > know if anyone has characterized mechanical bounce in terms of typical > frequencies and durations. If that information is not directly > available, my question then becomes one of pragmatics: What sampling > frequency have you successfully used, and how many samples did you need > before declaring a switch settled? > Scott Dattalo, on his amazing debounce technique[1], talks about the > "vague terms" surrounding debouncing in general. I'd like to get a feel > for the numbers that real-world practitioners use. Hmmm. If Scott has said anything about a PIC, it is gospel, but heregoes another approach : If you have a timed interrupt, it becomes extremely easy to debounce switches. In your ISR, you sample the input. If it is 'true', increase a counter, say InputDebounce. If it is 'false', clear it. If it reaches a pre-set value, you set flag , say InputDetected. The next time the input is sampled, it increases InputDebounce to one over the pre-set limit, and must not be increased again. Since the flag will only be set if InputDebounce = pre-set value, you don't have to worry about repeated triggers. Interrupt Service Routine : ******************** Check input Is input true ? Yes : Is InputDebounce