Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
391 views

Using Push Buttons

Push buttons are mechanical devices that either make or break an electrical connection between two terminals when pressed or released. There are two types - push-on switches that make a connection and push-off switches that break a connection. A problem with push buttons is switch debouncing, which is caused by the mechanical contacts oscillating briefly when the button is pressed or released. This can cause a single button press to register as multiple presses. Software or hardware debouncing methods like delays, interrupts, or RC circuits are used to filter out the oscillations and produce a clean digital signal.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
391 views

Using Push Buttons

Push buttons are mechanical devices that either make or break an electrical connection between two terminals when pressed or released. There are two types - push-on switches that make a connection and push-off switches that break a connection. A problem with push buttons is switch debouncing, which is caused by the mechanical contacts oscillating briefly when the button is pressed or released. This can cause a single button press to register as multiple presses. Software or hardware debouncing methods like delays, interrupts, or RC circuits are used to filter out the oscillations and produce a clean digital signal.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 29

Using Push Buttons

Push buttons are cheap mechanical


devices. When pushed they either make
connection between two terminals or
break connection between two terminals
and when released, comes to original
stage. Buttons which make connections
between two terminals when pressed are
called Push-ON switches and Buttons
which breaks connection between two
terminals are called push-OFF switches.
Usually common PCB mounted push
buttons has four pins (two for each
terminal) to give them mechanical
stability.
There are two ways to connect push
button to a circuit
1. Pull-UP
2. Pull-DOWN
When push-ON switch connected in
pull-down method, logic gate pin is
connected to ground level through
resistor (Logic ‘0’) before switch is
pressed. When switch pressed, logic
gate pin is connected to Vcc (Logic
‘1’). When switch is released logic
level goes back to Logic ‘0’.
Push button connected as Pull-Down
Push button connected as Pull-UP
Switch De-bouncing.
Operation of push button switch is
simple; it either makes connection or
breaks connection between its two
terminals. But wait, there is problem.
When switch is pressed there is short
period of time where oscillation
occurs.
Oscillation is random and usually less
than 10mS for general PCB mounted push
button switches known as micro
switches. This problem occurs because
mechanical contacts of switchs are not
perfect and nature of electricity. Different
speed of pushing switch is also affects
this problem. This phenomenon is called
switch de-bouncing.
If we ignore this de-bouncing when
creating circuit digital electronics or
microcontrollers, program may
behave in unexpected way or, single
button press may produce more than
one output pulse. To overcome this
issue we introduce small delay in our
program or create hardware
debounce
For example, when we detect switch
press (logic change, say 0 to 1) in
program, we wait small time (usually
about 10mS) and again check status
of switch, now if we encounter logic 1
again this means logic status of
switch is changed from 0 to 1, which
is called switch pressed.
Above figure shows timing diagrams
of switch pressing. Note the time
periods t1 to t2, t3 to t4 are
bouncing. This is what you see if you
examine switch press in oscilloscope.
This type delay method of de-
bouncing has some disadvantages.
Mainly the delay time of 10mS or so
iis idling time for MCU and for some
applications this time is too much and
unacceptable.
Much better way to do debouching is
using interrupts. For example we use
10mS timer interrupt which will
branch our program to switch scan
routine where we will quickly scan
status of all of our switches and
record them in array or variables.
Then after another 10uS same thing
will happen. The idea here is simple.
For every 10ms time, each push
button state will be checked and
compared to the previous states
recorded. This will uncover rising and
falling edges of signal.
If there is no change compared to
previous state of one switch, it is
obvious, that switch is not pressed (or
not changed) its status. In case of
change from 0 to 1, rising edge detected
and change from 1 to 0, falling edge
detected. If next 3 or 4 checks do not
detect any change in new logic state, we
are certain that switch is pressed (or
released).
Hardware Debouncers
Figure below shows the classic
debounce circuit. Two cross-coupled
NAND gates form a very simple Set-
Reset (SR) latch. The design requires
a double-throw switch. Two pull-up
resistors generate a logic one for the
gates; the switch pulls one of the
inputs to ground.
With the switch in the position shown the
upper gate's output will be a one, regardless
of the value of the other input. That and the
one created by the bottom pull-up resistor
drives the lower NAND to a zero . . . which
races around back into the other gate. If the
switch moves between contacts, and is for a
while suspended in the nether region
between terminals, the latch maintains its
state because of the looped back zero from
the bottom gate.
The switch moves a rather long way
between contacts. It may bounce
around a bit, but will never bang all
the way back to the other contact.
Thus, the latch's output is guaranteed
bounce-free.
An RC Debouncer
The SR circuit is the most effective of all
debouncing approaches. but it's rarely used.
Double-throw switches are bulkier and more
expensive than the simpler single-throw
versions. An awful lot of us use switches that
are plated onto the circuit board, and it's
impossible to make DP versions of these. So
ENGINEERs prefer alternative designs that
work with cheap single-throw switches.
Though complex circuits using
counters and smart logic satisfy our
longing for pure digital solutions to all
problems, from signal processing to
divorce, it's easier and cheaper to
exploit the peculiar nature of a
resistor-capacitor (RC) network.
Charge or discharge a capacitor
through a resistor and you'll find the
voltage across the cap rises slowly; it
doesn't snap to a new value like a
sweet little logic circuit. Increase the
value of either component and the
time lag ("time constant”) increases.
A simple circuit, surely, yet one that
hides a surprising amount of
complexity.
Suppose our fearless flipper opens
the switch. The voltage across the cap
is zero, but it starts to climb at a rate
determined by the values of R1, R2
and C. Bouncing contacts pull the
voltage down and slow the cap's
charge accumulation.
If we're very clever in selecting the
values of the components the voltage
stays below a gate's logic one level till
all of the whacking and thudding
ceases. (If the time constant is too
long, of course, the system won't be
responsive to fast switch actuations).
The gate's output is thus a pristine
bounce-free logic level.

You might also like