Counters

[ECEN 1400]
Introduction to Digital and Analog Electronics
R. McLeod
Lab #6: Counters
1
Introduction
The goal of this lab is to introduce a new digital circuit, the counter. As you might expect from its name, this
chip counts the periods of an input line in the binary number system. Here we will work with 4 bit counters that
can count from 0 to 15.
2
Components and Tools Required
• From your kit
Breadboard
Wires
Wire-cutters and pliers
Various resistors and capacitors
• From the TA’s
Two 74161 counter chips
• On the Lab Bench
Variable DC power supply
Function-generator
Oscilloscope
3
Count a switch
In this section you will build a simple 4-bit counter driven by a switch. The counter will count the number of
times the switch is pressed and display this count with 4 LEDs.
When a mechanical switch is opened or closed, it vibrates, causing fast oscillations between short and open,
as shown in Figure 1. This switch bounce will cause a digital circuit to randomly respond to several switch events
when only one is intended. For example, a switch used to increment a counter in (say) a digital clock would be
very annoying to use because the count could increment a random number of digits each time the button was
pushed. Capacitors provide a way to smooth out these fast oscillations, de-bouncing the switch.
Figure 1: Switch bounce. Note the cursor time interval is 2.6 ms. Source: Wikipedia - Switch Contact Bounce
Version 2.1, November 6, 2014
Page 1
[ECEN 1400]
Introduction to Digital and Analog Electronics
R. McLeod
Get a little micro-switch and socket from your T.A. Put the socket in your breadboard and then mount the
switch into the socket. There is a natural way to put the switch into the socket. If you have any questions, check
with your T.A. The switch has four leads coming out of it. Using the multimeter, check which leads are the ends
of the switch. Figure 2 may help you determine which leads are which.
Figure 2: Switch Wiring Diagram.
Figure 3 shows a switch (J1) and a pull-up resistor wired to the clock input of a counter. This combination
allows the switch to present either 5V or 0V to the chip input. Look at the data sheet for the counter to understand
the other pins of the 74161 counter. Pins that are particularly important are:
• A-D: inputs to load the initial count when pin 9 is taken low
• QA-QD: the count output
• RCO: counter rollover tells you when QA-QD = 1111
• CLOCK: Increment the count by one
Four LEDs have been connected to the output lines. Although the counters can provide a high enough voltage
level to turn on the LEDs, they do not provide enough current. Actually, the counter chip will try to provide as
much current as the LED wants for a given voltage level. However, if the amount of current the LED demands
is larger than what the chip is designed to handle, the chip will overheat and perhaps burn out. A secondary
issue is that even if the counter can provide enough current to the LEDs, the current flow must still be limited to
about 6mA to 10mA so the LEDs dont burn out. Check the datasheets of the counter for the maximum amount
of output current that the counter can produce with a high output level. You should find that this value is only
a few tenths of a milli-amp. Clearly this is not good enough to turn on an LED.
Figure 3: A four-bit counter driven by a bouncing switch and a pull-up resistor.
Version 2.1, November 6, 2014
Page 2
[ECEN 1400]
Introduction to Digital and Analog Electronics
R. McLeod
Now check the maximum amount of output current that the counter can produce with a low output value.
What is this value? It should be more than 6mA. With this being the case, an LED can be switched on and off
by the output of the counter. The circuit is similar to LED and transistor circuit from a couple weeks ago. The
+ end of the LED is connected to 5 Volts through a current-limiting resistor. The - end of the LED is connected
to the counter output pin.
Note that the LEDs are displaying NOT(QA), NOT (QB) etc. When the counter output is producing a logic
high voltage level, there is not enough voltage across the LED for it to turn on. When the counter is producing a
logic low voltage level, there is enough of a voltage drop across the LED for it to turn on. Notice that this is the
reverse of what you might expect. A logical 1 turns the LED off, and a logical 0 turns it on.
3.1
Build and test the counter with a bouncy switch.
Open and close the switch and observe the counter output. What specifically condition on the CLOCK pin causes
a counter increment? That is, does the counter increment continually when the CLOCK pin is high, for example?
Look at the datasheet for confirmation - this is typical behavior for digital circuits. You should sometimes see
the count increment by more than one due to switch bounce. However, bounce is random and depends on the
individual switch, so you might get lucky and not witness this. Increment the counter past roll-over (1111) and
observe what happens to the count. Finally, put the counter in an intermediate count between 0 and 15, then
ground pin 9 which loads the values on A-D into the counter. A-D are default low (0000).
3.2
Debounce the Switch
Add an RC combination to smooth-out the switch transition as shown in Figure 4. Select a combination of resistor
and capacitor to produce a time constant around 20 msec. Explain, using Figure 1, why 20 msec is reasonable and
(for example), 20 sec or 20 sec would probably not work well. Making this time constant a little larger is better
than making it smaller. After you have re-wired your circuit with this RC circuit, try using the switch again.
Check that you get the correct count sequence with no skips.
Figure 4: A four-bit counter driven by a debounced switch and a pull-up resistor.
Version 2.1, November 6, 2014
Page 3
[ECEN 1400]
4
Introduction to Digital and Analog Electronics
R. McLeod
Take the ”Modulo” Operation of a Square wave
Remove the switch and other elements driving the CLOCK pin and instead connect the function generator to
CLOCK. Set the waveform to be a 1 Hz square wave, 5 volt peak-to-peak and a +2.5 offset so that the voltage
swings between 0 and 5 V. Observe the output of the counter on the LEDs. What is the frequency of the QA,
QB, QC, and QD outputs? Increase the frequency to 32 KHz and use your oscilloscope to measure the frequencies
of QA, QB, QC, and QD. What is the relationship between the clock and these frequencies? This demonstrates
that a single oscillator frequency can be divided down to a lower frequency, which might be a handy capability in
the near future. In the next section, well divide it even further by cascading two counters. In the Digital Logic
lab, well use logic gates to access divisors that are not just multiples of two.
5
Cascade Two Counters
Remove the LEDs and pull-up resistors. Place a second 74161 counter on the breadboard and configure it like
the first. Wire QD of the first counter to CLOCK of the second counter. Using your oscilloscope, measure the
frequencies of QA, QB, QC, and QD on the second counter.
5.1
Accuracy Using a RC Relaxation Oscillator
If you had used your 555 oscillator as the input to CLOCK of the first counter with a nominal oscillation frequency
of 32 KHz, what would be the potential range of frequencies you would measure on QD of counter 2 if the resistors
you used to set the 555 frequency had a gold, silver or no band in the final color-code position? What would be
the frequency drift with a 50 degrees C temperature swing if the temperature coefficient of the resistor was 25
parts per million per degree C?
When you are finished, leave both counters wired on your breadboard!
6
Extra Credit: Using Schmmitt Triggers for debounce.
Schmitt Triggers are wonderful little diodes. Without getting into it too much, they snap the input voltage either
high (5V) or low (0V), which is quite handy when it comes to debouncing switches. You still have to use the
debounce circuit, but now instead of one level of debouncing, we will have two! All you have to do is get a Schmitt
Trigger diode and set it up at the output of your debounce circuit, and the output to the counter should be fairly
uniform!
VCC
5V
R1
R2
Schmmitt Trigger
To 74HC161
J1
C1
Figure 5: Debounce Circuit with additional Schmmitt Trigger Debounce.
Version 2.1, November 6, 2014
Page 4