ecen 1400 lab 6 counters.pdf
TRANSCRIPT
-
[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, thischip counts the periods of an input line in the binary number system. Here we will work with 4 bit counters thatcan count from 0 to 15.
2 Components and Tools Required
From your kitBreadboard
Wires
Wire-cutters and pliers
Various resistors and capacitors
From the TAsTwo 74161 counter chips
On the Lab BenchVariable 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 oftimes 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 eventswhen only one is intended. For example, a switch used to increment a counter in (say) a digital clock would bevery annoying to use because the count could increment a random number of digits each time the button waspushed. 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 theswitch into the socket. There is a natural way to put the switch into the socket. If you have any questions, checkwith your T.A. The switch has four leads coming out of it. Using the multimeter, check which leads are the endsof 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 combinationallows the switch to present either 5V or 0V to the chip input. Look at the data sheet for the counter to understandthe 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 voltagelevel to turn on the LEDs, they do not provide enough current. Actually, the counter chip will try to provide asmuch current as the LED wants for a given voltage level. However, if the amount of current the LED demandsis larger than what the chip is designed to handle, the chip will overheat and perhaps burn out. A secondaryissue is that even if the counter can provide enough current to the LEDs, the current flow must still be limited toabout 6mA to 10mA so the LEDs dont burn out. Check the datasheets of the counter for the maximum amountof output current that the counter can produce with a high output level. You should find that this value is onlya 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 offby 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 connectedto the counter output pin.
Note that the LEDs are displaying NOT(QA), NOT (QB) etc. When the counter output is producing a logichigh voltage level, there is not enough voltage across the LED for it to turn on. When the counter is producing alogic low voltage level, there is enough of a voltage drop across the LED for it to turn on. Notice that this is thereverse 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 causesa 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 seethe count increment by more than one due to switch bounce. However, bounce is random and depends on theindividual switch, so you might get lucky and not witness this. Increment the counter past roll-over (1111) andobserve what happens to the count. Finally, put the counter in an intermediate count between 0 and 15, thenground 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 resistorand 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 betterthan 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] Introduction to Digital and Analog Electronics R. McLeod
4 Take the Modulo Operation of a Square wave
Remove the switch and other elements driving the CLOCK pin and instead connect the function generator toCLOCK. Set the waveform to be a 1 Hz square wave, 5 volt peak-to-peak and a +2.5 offset so that the voltageswings 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 frequenciesof QA, QB, QC, and QD. What is the relationship between the clock and these frequencies? This demonstratesthat a single oscillator frequency can be divided down to a lower frequency, which might be a handy capability inthe near future. In the next section, well divide it even further by cascading two counters. In the Digital Logiclab, 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 likethe first. Wire QD of the first counter to CLOCK of the second counter. Using your oscilloscope, measure thefrequencies 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 frequencyof 32 KHz, what would be the potential range of frequencies you would measure on QD of counter 2 if the resistorsyou used to set the 555 frequency had a gold, silver or no band in the final color-code position? What would bethe frequency drift with a 50 degrees C temperature swing if the temperature coefficient of the resistor was 25parts 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 eitherhigh (5V) or low (0V), which is quite handy when it comes to debouncing switches. You still have to use thedebounce circuit, but now instead of one level of debouncing, we will have two! All you have to do is get a SchmittTrigger diode and set it up at the output of your debounce circuit, and the output to the counter should be fairlyuniform!
VCC5 V
R1
R2
C1J1
To 74HC161
Schmmitt Trigger
Figure 5: Debounce Circuit with additional Schmmitt Trigger Debounce.
Version 2.1, November 6, 2014 Page 4
IntroductionComponents and Tools RequiredCount a switchBuild and test the counter with a bouncy switch.Debounce the Switch
Take the "Modulo" Operation of a Square waveCascade Two CountersAccuracy Using a RC Relaxation Oscillator
Extra Credit: Using Schmmitt Triggers for debounce.