On Tue, 9 Mar 1999 16:43:02 +0000 Guy Sirton writes: >Hi all, > >On 8 Mar 99 at 11:18, Gerhard Fiedler wrote: > >> At 10:46 03/08/99 +0600, Dan Larson wrote: > >> >debouncing algorithms should I use? I am not asking >> >for code, just the algorithm. Code would be OK, by I can >> >write my own code so an explanation would be better. > >The problem you are trying to solve is that while a switch is >changing position it will "bounce" between on and off for a short >period of time (depending on the nature of the switch used). There are many different ways to deal with switch bounce. Perhaps the simplest is just to poll the switch slowly. If your polling interval is longer than the maximum bounce time, the output can always be trusted. The main problem with this method is that there is a relatively long and variable time to respond to the switch changing. If the switch is operated manually, it usually won't be noticeable. This method is entirely suitable for many applications. If the switches are part of a machine for example, a fast reaction to changes would be good. Consider reacting to the switch as soon as it changes, but then ignore further changes during the bouncing interval. This method gives fast response, but requires a "timer" for each switch. Both of the methods above, especially the second, are sensitive to pulses of noise on the switch inputs. Though this isn't strictly switch bounce, a routine intended to handle switch bounce can also serve to reject noise. Polling several times and looking for a majority or unanimous decision will reject pulses of noise that are shorter than the polling time. But it will extend the response time until a decision is made. In a highly optimized scheme, a decision could be made while the switch is still bouncing. Then a timer would be used to ignore the switch until the bounce time is over. ___________________________________________________________________ You don't need to buy Internet access to use free Internet e-mail. Get completely free e-mail from Juno at http://www.juno.com/getjuno.html or call Juno at (800) 654-JUNO [654-5866]