switch debounce methods
A small correction to Spyghosts' helpful post.
There are two distinct methods of debouncing, though the difference is based on switch topology, not implementation. The first method depends on time (SPST), the second on hysteresis (SPDT).
1) SPST (single-pole, single throw) switch
Whether it's a RC delay in hardware or counting clock cycles in firmware (RC, resonator or crystal timebase), the idea is the same, to intoduce a time delay greater than the bounce time of the SPST switch. All SPST switches depend on the time-delay method for proper deboucing.
2) SPDT (single-pole, double throw) switch
Here, a R-S flip-flop does the job, no time delays involved. Physically, the switch lever travels a much greater distance between contacts than the small distance it travels during bounce (important concept - the lever can't bounce all the way back to the other contact), and a R-S flip-flop provides the necessary hysteresis.
Btw, most pushbutton switches today are of the SPST variety, and a well done firmware time delay costs very little. Cheap & effective wins every time. - Claude