13 Counters and Oscillators: 13.1 Binary Counter

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

13 Counters and Oscillators

Due date: Sunday, November 22 (midnight)


Reading: HH sections 8.03, 8.25, 5.14, 5.19 (pgs. 473–478, 524–525, 286–291, 300-303)

Though specialized, the counter is possibly the single most likely digital circuit that you
are likely to use. We will see how typical counters work, and also how to interface data with
an LED display. Of course, counters and many other circuits often require a clock as well,
and we will discuss two types of oscillator circuits that can serve this purpose. Note that we
won’t end up using the circuit from last week, you can clean it up to make space on your
breadboard.

13.1 Binary Counter


The 74LS193 chip is a typical 4-bit binary counter. It has several useful features: it can count
up or down, it can be initialized to an arbitary value, and it has outputs to faciliate cascading
multiple chips. Figure 1 shows the pin designations, with the following descriptions:
Vcc, Ground: Supply voltages as usual.
Qi : Output bit i. Bit A is the least significant.
Up: Increments counter output by one when a rising edge is received.
Down: Decrements counter output by one when a rising edge is received.
Clear: When high, forces all output low.
Load: When low, each output Qi is set to the value at input Di .
Carry: Goes low when output wraps from 1111 to 0000 when counting up.
Borrow: Goes low when output wraps from 0000 to 1111 when counting down.
Note that a trigger input (Up or Down) that is not being used must be held in the high
state.
Wire up the chip with Clear tied to ground and the Down trigger tied to 5 V. Drive
the Up trigger with the Sync pulse from your function generator, with a frequency of 1 Hz.
Monitor the outputs Qi with channels 0-3 of the digital reader, and verify that they count
up at the expected rate. Drive the Down trigger instead and verify that the output counts
down.

B 1 16

B 2 15 A
A 3 14
4 13
5 12

C 6 11

D 7 10 C
8 9 D

Figure 1: Pin designations for 74LS193 4-bit binary counter.

1
Note, by the way, that if you include the trigger signal itself as data, you really have five
bits of counting capacity. If more capacity is needed, it is easy to cascade multiple chips.
Put your counter back into the upward counting mode. Then get a second 74LS193 and wire
it up like the first, but take the Up trigger from the Carry output of the first chip. Monitor
the four new outputs on channels 4-7 of the digital reader, and verify that the eight output
bits together count from 0 to 255.

13.2 LED Display


Watching the counter output on the Digital Reader is not very satisfying, nor practical.
Let us instead display the result on an LED numerical display. The HP 5082-7340 display
is convenient, because it has built in logic and drivers to convert a binary number to the
appropriate combination of illuminated LED bars. It displays one digit in hexadecimal
notation (4 bits), so you will need two displays.
The pinouts for the 5082 are shown in Fig. 2. Here In1 refers to the 1s-place bit, In2
refers to the 2s-place bit, etc. The Latch input causes the display to hold its current value
while the input is high. The Blank input causes the display to go dark while the input is
high. For our purpose, they should both be tied low.
Wire up both displays, using the four bits from the first counter to drive one and the
four bits from the second counter to drive the other. Verify that when the circuit is on, it
counts properly from 00 to FF. Try increasing the frequency of the clock signal. How fast
can it go so that you can still tell that the numbers are counting correctly?

13.3 Binary-Coded Decimal


Of course, we don’t usually work in hexadecimal notation. When working with numbers
meant to interface with humans, the normal practice is to use the binary-coded decimal
(BCD) convention. Here counting is done in base ten, but the numbers are stored in binary
representation. A 4-bit BCD counter’s output would thus go:

8 1 In2 1 8 In1
7 2 In4 2 7 Vcc
6 3 In8 3 6 GND
5 4 Blank 4 5 Latch

Bottom View Top View

Figure 2: Pin designations for the HP 5082-7340 LED hexadecimal display. Note the iden-
tifier dot on the bottom of the package.

2
0000 (0)
0001 (1)
0010 (2)
0011 (3)
0100 (4)
0101 (5)
0110 (6)
0111 (7)
1000 (8)
1001 (9)
0000 (0)
etc
The four bits are not used as efficiently as in a binary counter, but in most situations,
bits are cheap. When you need to convert binary data to BCD, you can use chips like the
74184/74185. (The ’184 converts BCD to binary, and the ’185 converts binary to BCD.) For
small circuits, however, it is more likely to be convenient to simply work in BCD throughout.
For instance, the 74LS192 is a BCD counter that is pin-compatable with the 74LS193. Try
simply replacing both ’193 chips with ’192s. Does your display now count in decimal? Make
sure you understand why you don’t need to change the display chip too. If you were storing
data in a RAM chip, would it matter whether it were binary or BCD?
One warning: encountering BCD where you don’t expect it can be very confusing. If you
are looking at a binary signal and see the sequence 01110011, you would normally interpret
it as hex 73, or decimal 115. With BCD coding, however, it represents decimal 73 (hex 49).
These are simply not the same, and if you don’t know which coding is being used, you can’t
be sure what the value is. It’s good to be aware of this ambiguity.

13.4 Timer
So far we have been using the function generator signal for our clock, but if you were building
a real circuit, you would not typically want to rely on an external signal. There exist a variety
of easy ways to generate an oscillating signal of your own. One of the most convenient is
the 7555 timer chip, shown in Fig. 3. The core logic is shown in part (b). Here the op amps
are serving as comparators, which we will see more of in the next lab. Since there is no
negative feedback, the op amp output simply rails postive or negative depending on whether
the positive or negative input signal is higher.
To operate as an oscillator, the 7555 is wired as in part (c). Also, the Reset signal must
be tied high. Since Trig and Threshold are tied together, refer to their common value as
T. Define α, β, and γ as in the diagram, so that we can refer to them while analyzing the
circuit.
Suppose that T is initially low. Then α will be low and β high. Since β is high, the lower
NOR is false and γ will be low. That makes the upper NOR true, and thus the output is
high. The capacitor will therefore begin to charge, with time constant RC. Eventually, the
T signal reaches Vcc /3, causing β to go low. Since the output is high, the lower NOR is still
false and γ remains low and the output doesn’t change.
Continue this analysis as the capacitor continues to charge. What happens next, and

3
Vcc
Threshold

Out
Gnd 1 8 Vcc Out
R
Trig 2 7 Discharge Threshold, Trig
Out 3 6 Threshold
C
Reset 4 5 Control

Trig

(a) (b) (c)

Figure 3: (a) Pin designations for 7555 timer. (b) Core logic functionality. Note that
the Reset, Discharge, and Control signals are not shown; consult the datasheet for more
information. (c) External wiring for operation as an oscillator.

then what happens after that? Demonstrate that the output will oscillate with a frequency
on the order of 1/RC. In fact, if you work through the math of the exponential charging
and discharging functions, you find the oscillation frequency should be 1/(1.4 RC).
Wire up a 7555 chip, using a 200 pF capacitor and a 100 kΩ resistor. Verify that the
output oscillates and compare its frequency to the expected value. You will probably want
to measure R and C to make an accurate comparison. Replace the resistor with a 100k pot.
What is the maximum frequency the circuit can produce? Choose a resistor/capacitor pair
to give a 1 Hz signal, noting that the device manufacturer recommends using a larger R and
a smaller C to minimize the output current required. Use your timer signal to drive your
counter, so that you have a self-contained circuit.
Two notes: First, the 7555 (and a handful of similar chips) are CMOS versions of the
original NE555 TTL chip, which is still available. However, the 555 chip draws a substantial
current spike from the power supply when it switches, and it can be difficult to prevent that
spike from affecting other parts of your circuit. The 7555 does not have that problem.
Second, the 555 and its relatives can do considerably more than just oscillate. It can be
wired to act as a monostable multivibrator, the oscillation frequency can be modulated, the
pulse width can be varied, and various other possibilities. If you have an electronics problem
involving the generation of some kind of timed pulses, it would be worth looking through
some application notes for the 555 chip.

13.5 Quartz-crystal Oscillators


It is difficult to achieve timing precision better than about 0.1% using the 7555 timer, or
any other RC-based circuit, due to thermal drifts in the component values. When greater
precision is required, the preferred solution is the quartz oscillator. This consists of a quartz
crystal that is precisely cut so that it vibrates mechanically at a particular frequency. Quartz

4
74HC04

10M

100k

Crystal
20 pF 20 pF

(a) (b)

Figure 4: (a) Equivalent electronic circuit for a quartz crystal. (b) Oscillator circuit based
on a quartz crystal.

is a piezo-electric material, so when it is subject to strain, it generates an voltage at its surface


and vice versa. It is therefore possible to drive the mechanical vibration with an electronic
signal.
The resulting system is somewhat complicated, but it works out that the crystal acts
electronically as the circuit of Fig. 4(a). Such a circuit could of course be constructed
electrically, but the advantage here is that the resonant frequency is stable to typically a few
parts per million. Quartz crystal oscillators are used, for instance, to generate the timing in
standard wristwatches, where 1 ppm corresponds to an error of about 1 second per week.
The simplest way to generate an oscillating signal using a quartz crystal is with the
circuit of Fig. 4(b). Here the first NOT gate is unstable, since its output drives its input.
The arrangement of resistors and capacitors ensures that the instability is large enough to
permit oscillation at the crystal frequency. The second NOT gate serves as a buffer, to
ensure that the output signal has a standard logic level and that loads on the circuit do not
affect the oscillation.
Wire up this circuit using a 74HC04 CMOS chip and a 1-MHz crystal. Also, filter the
chip’s power supply pin with a 1 µF capacitor. Adjust the resistor to obtain oscillation. The
signal will be clearer if you use a 10× scope probe. Measure the duration of ten periods and
compare the resulting frequency to the expected value. It is likely that any error you see is
due to the scope, rather than the crystal.
Try replacing the 1-MHz crystal with a 4-MHz and a 12-MHz crystal. You will likely
need to readjust the pot for each. Are you able to achieve oscillation? The 12-MHz crystal
may be difficult; can you guess what the problem most likely is?
When you are finished, clean up your circuits. In the next lab, we will look at converting
between analog and digital signals.

You might also like