Thread: toggle switch
View Single Post
  #13   Spotlight this post!  
Unread 21-01-2006, 15:27
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
Re: toggle switch

HW =Hardware solution (using a capacitor). the cap could be wired right across the switch, but the value of the cap depends on several factors in your system, and is best determined by testing the results with an oscilloscope (digital scope preferrably).

SW= Software (programming). The method I described accepts the button push immediately (as long as the 'debounce' flag has not been previously set), and it starts a timer when the button is released. The SW switches state immediately when the button is pushed (because that is when the driver wants something to happen: ............NOW!) Then it watches the button to see when it is released, and makes sure it stays released for the debounce time (100mS) until it will accept another NOW! from the driver.

The best way to visualize a bouncing switch is when someone pushes the button slowly, very slowly till it just makes contact, and they hold it there. What will the code see on the input? ( a mess!) With a one-button solution your drivers will have to be trained to push the button cleanly, not holding their finger on the button and sort-of pressing it. But even when you push it quickly and cleanly, a pushbutton or toggle switch will still bounce.

Two buttons makes everything easier for the SW to handle the inputs, but if you are stuck with one button for ON and OFF, you gotta take what the HW guys gave you and make it work in the code.