Download ENGR 4803 - Lab 5

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Flip-flop (electronics) wikipedia , lookup

Pulse-width modulation wikipedia , lookup

Buck converter wikipedia , lookup

Electronic paper wikipedia , lookup

Time-to-digital converter wikipedia , lookup

Switched-mode power supply wikipedia , lookup

Two-port network wikipedia , lookup

Opto-isolator wikipedia , lookup

Immunity-aware programming wikipedia , lookup

Transcript
Laboratory 5
Counter and LED Display
= Required to submit your Multisim circuit files before you start the lab.
Pre-lab Questions
1. Attach the detailed wiring diagram you used to construct a one decade digital display as
shown in Figure 5.6. Make sure all of the pins used are labeled and numbered.
2. Attach the detailed wiring diagram you used to construct a one decade digital display as
shown in Figure 5.7. Make sure all of the pins used are labeled and numbered.
3. Draw a schematic of the circuit you used to wire up the normally open (NO) button to
reset the counter to 0. Show all required added components and wiring.
4. Using pseudo-code, describe an algorithm for the LED display to count up (continuously,
with 1 second pauses between numbers) when SW1 is pressed and held down, and count
down when SW2 is pressed and held down (see figure 5.7).
Page 1 of 9
Laboratory 5
Counter and LED Display
Purpose
 To build a digital counter with 1-digit decimal LED display.
 To learn how to assemble and interconnect various integrated circuits to achieve
sophisticated functionality.
 To introduce the digital input and output functions of the Basic Stamp microcontroller.
Introduction
A common requirement in digital circuits applications is to count and display the number
of pulses contained in a continuous TTL compatible pulse train (e.g., the output of a proximity
sensor detecting parts on a moving conveyor belt or a photosensor detecting a reflection from a
piece of tape on a rotating shaft). We want to count the number of pulses and output this number
in binary coded form. This can be done using a 7490 decade counter. Refer to the 7490 pin-out
and function information in Figure 5.1.
Figure 5.1 7490 Datasheet Information
The output of the counter is in binary coded decimal (BCD) form and consists of four
bits, one bit presented by each of the four output terminals. The maximum number of
combinations possible with 4 bits is 24 or 16. The 10 output combinations used for BCD are
shown in Table 5.1. Note that here a logic high corresponds to a voltage high. A BCD counter
cycles from 0 through 9, returning back to 0 after 9.
Page 2 of 9
Table 5.1 7490 Decade Counter BCD Coding
The 7490 decade counter has four reset inputs: R0(1), R0(2), R9( 1), and R9(2) that control
count and reset functions. The Reset/Count Truth Table summarizing the functions of these four
pins is included in Figure 5.1. There are many ways to utilize these reset inputs. A simple
method is to set R0(2) = H, R9(l) = L, and R9(2) = L, where H=5V and L=0V. When R0(1) is set to L,
the counter will be in count mode (see row 5 or 6 of the Reset/Count Truth Table in Figure 5.1).
When R0(1) is set to H, the counter will reset to 0 (LLLL) (see row 2 of the Reset/Count Truth
Table).
It is also convenient to display the output count on a 7 segment LED in digit form.
Another device will be necessary to decode the four bits into a form compatible with the LED
array. This device, the 7447 BCD-to-seven-segment decoder, converts the BCD binary number
at its inputs into a 7 segment code to properly drive the LED digit (see Figure 5.2).
Figure 5.2 Seven –Segment LED Display (LCD)
Page 3 of 9
The function table describing the input (BCD) to output (7-segment LED code)
relationship for the 7447 is shown in Table 5.2. Refer to Figure 5.3 for the pin-out diagram for
the device.
Table 5.2 7447 BCD to 7-segment Decoder
Figure 5.3 7447 Pin-out Diagram
If the 7447 decoder driver is now properly connected to a 7 segment LED display, the
count from the counter will be displayed in an easily recognizable form. It should be noted that
the decoder driver does not actually drive the segment LEDs by supplying current to them;
instead, it sinks current from them.
Page 4 of 9
Components
Qty.
1
1
2
1
1
1
1
3
1
1
2
Item
OEM Basic Stamp 2SX microcontroller
1kΩ resistor
10kΩ resistor
470Ω or 330 Ω DIP resistor pack
7490 decade counter
7447 BCD to LED decoder
555 timer
0.1µF capacitor
0.01µF capacitor
7-segment LED (common anode (CA))
SPDT switches or NO buttons
Procedure
1. Construct the timer circuit (see Figure 5.4) at one end of your protoboard carefully laying
out the connections and wiring for easy debugging. Using the components shown in
Figure 5.4, the output of the circuit will be a pulse train with a frequency of
approximately 60 Hz responding to a period of approximately 16.7 ms.
VCC
555_TIMER_RATED
5V
U5
R1
1.5kΩ
VCC
RST
OUT
DIS
THR
R2
120kΩ
TRI
CON
GND
C1
0.1µF
C2
0.01µF
Figure 5.4 555 Timer Circuit
2. Figure 5.5 shows information from the 555 datasheet. Verify that your timer-circuit is
working properly by verifying the output on the oscilloscope or by driving an LED. Show
the result to your Lab instructor before continuing. Leave this circuit on your protoboard
as it will be used later.
Page 5 of 9
Figure 5.5 555 Pin-out
3.
In the steps that follow, you will construct a one decade digital display as shown in
Figure 5.6. Finish wiring the 7447 and 7490 as shown in Figure 5.6.
VCC
5V
CA
VCC
555_TIMER_RATED
VCC
5V
VCC
5V
5V
GND
U4
A B C D E F G H A B C D E F G H
U5
R1
1.5kΩ
RST
OUT
DIS
THR
R2
120kΩ
TRI
CON
GND
C1
0.1µF
U1
VCC
C2
0.01µF
14
1
INA
INB
2
3
R01
R02
6
7
R91
R92
U2
QA
QB
QC
QD
7490N
12
9
8
11
7
1
2
6
A
B
C
D
3
5
4
~LT
~RBI
~BI/RBO
R3
OA
OB
OC
OD
OE
OF
OG
13
12
11
10
9
15
14
7447N
2X8DIP
330 Ω
Figure 5.6 Decade Counter Circuit Schematics
Note: it is good practice to include a 0.1 |uF capacitor across the power and ground pins
of each IC (not shown in Figure 5.6 or Figure 5.7). This helps filter out transients that
could occur on the power and ground lines during switching. The capacitors are
especially important in more complicated circuits where a single power supply may be
providing reference voltages and switched current to numerous components.
4. Attach the lamp test of the 7447 (pin 3, 0Vand pin 4 and pin 5, 5 V). Turn on the power
supply and describe what happens.
5. Refer to the 7490 Reset/ Count Truth Table, all of the reset pins are grounded, putting the
7490 in count mode. To be able to reset the counter (e.g., with at pushbutton input), set
R0(2)=H, R9(1)=L, and R9(2)=L, and wire up a normally-open (NO) button to R0(1) so the
Page 6 of 9
signal is low when the button is not pressed. When R0(1)=L, the counter will be in count
mode, and when R0(1 )=H (when the button is pressed), the counter will reset to 0.
6. Demonstrate to the lab instructor that your display can increment properly from 0 to 9. At
the same time, also demonstrate that you can reset the counter to 0.
7. Now disconnect the 555 circuit and wire up a button with a pull-up resistor to the 7490
input instead. Press the button a few times and describe what happens.
8. Build the section of the circuit shown in the dashed rectangle (A) first. Do not connect
the 7447 to the Stamp yet! Use the pinout diagrams for the 7447 and display to locate
where the pins are actually located.
Figure 5.7 Switch Controlled Display Circuit
9. After you have proven that the 7447 and 7-segment display have been wired correctly,
connect power and common to the Stamp pins Vin and Vss respectively. Don‟t connect
anything else to the Stamp yet! To make sure that the Stamp is not running some previous
program, enter and run the following program:
‘Stop everything
‘Put your name here
‘Put the date here
end
Page 7 of 9
10. Now connect the DCBA inputs to the Stamp pins P3, P2, P1, and P0 respectively. Enter
and run the following program:
„Display test
„Put your name here
„Put the date here
LOW 0
LOW 1
LOW 2
LOW 3
end
What does the 7-segment display show? The command LOW n does two things: 1) It
makes the pin n an output, and 2) It takes the voltage down close to common potential
(i.e., outputs a „0‟). What is the voltage at pins 9, 10, 11, 12, 13, and 15 of the 7447
chip? What is the voltage at pin 14 of the 7447 chip? Save the program to your USB
flash drive. Change the line “LOW 0” to HIGH 1. Which pins of the 7447 do you
expect to be at 5 V, and which are low? Experiment with making pins P0-P3 HIGH or
LOW until you are satisfied with your understanding of what is happening with the
Stamp pins and your circuit.
11. The approach above is not very amenable to automating the output of a number to the
display. Suppose you had a loop that counted between 0 and 9, and you wanted to output
the count to the display. How would you do it? One way to do it is to store a binary
number in a variable in the microcontroller‟s address space that corresponds to the I/O
pins. The 0‟s in the binary number will set the corresponding pin low, and the 1‟s will set
the corresponding pin high. Try the following program:
„Display loop test
„Put your name here
„Put the date here
counter var nib
„defines the variable counter as a 4 bit variable
OUTA=$0
„sets the lower 4 bits in the ouput register to b0000, i.e.,
makes sure P0-P3 will go low when DIR is set to output
DIRA=$F
„sets the lower 4 bits in the DIRS register to b1111, i.e.,
makes pins P0-P3 be outputs, so values in OUTA show
up there. Should see „0‟ on display now
loop:
FOR counter=0 to 9
OUTA=counter
pause 1000
NEXT
goto loop
What happens to the display? Save the program to your USB flash drive. Modify
the program to count down.
Page 8 of 9
12. So far we‟ve been dealing with the digital output capabilities of the Stamp. Now let‟s
bring in the digital input capabilities. Let‟s make the display circuit output “0” if neither
button is pressed, “1” if SW1 is pressed, or “2” if SW2 is pressed. Complete the circuit in
Figure 5.7 by wiring in the two switches and their current limiting resistors. Try the
following program:
„Switch Controlled Display Circuit
„Put your name here
„Put the date here
OUTA=$0
„sets the lower 4 bits in the ouput register to b0000, i.e.,
makes sure P0-P3 will go low when DIR is set to output
DIRC=$0
„sets the lower 4 bits of the upper byte in the DIRS
register to b0000, i.e., makes P8-P11 inputs
DIRA=$F
„sets the lower 4 bits in the DIRS register to b1111, i.e.,
makes pins P0-P3 be outputs, so values in OUTA show
up there. Should see „0‟ on display
loop:
IF IN8=1 AND IN9=1 THEN zero
IF NOT IN8=1 AND IN9=1 THEN one
OUTA=2
goto loop
one:
OUTA=1
goto loop
zero:
OUTA=0
goto loop
Explain how this program works following the label “loop:”
13. Modify the program from Step 12 so that the display will output “3” if both switches are
pressed (and held down).
14. Write a program that will cause the display to count up (continuously, with 1 second
pauses between numbers) when SW1 is pressed and held down, and count down when
SW2 is pressed and held down.
Questions
1. Which pins of the 7447 should be high to display a “b”?
2. When the button is used for the input instead of the 555 circuit, what did you observe
with each press and release of the button, and why? Be specific.
Page 9 of 9