4.7 Circuits That Move to a Beat: Digital Circuits and the Clock
The circuits we’ve looked at so far share a common name: digital circuits. Everything from Chapter 3’s AND and OR to the adder, MUX, latch, and flip-flop in Chapter 4 has been a digital circuit. (Some of these circuits have analog counterparts that do the same job, and there are a few analog circuits inside chips too, but every circuit in this book is digital.) I didn’t bring up the term at the start because I wanted to focus on starting from familiar circuits and building up one step at a time. Now let’s gather the circuits we’ve seen under the name digital circuit, and look at the clock — the signal that announces the “click” the flip-flop has been waiting for.
A digital circuit is a circuit that handles voltage as just two states, 0 and 1. The whole circuit follows the agreement we made in Section 3.1: “if the voltage is above the reference level it’s 1, and if it’s below, it’s 0.” Figure 4-11 compares this with an analog circuit. In an analog circuit, the voltage flows continuously like a wave and can be 2V or 3.7V, and every one of those values carries meaning. In a digital circuit the actual voltage also rises and falls a little, but the circuit reads it only as 0 or 1. (The figure uses 0V and 5V for the sake of explanation, but today’s chips usually use voltages of around 1V.)

Why read it as only two states? Comparing with analog circuits makes it clear. In an analog circuit, every voltage is a different value: 5V and 4.6V are different values, and so are 4.6V and 4.5V. So when the voltage wavers even a little, it’s interpreted as a correspondingly different value. With only two states, things are different. If we set the reference halfway between 0V and 5V, at 2.5V, then even if a 5V signal sent to represent 1 drops a little to 4.6V along the way, it’s still above 2.5V and is read as 1. Likewise, a 0V signal sent to represent 0 that creeps up to 0.3V is still read as 0. Inside a chip, voltages always waver a little as they pass through wires and gates, but a digital circuit still reads them as just two states. And it’s not only how they’re read: gates are physically built to send their output back out near a crisp 0V or 5V. So as long as the wavering stays within a certain range, the value is preserved even after passing through a great many gates.
In this way, a digital circuit can tell 0 and 1 apart clearly even when the voltage wavers a little within a set range. But once remembering circuits come in, another ambiguity appears: “when.” In Section 4.6 we said a flip-flop captures a value only at the moment of the “click.” So who announces that “click”? What would happen if the countless flip-flops in a chip each “clicked” according to their own clock?
Say we agree to “count to three and start together.” Without a single clock everyone follows, each person’s “three” can be different. Some count fast and some count slowly, so in the end everyone starts at a different moment. The same is true inside a chip. In a chip, as in Figure 4-12, flip-flops and computing circuits are lined up in a row: the value from the front flip-flop passes through a computing circuit to become a result, and the back flip-flop captures that result. But if each flip-flop had a different clock and “clicked” at a different moment, the back flip-flop could capture a result before the computation had even finished. Conversely, if the front flip-flop switched to the next value too early, the back one would receive the result of the wrong computation. The values themselves are clear, but the “when” is off, so the answer comes out wrong.

So a chip needs a beat that everyone follows together — a kind of shared sense of time. The signal that announces that beat is the clock. It’s the chip’s own timepiece. As in Figure 4-13, the clock repeats 0 and 1 endlessly at regular intervals and is delivered to every circuit that needs it (flip-flops and so on). (Some parts of a chip use different beats, but here let’s look at circuits that all follow a single clock.) The span from when the clock rises from 0 to 1 (the voltage going from low to high), falls back to 0, and continues until just before it rises again is called one cycle — one beat. The “click” from Section 4.6 is exactly the moment the clock rises from 0 to 1. Just as everyone starts together when they count to three while watching the same clock, all the flip-flops receive the same clock, so the whole chip can “click” at the same instant, and each part does its job at the right time, in step with the set beat.

Now let’s see how the earlier problem is solved, following Figure 4-12 from the front flip-flop. When “click 1” sounds, the front flip-flop captures its input and sends it out to the computing circuit. The computing circuit doesn’t wait for the clock. It’s a combinational circuit, like the doorbell in Section 4.6, so it starts computing the moment a value arrives. While this value passes through the computing circuit, no flip-flop changes its value until the next “click.” In the meantime, the computing circuit completes its result. Then, at the instant “click 2” sounds, the back flip-flop captures the finished result, and only then does the front flip-flop capture the next input. Compute for one beat, then hand the result over at the next “click.” That’s why an unfinished result never gets passed along and values never get mixed up. There are a great many such flip-flops in a chip, but because they all follow the same beat, the whole chip moves precisely.
Figure 4-14 shows this process in time order, together with the clock. When the front flip-flop sends out value 1 at “click 1,” the computing circuit’s output briefly passes through “computing,” shown with hatching, and becomes result 1. The back flip-flop captures this result 1 at “click 2,” and at the same moment the front one sends out value 2. The same thing repeats, one beat at a time.

What if a computation is too long to finish within one beat? There are ways to handle it. For example, we can split the computation into several stages and put flip-flops between the stages, so that each stage finishes within one beat. Or we can hold the front value steady while computing, and give the back flip-flop a separate signal that says “don’t take it yet,” like the E from Section 4.6, so that it takes the result only at the “click” that comes after the computation is done. Either way, the principle is the same: “take values only on the click.”
The speed of a clock is expressed as its period or its frequency. The period (T) is the time one cycle takes, and the frequency (f) is how many times a cycle comes around in one second. The two are reciprocals of each other (T = 1/f). For example, a clock whose cycle is 0.2 seconds comes around 5 times a second, so it’s 5Hz, and a clock whose cycle is 1 second is 1Hz. If the same job takes 3 cycles, it takes 0.6 seconds with the first clock and 3 seconds with the second. Figure 4-15 compares these two clocks.

So the higher the frequency, the faster a chip finishes the same job. The “3.6GHz” in a CPU’s specs means the clock “clicks” 3.6 billion times a second. But the frequency can’t be raised forever, because the computing circuit has to finish its computation within one cycle. If the cycle gets too short, the next “click” arrives before the computation is done, and the back flip-flop captures an unfinished result. On top of that, the more often it “clicks,” the more power it uses and the more heat it produces. So the clock frequency is set to a sensible balance between speed, power, and heat.
To sum up: digital circuits remove ambiguity about value by reading voltage only as 0 or 1, and the clock removes ambiguity about timing by making every flip-flop follow the same beat. Thanks to these two, a vast number of circuits can work together precisely inside a single chip. In the next section, building on our understanding of these remembering circuits, let’s take a deeper look at the memory spaces we glimpsed back in Section 2.3, from registers all the way to storage.