> >It sound very noisy button. I have not seen 30 ms bouncing signal > >coming from a button. I assume you did not see it under a > >osciloscope. My avagare bouncing lasts for less than one ms. I use > >three successive stable readings to validate a keystroke within 12ms > >periodic polling to read matrix key strokes and it works just fine. > > I've got a truckload of those buttons :( > > I shouldn't really complain because it has allowed me to come up with some > pretty efficient routines for debouncing. > > If you're polling the button (no interrupts) the algorithm is: > > DebounceLoop: ; Come Back Here to Wait for the keypress > if Button_Up goto DebounceLoop > > Counter = 20 msec delay ; Wait a solid 20 msec to assume good down > DebounceWaitLoop: ; Button in this loop > Counter = Counter - 1 > if Counter == 0 goto DebounceEnd > if Button_Up goto DebounceLoop ; If Button goes up, start over > goto DebounceWaitLoop > > DebounceEnd: ; Button is down and Debounced > > Note that I continuously poll the button and if it ever goes back up I > restart the process. Note that the same thing should be done for the button > release. > Since nobody's mentioned it yet, there is the debouncing system that uses parallel counters to debounce buttons. It uses simple boolean logic to low pass filter 1 to 8 inputs. It has the advantage of requiring only one counter (spread over two bytes) and can debounce up to 8 inputs simultanously. I found it on 'n PIC related web page a while back - I cannot remember the URL or the original author anymore, but it really works well. Niki