[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

You should find that this value is only a few tenths of a milli-amp.A. Version 2. the current flow must still be limited to about 6mA to 10mA so the LEDs dont burn out. the counter chip will try to provide as much current as the LED wants for a given voltage level. they do not provide enough current. Figure 3: A four-bit counter driven by a bouncing switch and a pull-up resistor. Figure 2: Switch Wiring Diagram. Actually. if the amount of current the LED demands is larger than what the chip is designed to handle. If you have any questions. November 6. the chip will overheat and perhaps burn out. check with your T. check which leads are the ends of the switch. There is a natural way to put the switch into the socket. Figure 2 may help you determine which leads are which. Figure 3 shows a switch (J1) and a pull-up resistor wired to the clock input of a counter. A secondary issue is that even if the counter can provide enough current to the LEDs.[ECEN 1400] Introduction to Digital and Analog Electronics R. Using the multimeter.A. Although the counters can provide a high enough voltage level to turn on the LEDs. McLeod Get a little micro-switch and socket from your T. Look at the data sheet for the counter to understand the other pins of the 74161 counter. The switch has four leads coming out of it. Clearly this is not good enough to turn on an LED. Put the socket in your breadboard and then mount the switch into the socket. 2014 Page 2 .1. Check the datasheets of the counter for the maximum amount of output current that the counter can produce with a high output level. However. 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. This combination allows the switch to present either 5V or 0V to the chip input.

and a logical 0 turns it on. The .this is typical behavior for digital circuits. bounce is random and depends on the individual switch. 20 sec or 20 sec would probably not work well. You should sometimes see the count increment by more than one due to switch bounce. an LED can be switched on and off by the output of the counter. What is this value? It should be more than 6mA. A-D are default low (0000). 3. Making this time constant a little larger is better than making it smaller.2 Debounce the Switch Add an RC combination to smooth-out the switch transition as shown in Figure 4. Open and close the switch and observe the counter output. try using the switch again. A logical 1 turns the LED off. Figure 4: A four-bit counter driven by a debounced switch and a pull-up resistor. The circuit is similar to LED and transistor circuit from a couple weeks ago. using Figure 1. Increment the counter past roll-over (1111) and observe what happens to the count. November 6. However.end of the LED is connected to the counter output pin. Note that the LEDs are displaying NOT(QA).1 Build and test the counter with a bouncy switch. Explain.[ECEN 1400] Introduction to Digital and Analog Electronics R. Version 2. When the counter is producing a logic low voltage level. there is not enough voltage across the LED for it to turn on. After you have re-wired your circuit with this RC circuit. does the counter increment continually when the CLOCK pin is high. for example? Look at the datasheet for confirmation . When the counter output is producing a logic high voltage level.1. What specifically condition on the CLOCK pin causes a counter increment? That is. why 20 msec is reasonable and (for example). Notice that this is the reverse of what you might expect. NOT (QB) etc. The + end of the LED is connected to 5 Volts through a current-limiting resistor. Check that you get the correct count sequence with no skips. 2014 Page 3 . then ground pin 9 which loads the values on A-D into the counter. Select a combination of resistor and capacitor to produce a time constant around 20 msec. put the counter in an intermediate count between 0 and 15. so you might get lucky and not witness this. McLeod Now check the maximum amount of output current that the counter can produce with a low output value. 3. Finally. there is enough of a voltage drop across the LED for it to turn on. With this being the case.

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. and QD on the second counter. 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. leave both counters wired on your breadboard! 6 Extra Credit: Using Schmmitt Triggers for debounce. 5. Set the waveform to be a 1 Hz square wave. 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. 5 Cascade Two Counters Remove the LEDs and pull-up resistors.[ECEN 1400] 4 Introduction to Digital and Analog Electronics R. What is the frequency of the QA. Version 2. 2014 Page 4 . Observe the output of the counter on the LEDs. which is quite handy when it comes to debouncing switches. and QD outputs? Increase the frequency to 32 KHz and use your oscilloscope to measure the frequencies of QA. QB. measure the frequencies of QA. Wire QD of the first counter to CLOCK of the second counter. 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.5 offset so that the voltage swings between 0 and 5 V. well divide it even further by cascading two counters. Using your oscilloscope. which might be a handy capability in the near future. In the next section. 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. You still have to use the debounce circuit. Without getting into it too much. QB. and QD.1. November 6. QB. they snap the input voltage either high (5V) or low (0V). but now instead of one level of debouncing. QC. QC. 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. Place a second 74161 counter on the breadboard and configure it like the first. well use logic gates to access divisors that are not just multiples of two. 5 volt peak-to-peak and a +2. QC. 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. Schmitt Triggers are wonderful little diodes. In the Digital Logic lab.