yeolyi.comSeongyeol's CS

Clock

If we connect an adder’s result to D of a D latch, we can remember the result of a calculation. But when should E be turned on? It might seem enough to turn it on as soon as the adder produces its answer, but the moment it “produces its answer” is less clear than you might think.

Until the result settles

A gate takes some time after its input changes before its output changes. In a ripple carry adder, the carry passes up one place at a time from the lowest place, so higher places settle later.

Below is an adder computing 1112 + 0. Raise B0 to 1 to make it 1112 + 12. The result C3~C0 doesn’t become 10002 (8) all at once. It changes from the lowest place up, in the order 0111 (7) → 0110 (6) → 0100 (4) → 0000 (0) → 1000 (8). 6, 4, and 0 are wrong values that only pass by briefly.

Storing the result during this time stores a wrong value. Storing it the moment 0100 appears would remember 7 + 1 as 4, and the next calculation would carry on from that 4. So we have to store it only after even the slowest place has settled.

Clock

That is why a computer sends every circuit a clock to keep them on the same beat. A clock is a signal that alternates between 0 and 1 at a regular period. The circuits agree to store their results when the clock changes from 0 to 1, and finish their calculations in between.

In the circuit demos, the clock is drawn as the part below.

  1. Click the CLK cell. Each click switches it between 0 and 1.
  2. Press the play button on the right. It alternates between 0 and 1 on its own, at a steady beat.

So the clock period has to be long enough for the slowest calculation to finish. The “3.2 GHz” in a computer’s specs means the clock alternates between 0 and 1 3.2 billion times a second. The faster circuits finish their calculations, the faster the clock can be.

Wrapping up

But the D latch as it is follows D the whole time E is 1, not just at the moment it changes. That becomes a problem in circuits where the stored value goes back into the calculation. Below is a circuit that inverts Q and feeds it back into D. We wanted it to flip once per clock, but how many times it flips while CLK is 1 depends on the speed of the gates, so it can’t be known in advance.

Change CLK from 0 to 1. Q flips not once but several times.

Like a counter that counts up by 1, or a CPU that runs a program one line at a time, most of a computer’s calculations use the current value to make the next one. The result is only well defined if one clock is exactly one step. How can we store a value only once, at the moment the clock changes from 0 to 1? Let’s find out in the next post.

Challenge

A machine has three calculating circuits, and after their inputs change, their results take 2 ns, 5 ns, and 4 ns (1 ns is a billionth of a second) to fully settle. If all three store their results on the same clock, how fast can the clock be, at most, in MHz? 1 MHz is a million times per second. Answer with a number.