SWITCH INTERFACING:
CPU accesses the switches through
ports. Therefore these switches are connected to a microcontroller. This switch
is connected between the supply and ground terminals. A single microcontroller
(consisting of a microprocessor, RAM and EEPROM and several ports all on a
single chip) takes care of hardware and software interfacing of the switch.
These switches are connected to an
input port. When no switch is pressed, reading the input port will yield 1s
since they are all connected to high (Vcc). But if any switch is pressed, one
of the input port pins will have 0 since the switch pressed provides the path
to ground. It is the function of the microcontroller to scan the switches
continuously to detect and identify the switch pressed.
The switches that we are using in our
project are 4 leg micro switches of momentary type.
Interfacing switch
with the microcontroller
Thus now the two conditions are to be remembered:
1. When the switch is open, the total
supply i.e., Vcc appears at the port pin P2.0
P2.0 = 1
2. When the switch is closed i.e., when
it is pressed, the total supply path is provided to ground. Thus the voltage
value at the port pin P2.0 will be zero.
P2.0 = 0
By reading the pin status, the
microcontroller identifies whether the switch is pressed or not. When the
switch is pressed, the corresponding related to this switch press written in
the program will be executed.
LED INTERFACING:
LED stands for Light Emitting Diode.
Microcontroller port pins cannot
drive these LEDs as these require high currents to switch on. Thus the positive
terminal of LED is directly connected to Vcc, power supply and the negative
terminal is connected to port pin through a current limiting resistor.
This current limiting resistor is
connected to protect the port pins from sudden flow of high currents from the
power supply.
Thus in order to glow the LED, first
there should be a current flow through the LED. In order to have a current
flow, a voltage difference should exist between the LED terminals. To ensure
the voltage difference between the terminals and as the positive terminal of
LED is connected to power supply Vcc, the negative terminal has to be connected
to ground. Thus this ground value is provided by the microcontroller port pin.
This can be achieved by writing an instruction “CLR P1.0”. With this, the port
pin P1.0 is initialized to zero and thus now a voltage difference is
established between the LED terminals and accordingly, current flows and
therefore the LED glows. LED and switches can be connected to any one of the
four port pins.
Light-emitting diode (LED)
Light-emitting
diodes are elements for light signalization in electronics. They are
manufactured in different shapes, colors and sizes. For their low price, low
consumption and simple use, they have almost completely pushed aside other
light sources- bulbs at first place. They perform similar to common diodes with
the difference that they emit light when current flows through them.
It
is important to know that each diode will be immediately destroyed unless its
current is limited. This means that a conductor must be connected in parallel
to a diode. In order to correctly determine value of this conductor, it is
necessary to know diode’s voltage drop in forward direction, which depends on
what material a diode is made of and what colour it is. Values typical for the
most frequently used diodes are shown in table below: As seen, there are three
main types of LEDs.
Standard ones get ful brightness at current
of 20mA. Low Current diodes get ful brightness at ten times lower
current while Super Bright diodes produce more intensive light than
Standard ones.
Since the
8051 microcontrollers can provide only low input current and since their pins
are configured as outputs when voltage level on them is equal to 0, direct
connectining to LEDs is carried out as it is shown on figure (Low current
LED, cathode is connected to output pin).
Switches and Pushbuttons
There
is nothing simpler than this! This is the simplest way of controlling
appearance of some voltage on microcontroller’s input pin. There is also no
need for additional explanation of how these components operate.
Fig 4.3 : Switches and Pushbuttons
Nevertheless,
it is not so simple in practice... This is about something commonly
unnoticeable when using these components in everyday life. It is about contact
bounce- a common problem with m e c h a n i c a l switches. If contact
switching does not happen so quickly, several consecutive bounces can be
noticed prior to maintain stable state. The reasons for this are: vibrations,
slight rough spots and dirt. Anyway, whole this process does not last long (a
few micro- or miliseconds), but long enough to be registered by the
microcontroller. Concerning pulse counter, error occurs in almost 100% of
cases!
The
simplest solution is to connect simple RC circuit which will “suppress” each quick
voltage change. Since the bouncing time is not defined, the values of elements
are not strictly determined. In the most cases, the values shown on figure are
sufficient.
If
complete safety is needed, radical measures should be taken! The circuit, shown
on the figure (RS flip-flop), changes logic state on its output with the first
pulse triggered by contact bounce. Even though this is more expensive solution
(SPDT switch), the problem is definitely resolved! Besides, since the
condensator is not used, very short pulses can be also registered in this way.
In addition to these hardware solutions, a simple software solution is commonly
applied too: when a program tests the state of some input pin and finds
changes, the check should be done one more time after certain time delay. If
the change is confirmed it means that switch (or pushbutton) has changed its
position. The advantages of such solution are obvious: it is free of charge,
effects of disturbances are eliminated too and it can be adjusted to the worst-quality
contacts.
No comments:
Post a Comment