Specifications

mikroElektronika | Free Online Book | PIC Microcontrollers | Appendix B: Examples
It is about contact bounce- a common problem with mechanical switches. When the contacts strike together, their
momentum and elasticity act together to cause bounce. The result is a rapidly pulsed electrical current instead of a clean
transition from zero to full current. Generally, it mostly occurs due to vibrations, slight rough spots and dirt between
contacts. This effect is usually unnoticeable when using these components in everyday life because the bounce happens
too quickly to affect most equipment, but causes problems in some analogue and logic circuits that respond fast enough to
misinterpret the on-off pulses as a data stream. Anyway, the whole process does not last long (a few micro- or
milliseconds), but long enough to be registered by the microcontroller. When using only a push-button as a pulse counter,
errors occurs in almost 100% of cases!
This problem may be easily solved by connecting a simple RC circuit to surpress quick voltage changes. Since the bounce
period is not defined, the values of components are not precisely determined. In most cases, it is recommended to use the
values as shown in figure below.
If complete stability is needed then radical measures should be taken! The output of the circuit, shown in figure below (RS
flip-flop), will change its logic state only after detecting the first pulse triggered by contact bounce. This solution is more
expensive (SPDT switch), but the problem is definitely solved!
In addition to these hardware solutions, there is also a simple software solution. When a program tests the state of an
input pin and detects a change, the check should be done one more time after a certain delay. If the program confirms
http://www.mikroe.com/en/books/picmcubook/appb/ (5 of 54)5/3/2009 11:36:02 AM