Microchip Technology DM164130-9 Manuale Utente
Lessons
2012 Microchip Technology Inc.
DS41628B-page 63
3.7
LESSON 6: DEBOUNCE
3.7.1
Introduction
Mechanical switches play an important and extensive role in practically every com-
puter, microprocessor and microcontroller application. Mechanical switches are inex-
pensive, simple and reliable. In addition, switches can be very noisy. The apparent
noise is caused by the closing and opening action that seldom results in a clean elec-
trical transition. The connection makes and breaks several, perhaps even hundreds, of
times before the final switch state settles.
The problem is known as switch bounce. Some of the intermittent activity is due to the
switch contacts actually bouncing off each other. Imagine slapping two billiard balls
together. The hard non-resilient material does not absorb the kinetic energy of motion.
Instead, the energy dissipates over time and friction in the bouncing action against the
forces pushing the billiard balls together. Hard metal switch contacts react in much the
same way. Also, switch contacts are not perfectly smooth. As the contacts move
against each other, the imperfections and impurities on the surfaces cause the electri-
cal connection to be interrupted. The result is switch bounce.
The consequences of uncorrected switch bounce can range from being just annoying
to catastrophic. For example, imagine advancing the TV channel, but instead of getting
the next channel, the selection skips one or two. This is a situation a designer should
strive to avoid.
Switch bounce has been a problem even before the earliest computers. The classic
solution involved filtering, such as through a resistor-capacitor circuit, or through reset-
ting table shift registers. These methods are still effective, but they involve additional
cost in material, installation and board real estate.
puter, microprocessor and microcontroller application. Mechanical switches are inex-
pensive, simple and reliable. In addition, switches can be very noisy. The apparent
noise is caused by the closing and opening action that seldom results in a clean elec-
trical transition. The connection makes and breaks several, perhaps even hundreds, of
times before the final switch state settles.
The problem is known as switch bounce. Some of the intermittent activity is due to the
switch contacts actually bouncing off each other. Imagine slapping two billiard balls
together. The hard non-resilient material does not absorb the kinetic energy of motion.
Instead, the energy dissipates over time and friction in the bouncing action against the
forces pushing the billiard balls together. Hard metal switch contacts react in much the
same way. Also, switch contacts are not perfectly smooth. As the contacts move
against each other, the imperfections and impurities on the surfaces cause the electri-
cal connection to be interrupted. The result is switch bounce.
The consequences of uncorrected switch bounce can range from being just annoying
to catastrophic. For example, imagine advancing the TV channel, but instead of getting
the next channel, the selection skips one or two. This is a situation a designer should
strive to avoid.
Switch bounce has been a problem even before the earliest computers. The classic
solution involved filtering, such as through a resistor-capacitor circuit, or through reset-
ting table shift registers. These methods are still effective, but they involve additional
cost in material, installation and board real estate.
FIGURE 3-5:
SWITCH DEBOUNCING
One of the simplest ways to switch debounce is to sample the switch until the signal is
stable or continue to sample the signal until no more bounces are detected. How long
to continue sampling requires some investigation. However, 5 ms is usually plenty long,
while still reacting fast enough that the user will not notice.
The switch on the LPC Demo Board does not bounce much, but it is good practice to
debounce all switches in the system.
stable or continue to sample the signal until no more bounces are detected. How long
to continue sampling requires some investigation. However, 5 ms is usually plenty long,
while still reacting fast enough that the user will not notice.
The switch on the LPC Demo Board does not bounce much, but it is good practice to
debounce all switches in the system.
3.7.2
Hardware Effects
When the switch is held down, DS1 will be lit. When the switch is not held down, all
LEDs are OFF.
LEDs are OFF.
+V
R1
R2
Filtered
Switch
Output
SW
C
1