Martin R. Green wrote: > > I am planning to debounce a simple pushbutton connected to a PIC input with > weak pullups enabled. My strategy is to read the button every 10ms, and > when 4 successive reads are the same, consider the level valid. Here is another algorithm that does the same thing: http://www.interstice.com/~sdattalo/technical/software/pic/debounce.html > Any comments on this? Is 10ms about right? How about using 4 successive > reads, is this enough, too many, etc.? Depends. I presume that the time the switch (or switches) is pressed is not too critical. In which case you could get by with two samples spaced 50ms apart. (This assumes of course that the switch is pressed fewer than 10 times per second and is held down for more than 100ms.) If you change from switches to say monitoring relay contacts, then the filtering criteria certainly change. In one instance for example, I needed 1ms time stamping resolution for relay contacts. In that case I chose a ~500us sampling period with 8 consecutive samples. So pulses shorter than 8 * 500us = 4ms were rejected as glitches. So ask your self these questions: 1) How many changes/second do you need to monitor? 2) What is the minimum time the switch is pressed? 3) How 'noisy' is the switch or in other words how long does it take the switch to complete a transition? Perhaps someone else can add to this list. Scott -- __o I buy pizza instead of gas. \< (*)/(*) Or as Mike#99 might say: I get gas instead of buy gas.