Chapter Eighteen

Let’s Build a Clock!

What a fun project it might be to build a clock! Imagine a big old-fashioned grandfather clock, with an intricately carved wood case and a glass door through which you can see the ponderous swinging pendulum. Behind the ornate metal dial is a complex of gears that keep time using a clever little mechanism called an escapement, the ticking and tocking of which reverberates throughout your home and triggers solemn chimes every hour.

But no. That’s not the kind of clock we’ll be building. The clocks in this chapter are instead digital clocks that display the hours, minutes, and seconds with numbers rather than rotating arms on a dial. In fact, the first version of this clock won’t even display conventional decimal digits but instead use flashing lights to show the time in binary.

I know, I know: A time display in binary seems awful! But that’s a necessary first step to representing the time with familiar decimal numerals. Moreover, the binary numbers that we’ll be using are actually a cross between pure binary and decimal.

Let’s first examine the numbers that make up the time. If we include seconds as well as minutes, a time display requires six decimal digits—for example:

12:30:47

That’s 12 hours, 30 minutes, and 47 seconds, about a half-hour past midnight or noon. An indicator for AM or PM would clarify that information.

In binary, this time could be represented with the binary equivalents of the numbers 12, 30, and 47:

1100:11110:101111

I don’t know about you, but I’d prefer not to see the time in that form. After I finished converting those binary numbers into decimal, the time might well be a minute later.

So let’s not do it that way. Let’s instead represent each decimal digit separately in binary so that the time of 12:30:47 is instead displayed using the binary numbers for 1, 2, 3, 0, 4, and 7, or:

00010010:00110000:01000111

Now you have six four-digit binary numbers to convert in your head to decimal, but the decimal values are all between 0 and 9, so the conversions are much easier. Moreover, just by watching the seconds tick by on such a clock, you’d be able to quickly learn to read and interpret these binary numbers.

There’s a name for this type of representation. It’s called binary-coded decimal, or BCD. With BCD, each digit of a decimal number is encoded as a four-digit binary number, as shown in the following table:

A table showing binary values from 0000 through 1001 and their decimal equivalents.

You’ve seen tables like this before, but they’ve usually continued past 1001 (decimal 9) to show 1010, 1011, 1100, 1101, 1110, and 1111—the binary equivalents of 10 through 15. With BCD, these additional binary numbers are invalid. BCD only goes up to 1001, and those other combinations of bits are not used.

This is yet another example of bits not telling you anything about themselves. If you encountered the number 10011001, you can’t tell what that is without some context. As an unsigned integer, it’s decimal 153, but as a two’s complement signed integer (which you learned about in Chapter 16), it’s –103. If it’s BCD, it’s 99.

BCD is not used much in the internals of computers because it complicates basic arithmetical operations such as addition and subtraction. But when it comes time to display decimal numbers, BCD is often an intermediary step.

The first clock that I’ll show you in this chapter will not necessarily display the correct time, but it will show seconds increasing from 00 through 59, and then minutes 00 through 59, and then hours. The decision to display the time in BCD implies that each of the six decimal digits of the time can be calculated individually, beginning with the seconds. Here are the six digits that compose the time, with the valid ranges of values:

  • Seconds, low digit, ranging from 0 through 9.

  • Seconds, high digit, ranging from 0 through 5.

  • Minutes, low digit, ranging from 0 through 9.

  • Minutes, high digit, ranging from 0 through 5.

  • Hours, low digit, ranging from 0 through 9.

  • Hours, high digit, either 0 or 1.

The low digit of the seconds increases steadily from 0 through 9. Every time that low digit reaches 9, it rolls over (or resets) to 0, and the high seconds digit is incremented (that is, increases) by 1: from 0 to 1, then to 2, to 3, to 4, and finally to 5. When the seconds reach 59, the next value is 00, and the minute increases by 1.

Each of the six digits in the time requires a separate circuit, which then affects the next circuit.

Let’s begin with the low digit of the seconds. You might begin by wiring up four edge-triggered flip-flops in a row, similar to the way that flip-flops were wired on page 235 of Chapter 17 to create a ripple counter. Each of the Q outputs of the flip-flops is connected to a light:

Four edge-triggered flip-flops wired to count in seconds from 0 through 15.

In Chapter 17, the flip-flops were wired from left to right; here they’re wired from right to left. As you’ll see shortly, this arrangement allows the lights to display readable binary numbers.

The input at the far right is an oscillator of some sort with a frequency of 1 Hertz, or one cycle per second. The period of this oscillator—the time required for one cycle—is 1 divided by the frequency, or 1 second. Every second that one-second oscillator goes from 0 to 1 and then back to 0.

The outputs of each flip-flop are Q and Q, which are opposite values. If Q is 0, then Q is 1. Each of the flip-flops has its Q output connected to its D (or Data) input. When the Clock input transitions from 0 to 1, that D input becomes the Q output. When that Q output transitions from 0 to 1, it also changes the state of the next leftmost flip-flop.

For the first flip-flop at the right, the Q output will be 0 for one second and 1 for the next second, turning the light off for a second and then on for a second. The period is two seconds, and the frequency has been divided in half. The second flip-flop from the right halves that frequency again, turning its light on for two seconds and then off for two seconds. And so forth.

The result is that the four blinking lights count the seconds in binary:

00000001001000110100111011110000

The lights will count 0000 to 1111 and then back to 0000, completing a cycle every 16 seconds.

But this is not what we want! We want the lights to count from 0000 to 1001 every 10 seconds. After it gets to 1001 (decimal 9) we want it to go back to 0.

Fortunately, we have used flip-flops that have a Clear input labeled Clr at the bottom of the flip-flop. When this Clear input is set to 1, the Q output of the flip-flop becomes 0 regardless of the other inputs. Moreover, all those Clear inputs can be set to 1 at the same time, causing the displayed number to go back to 0000.

When should these Clear inputs be set to 1? A displayed value of 1001 (decimal 9) is valid, but the next value 1010 (decimal 10) is not valid. So when the output of the four flip-flops is 1010—which is 10 in decimal—we want all the flip-flops cleared to zero.

This can be accomplished with an AND gate connected to two of the flip-flop Q outputs:

Four flip-flops that count seconds upward from zero but are cleared to zero when the value ten is about to be displayed.

In real life, the transistors that make up the flip-flops will be so fast that you won’t see the transition from 1010 to 0000. As soon as the Q outputs of the four flip-flops become 1010, the output of the AND gate is 1, the flip-flops are cleared, and they go back to all zeros. Visually, it will be a smooth transition from 1001 to 0000:

00000001001000110100010101100111100010010000

If you’re a little uncomfortable about using the flip-flop outputs to clear the flip-flops, your worries are not completely unjustified. There exist better ways to do this type of thing, but they are rather more complicated. If you were building a binary clock in real life, you should also be aware that there exist integrated circuits called decade counters that count from 0000 through 1001 and then gracefully transition back to 0000.

Now we’re counting seconds from 0 through 9, and very shortly you’ll see another circuit for the high digit of the second that counts from 0 through 5. When the four lights of the low digit go from 1001 back to 0000, the high digit should increase by 1, which means that we need a signal that goes from 0 to 1 at that time.

The output of the AND gate could be used for that purpose, but let’s take a little different approach by adding a NAND gate to this circuit:

Four flip-flops that count seconds from 0 through 9, and then output another signal with a period of 10 seconds.

Recall that the output of a NAND gate is opposite an AND gate. The output is normally 1 except when the two inputs are 1, in which case the output is 0. This NAND gate is wired so that the two inputs are 1 when the displayed number is 1001, or decimal 9. The output of the NAND gate will become 0 when the displayed number is 1001 and then go back to 1. This will happen every 10 seconds, and that transition from 0 to 1 can be an input to another edge-triggered flip-flop.

This timing diagram shows the 1-second period signal, the Q outputs from each of the four flip-flops (from right to left), and the 10-second period signal:

A timing diagram showing the 1 second period signal, the output of the four flip-flops counting from 0 through 9, and the 10 second period signals.

If you turn the diagram 90 degrees clockwise, you can see that the four flip-flops count from 0000 to 1001 and then go back to the beginning.

The output of that NAND gate is the input to the next stage of the binary clock, which counts the upper digit of seconds: 0, 1, 2, 3, 4, and 5. This stage only needs three flip-flops, but when it reaches 110 (decimal 6), all the flip-flops need to be cleared:

Three flip-flops wired to count the high digit of seconds from 0 through 5, output another signal with a 1 minute period.

The output of the NAND gate in this circuit becomes 0 when the displayed number is 101, or decimal 5. In combination with the previous four flip-flops, the clock is now counting from 000 0000 to 101 1001, or decimal 59, at which time all seven flip-flops go back to 0. Here’s the timing diagram for these three flip-flops:

A timing diagram showing the 10 second period signal, the output of the three flip-flops counting from 0 through 5, and the 1 minute period signals.

Again, turn the diagram 90 degrees clockwise to see how the flip-flops count from 000 to 101, and then go back to the beginning.

Now we have a signal with a period of 1 minute. We can begin counting minutes. Four more flip-flops are configured just like the earlier four to count minutes from 0 through 9:

Four flip-flops wired to count the low digit of minutes from 0 to 9.

That 10-minute period output can now be an input to another assemblage of three flip-flops for the high digit of the minutes, which is just like the high digit of the seconds:

Three flip-flops wired to count the high digit of minutes from 0 to 5.

And now, just when it seems that you’re in the home stretch of constructing an entire binary clock, you might begin to experience some forebodings of dismay.

With a 24-hour clock, the hour begins at 0 and goes to 23, but English-speaking countries generally use a 12-hour clock, and that introduces a problem. The hour has two digits, like seconds and minutes, but the hours don’t start at zero. By convention, noon or midnight is an hour of 12, and then the next hour is 1.

Let’s ignore that problem for a moment. Let’s assume that with a 12-hour clock, the hours go 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, and then back to 0, and that the time 00:00:00 is what we call midnight or noon.

But there’s still another idiosyncrasy with the hours: With seconds and minutes, clearing the low digits and clearing the high digits are independent of each other. The low digit must be cleared when it reaches 1010 (decimal 10), and the high digit must be cleared when it reaches 110 (decimal 6).

With the hours, the low digit must also be cleared when it reaches 1010. That’s the transition from 9:59:59 to 10:00:00. But both digits must be cleared when the high digit is 1 and the low digit is 0010. That’s the transition from 11:59:59 to midnight or noon, which we’ll be temporarily representing as 00:00:00.

This means that the low and high digits of the hour must be considered together. The five flip-flops here show how the two digits can be cleared under two different conditions:

Five flip-flops wired together to display hours from 0 through 11.

The four flip-flops at the right are wired very similarly to the low digit of the seconds and minutes. An AND gate clears the flip-flops when the number becomes 1010, and a NAND gate outputs a signal that transitions from 0 to 1 at the same time.

But another three-input AND gate on the far left near the top determines when the high digit of the hour is 1 and the low digits are 0010 (decimal 2), for a combined BCD value of 12. You might think you want to display 12 at this time, but then you’d be stuck with the problem of displaying the next value as 1. Instead, this three-input AND gate clears all five flip-flops so the displayed hour is 0.

This circuit successfully displays hours in sequence from 0 through 11. Now we only need to fix one problem: When the Q outputs of all the flip-flops are 0, we want the displayed hour to instead be 12, or 1 0010.

This can be accomplished with a five-input NOR gate, shown here at the far right:

Five flip-flops wired together with a five-input NOR gate to display hour 0 as hour 12.

Recall that the output of a NOR gate is opposite an OR gate. The output of this NOR gate is 1 only when all five inputs are 0. The output of that NOR gate is then an input to two OR gates on two of the digits. Hence, when the output of the five flip-flops is 0 0000, the lights display 1 0010, or decimal 12.

I haven’t yet mentioned the NAND gate at the far left. The output of this gate is normally 1 except when the hour is 1 0001, or decimal 11. Then the output of the NAND gate becomes 0. When the hour is no longer 11, the output goes to 1 again. This output can be used as input to another flip-flop that serves as an AM/PM indicator:

A single flip-flop to display AM and PM.

The complete binary clock combining all the components you’ve seen is available on the website CodeHiddenLanguage.com.

Images

As you’ve seen, each of the six digits of this clock uses a NAND gate to generate a clock signal for the next digit. The output of this NAND gate is normally 1 unless the two inputs are both 1. This results in a peculiarity when the clock first starts up. At that time, each NAND gate will have an output of 1, which triggers the Clock input of the first flip-flop of the next stage. When the clock starts up, the initial time will be set to:

1:11:10

That’s great if that’s the exact time you start up the clock, but otherwise you might want to be able to set the clock to the current time.

Some digital clocks get the time over the internet or from GPS satellites or from radio signals designed for that purpose. But for those that require the time to be manually set, you might have encountered clocks with multiple buttons that must be variously manipulated, perhaps in so complex a sequence that detailed instructions are required.

Interfacing with human beings is always a challenge, so let’s implement something very simple.

The seconds, minutes, and hours of the binary clock are connected right to left, as shown in this block diagram:

A block diagram showing how the second, minutes, and hours of the clock are connected.

Let’s add two switches to this circuit. Pressing the first of these switches will manually increment the minutes, and pressing the second switch will manually increment the hours. This approach is not an optimum solution: If the displayed time is 2:55 and you need to set it to a time of 1:50, you’ll need to press the minutes button 55 times and the hours button 11 times. But this approach has the advantage of simplicity. You won’t need detailed instructions to set the time.

The minutes normally increase when the seconds reach 59 and then go back to 00. That signal, labeled “1 minute period,” is normally 1, but it’s 0 when the high digit of the seconds is 5. Similarly, the signal labeled “1 hour period” is also normally 1, but it’s 0 when the high digit of the minutes is 5.

We want to alter those two signals when the switches to set the time are pressed. For example, if the “1 minute period” signal is 1 (which it is most of the time), then pressing the switch should make it 0, and releasing the switch should let it go back to 1. Similarly, if the signal is 0 (which it will be if the seconds are between 50 and 59), then pressing this switch should make the signal go to 1, and releasing the switch should allow it to go back to 0.

In other words, the switches to set the time manually should make those “1 minute period” and “1 hour period” signals the opposite of what they are normally.

This is one of the applications of the Exclusive OR, or XOR, gate, which was used in Chapter 14 to add two numbers together. The output of the XOR is the same as the OR gate except when both inputs are 1:

A table showing the XOR logical operation. The output is 1 when either input is 1 but not both.

Aside from its vital role in addition, the XOR gate can also invert a signal. When one input is 0, then the output of the XOR gate is the same as the other input. But when one of the inputs is 1, the output is the opposite of the other input.

Using XOR gates, adding switches to set the time manually then becomes quite simple:

Images

Two switches and XOR gates added to the binary clock to manually set the time.

As the seconds and minutes tick by on a binary clock, the effect can be quite hypnotic. Beginning in the 1970s, binary clocks with flashing lights were manufactured and sold as novelty items, often with prices that didn’t reflect the simplicity of the underlying circuitry. But for people who wish to learn binary numbers—or at least binary-coded decimal numbers—they do have some educational value.

For those who prefer the display of conventional decimal digits, there are alternatives. One of the most beautiful (in a technologically retro sense) is called a cold cathode display, which is a glass tube filled with mostly neon. Inside are overlapping wires shaped into numbers, each of which is connected to one of the ten pins at the bottom, starting with 0 at the far left:

A cold-cathode display tube showing all ten digits inside.

Not shown is another pin for the ground. Also not shown is a wire mesh connected to that ground that surrounds all these wires.

When a voltage is applied to one of the pins, the neon surrounding that number glows:

A cold-cathode display tube displaying the number 3.

The Burroughs Corporation introduced this type of display tube in 1955 and gave it the name of a mythological water sprite. They called it a Nixie tube.

You’ll need one of these tubes for each of the six digits of the time display. Conceptually, using a Nixie tube is fairly easy: You just need to design circuitry that applies power to one of the ten pins to light up that number. In actual use, it’s a little more difficult because more power is required than is generally available from the transistors in integrated circuits. Special circuits called drivers for Nixie tubes are available to supply the necessary current.

The digital circuitry for a Nixie tube must convert the binary-coded decimal numbers coming from the flip-flops into separate signals for each of the ten pins. When the number is 0000, you want a signal for the first pin representing 0. When the number is 0001, that’s the pin for the number 1, and when the number is 1001, that’s the last pin for the number 9.

You saw a circuit similar to this toward the end of Chapter 10 on page 114. An octal number was converted into signals to light one of eight lights. Such a circuit is called a decoder, and here it is expanded just a bit to accommodate BCD numbers. This circuitry is therefore called a BCD decoder:

Images

A decoder that converts four-bit binary-coded decimal to one of 10 pins of a Nixie tube.

I know that this circuitry looks insane, but it’s extremely methodical. The BCD number coming from four flip-flops is at the bottom. The red wires in the figure indicate that this number is currently 0101, the binary number for 5. Each of those four signals is inverted with an inverter, and various combinations of the original signals and the inverted signals all go into the ten four-input AND gates. For the AND gate corresponding to 5—the AND gate just to the right of center—the four inputs are:

  • The least significant (rightmost) BCD bit

  • The next-most significant BCD bit, inverted

  • The next-most significant BCD bit

  • The most significant (leftmost) BCD bit, inverted

These four inputs are all 1 only for the BCD number 0101.

A more common approach to displaying decimal numbers is a seven-segment display. This consists of seven elongated lights arranged in a simple pattern:

A seven-segment display.

When these displays are manufactured, generally there are seven pins on the back, one for each of the seven segments. An eighth pin is for the ground. Voltages applied to combinations of those seven pins light up the appropriate segments to show a particular decimal digit:

Decimal digits 0 through 9 as shown on seven-segment displays.

For the ease of wiring up the seven-segment display, each of the segments is assigned an identifying letter:

The seven segments of a seven-segment display assigned identifying letters from a through g.

The following table shows what segments must be lit for each decimal digit 0 through 9:

A table showing which of the seven segments must be lighted for the decimal digits 0 through 9.

Signals corresponding to the decimal digits are already available. They are the outputs of the AND gates in the BCD decoder that was just used to light up the Nixie tube.

Let’s look at the “a” segment first. This segment must be lit when the decimal number is 0, 2, 3, 5, 6, 7, 8, or 9. This means that the outputs of the eight AND gates corresponding to those numbers can be inputs to an eight-input OR gate:

An 8-input OR gate used to combine the eight outputs of the BCD decoder and generate a signal to light up the top segment of a seven-segment display.

You can do something similar for the segments “b” through “g.”

Or you might seek something a little simpler.

The “a” segment is lit up for numbers 0, 2, 3, 5, 6, 7, 8, or 9, which means that it’s not lit up for numbers 1 and 4. Therefore, you can use the outputs of the two AND gates corresponding to 1 and 4 as inputs to a normal two-input NOR gate:

A two-input NOR gate used to combine two outputs of the BCD decoder and generate a signal to light up the top segment of a seven-segment display.

The output of this NOR gate is 1 except when the inputs are the 1 or 4 signals. For these two numbers, the top segment is not illuminated.

These two approaches aren’t exactly the same. There might be times when you want the seven-segment display to be entirely blank rather than displaying a decimal digit. This can be achieved if none of the ten signals from the AND gates in a BCD decoder are 1. The eight-input OR gate would work correctly in that situation, but the two-input NOR gate would continue to illuminate the top segment.

If your seven-segment display will always be displaying a digit, then a seven-segment decoder can be built from a BCD decoder as shown here:

Images

Five NOR gates, one OR gate, and one inverter used with a BCD decoder to illuminate a seven-segment display.

Notice that NOR gates are used for five of the segments, but an OR gate and an inverter can be used for the other two.

Notice also that the AND gate at the far right isn’t connected to anything! This AND gate is associated with the display of digit 9, and all the segments for that digit are illuminated by the NOR gates and the inverter.

Seven-segment displays can also be wired to display the additional digits of hexadecimal numbers, but you’ll need some way to distinguish the hexadecimal B from an 8, and a hexadecimal D from a 0. One solution requires mixing uppercase and lowercase. Here are the letters A, b, C, d, E, and F:

The seven-segment display used for displaying hexadecimal letters A through F.

To represent all 26 letters, you’d need a few more segments, including diagonal segments. Common solutions are 14-segment displays and 16-segment displays.

You might wonder if you’ll need decoding circuitry for every digit that you need to display. You can do that if you want to, but to reduce the amount of circuitry, there are alternatives. A technique called multiplexing allows the decoding circuitry to be shared among multiple digits. The inputs to the decoder can be quickly shifted among different sources, and the outputs of the decoder can go to all the displays simultaneously. However, in synchronization with the shifting of the decoder among various sources, only one display is grounded. At any one time, only one digit is illuminated, but the shifting among the displays happens so fast that it’s usually not noticeable.

Still another approach to displaying numbers and letters is called a dot matrix, which is a collection of round lights arranged horizontally and vertically in a grid. The smallest grid that can handle all the numbers, punctuation, and unaccented letters of the Latin alphabet is five dots wide and seven dots tall, called a 5-by-7 dot matrix, shown here displaying the number 3:

A five-by-seven dot matrix display showing the number 3.

You might think that these little lights can be independently controlled using the technique shown earlier for the seven-segment display. But that wouldn’t work well. There are 35 of these little lights, and turning them off and on individually would require quite a lot of circuitry. Instead, a different approach is used.

Those 35 lights are light-emitting diodes, or LEDS. Diodes are small electrical components that are symbolized like this:

The graphical symbol for a diode.

Diodes allow electrical current to flow in only one direction—in this case, from left to right. The vertical line at the right symbolizes how the diode blocks current that would otherwise flow from right to left.

A light-emitting diode is a diode that shoots out photons as the current is flowing through. These photons register in our eyes as light. LEDs are commonly symbolized just like diodes but with little arrows representing rays of light:

The graphical symbol for a light-emitting diode is the same as a diode but with little arrows representing light rays.

Over recent decades, as LEDs have become brighter and cheaper, they now commonly light up our homes with less electricity and less heat than other types of bulbs.

The 35 LEDs that make up a 5-by-7 dot matrix display are wired like this:

A grid of 35 light-emitting diodes showing how they are connected in rows and columns.

Each LED is at the intersection of a row and column. In each row of LEDs, the diode inputs are connected, and in each column the outputs are connected. (An alternative scheme is for the inputs to be connected in columns and the outputs connected in rows, but there’s no substantial difference in how it works overall.)

This organization reduces the number of connections from 35 to only 12 for the 7 rows and 5 columns.

The downside is that you can illuminate only one row or one column of lights at a time. At first this seems horribly restrictive, but there’s a trick: If the rows and columns of the dot matrix are displayed in sequence very quickly, it will seem as if the entire display is lit up at once.

Look back at how the number 3 is displayed by the dot matrix. In the leftmost column, two lights are lit up: the top light, and the second to bottom. This can be accomplished by supplying a voltage to those two rows, and supplying a ground to the first column, like so:

The 5-by-7 dot matrix showing the lights lit up for the first column of the number 3.

If you trace through all the possible connections from the voltages to the ground, you’ll see that the diodes prohibit all other paths except those for the two illuminated lights.

For the second column of lights for the number 3, the top and bottom lights are lit up. To accomplish that, apply voltages to those two rows and supply a ground for the second column:

The 5-by-7 dot matrix showing the lights lit up for the second column of the number 3.

The other columns work similarly. For the rightmost column of the number 3, three lights must be lit up. Apply voltages to those rows, and supply a ground on that column:

The 5-by-7 dot matrix showing the lights lit up for the last column of the number 3.

Now we need to find a way to automate the process of supplying voltages to the rows of the dot matrix and supplying a ground to one of the columns.

Coming to the rescue again are diodes—but just regular diodes, not those of the light-emitting variety. Here’s how to wire up some diodes to resemble the number 3:

Diodes wired in rows and columns to encode the number 3.

Can you see the number 3 here? The diodes correspond exactly to the illuminated lights shown earlier that display the number 3. But again, these are not LEDs. They’re just regular diodes. The number 3 is essentially encoded in this collection of connected diodes.

This configuration of diodes is called a diode matrix. It’s storing information, specifically the position of the lights that must be illuminated to display the number 3. For that reason, this diode matrix is also considered to be a type of memory. Because the contents of this diode matrix cannot be changed without rewiring the diodes, it’s more precisely referred to as a type of read-only memory, or ROM.

This diode matrix ROM can help display the number 3 on a dot matrix LED display. Notice the wires corresponding to each column across the top. These correspond to the five columns of the dot-matrix display. The following diagram shows a voltage supplied to the first vertical wire on the left:

Diodes wired in rows and columns to represent the number “3” showing a voltage applied to the first column.

Because of the arrangement of the diodes, two voltages are available at the right. These correspond to the lights that must be lit in the first column of the LED for the number 3.

By applying voltages successively (and quickly) to the remaining columns, all the combinations of voltages for the LED dot matrix display can be generated.

The following diagram shows the diode matrix ROM and the dot matrix display wired together with some support circuitry. The diode matrix ROM is slightly reoriented from the one you’ve just seen, but it’s functionally the same:

A diode-matrix ROM and a dot matrix display wired together to display the number “3.”

Begin examining this circuit in the lower-left corner: We need a very fast oscillator, fast enough to switch lights on and off so quickly that the human visual system doesn’t even notice. This oscillator is an input to a counter built from three flip-flops. You’ve seen circuits like this before:

A counter that counts in binary numbers from 0 through 4.

This is similar to the counters used in the clock except that it only counts from 0 to 4, or in binary, 000, 001, 010, 011, and 100. Once it reaches 101, the AND gate clears the three flip-flops back to 0.

Those binary numbers are input to the 3-to-5 decoder shown at the left. This is a stripped-down version of the 3-to-8 decoder shown on page 114 in Chapter 10 and the BCD decoder shown earlier in this chapter. It’s stripped down because it only needs to decode three-digit binary numbers from 000 through 100 into one of five signals:

A 3-to-5 decoder that decodes a three-digit binary number into one of 5 signals.

As the three-digit binary number counts from 000 to 100, the decoder outputs are successively 0, 1, 2, 3, 4, and then back to 0 for the next cycle. Notice that the output labeled “4” does not require an AND gate, because Q2 is 1 only when the binary number is 100 or 4.

These five outputs, 0 through 4, correspond to the five columns of the diode matrix ROM at the left of the large diagram, which then supply voltages to the seven rows of the dot matrix display at the right. In real life, resisters would be inserted between the diode matrix and the dot matrix display to limit the current and avoid burning out the LEDs.

The voltages then go down into a box mysteriously labeled “3-to-5 Sinker,” which is the only new component of this circuit.

We need something in this circuit that’s a little unusual. In synchronization with the five signals going up through the diode matrix, we need some way to connect one of the five columns of the dot matrix display to ground. All through this book we’ve built circuits and logic gates that supply a voltage. Such a circuit can be described as a current source. But now we need the opposite. We need something that sinks a current—something that connects it to ground in an automated manner.

Let’s use those transistors that we learned about in Chapter 15. Here is one (at least in its symbolic form):

The symbolic representation of a transistor.

The three letters stand for base, collector, and emitter. A current applied to the base will allow current to flow from the collector to the emitter, which means that we can connect the emitter to ground.

The 3-to-5 sinker at the bottom of the large diagram is extremely similar to the 3-to-5 decoder. In fact, the same circuitry can be used for both. The only difference is that the outputs of the AND gates at the top (and the Q2 input) are connected to the base inputs of five transistors:

A circuit that successively connects five columns of the dot matrix display to ground.

The currents coming down through the five columns of the dot matrix display are then successively connected to ground by these transistors.

And now we have a complete circuit that will show the number 3 on a dot matrix display. Of course, this isn’t quite what we want. Just as with the Nixie tube and the seven-segment display, we want this circuit to display digits 0 through 9 coming from the clock. This requires expanding the diode matrix with the other nine digits and then implementing another level of selection using the BCD decoder.

Images

An animated version of this circuit displaying digits 0 through 9 is available on the website CodeHiddenLanguage.com.

But however much fun we might be having in displaying animated digits corresponding to binary numbers, the goal of this book is not to build a clock.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.238.71.155