Skip to content

Demo 6.3: Clocks and the Binary Count Sequence

The previous demonstration took a JK flip-flop apart. This one treats it as a single block and asks what you can build with it, and the answer rests on a single observation about how we write numbers down.

Write the numbers 0 to 15 in binary, one per line. Then stop reading across the rows, which is the natural thing to do, and read down the columns instead.

0000 Every column is a square wave.
0001
0010 The rightmost alternates every line.
0011 The next alternates every two lines.
0100 The next every four. The next every eight.
0101
0110 Each column is exactly half the
0111 frequency of the one to its right.
1000
...

Kuphaldt states it as: “the LSB will oscillate at the highest frequency, followed by the next bit at one-half the LSB’s frequency, and the next bit at one-half the frequency of the bit before it.”

This is more than a feature of the notation. It is the basis of every binary counter, because if the bits of a count are square waves at halving frequencies, then a device that halves a frequency is a device that counts. And you already have one: a JK flip-flop with both inputs tied high toggles once per clock edge, which is a division by two.

The other half of this demonstration is the horizontal axis. Everything here is drawn against t, with a clock frequency you choose, because a clock period is not a column on a diagram. It is a length of time, and at a gigahertz it is a nanosecond, in which light travels about 30 cm.

The binary count sequence puts the table and the four waveforms side by side and steps a cursor through them. The horizontal axis switches between clock periods and real time at whatever frequency you set, and the tables underneath give every bit’s frequency and period at that setting.

The JK as a black box is the device with its insides hidden. Set J and K, then click the clock and watch which of its two transitions it responds to. The rising-edge and falling-edge symbols are shown side by side so you can see that the difference between them is one bubble.

Dividing the clock by two ties J and K high and shows the result against the clock, with the frequency readouts following whatever you set on the first tab.

Clocks and the Binary Count Sequence

Why the columns of a binary count are square waves at halving frequencies, what a clock period is as a length of time, and the one flip-flop that halves a frequency.

Write out the count, then read down the columns instead of across the rows.

  • A four-bit unsigned count runs 0000 to 1111, which is 0 to 15, and then starts again.
  • Read across a row and you have a number. Read down a column and you have a square wave.
  • The least significant column alternates every count, so it is a square wave at half the clock frequency. The next alternates every two counts, at a quarter. Then an eighth, then a sixteenth.
  • Every column is exactly half the frequency of the one above it, all the way up.
  • That is not a coincidence about how we write numbers. It is the design of every binary counter, because a device that halves a frequency is a device that counts.
  • Everything below is drawn against time, and you can set the clock frequency to whatever you like. That second axis is the other half of this demonstration.
The clock1.000 GHz
1 Hz1 kHz1 MHz1 GHz
One clock period

1.000 ns

T = 1/f = 1/1.000 GHz

In that time, light travels

30.0 cm

about the length of your forearm

A signal in copper manages

19.8 cm

roughly two thirds of light speed on a board

1 GHz: a Raspberry Pi 2 or 3.

The horizontal axis
Animation speed1.50 clocks/s
t = 0.00 of 16 clock periods
CLKthe clockQ0LSB, f/2Q1f/4Q2f/8Q3f/160123456789101112131415012345678910111213141516clock periods

The amber marks are the clock's falling edges, which is where the count advances. The number between each pair of them is the count in force during that period, and the red line is where the animation has got to.

The count sequenceQ₃Q₂Q₁Q₀
nbinaryt from
000000 T
100011 T
200102 T
300113 T
401004 T
501015 T
601106 T
701117 T
810008 T
910019 T
10101010 T
11101111 T
12110012 T
13110113 T
14111014 T
15111115 T
Every bit's frequency at 1.000 GHz
bitdivides byfrequencyperiod
Q0 (LSB)2500.0 MHz2.000 ns
Q14250.0 MHz4.000 ns
Q28125.0 MHz8.000 ns
Q3 (MSB)1662.5 MHz16.0 ns
whole cycle1662.5 MHz16.0 ns

Sixteen counts take 16.0 ns, so this counter gets back to zero 62.5 MHz times a second.

The animation is not running at that frequency
  • The transport is set to 1.50 clock periods per second, because a human has to be able to see it.
  • The frequency you have chosen is 1.000 GHz, which is 6.7e+8 times faster.
  • So this is a slowed film. The shapes are right and the timescale is not, which is true of every timing diagram you will ever be shown.
  • The numbers in the tables are the real ones. Only the red cursor is slow.
What 1.000 GHz actually means
  • One clock period is 1.000 ns. That is the entire budget for everything the machine does between one tick and the next.
  • In that time light travels 30.0 cm, and a signal on a circuit board manages about 19.8 cm.
  • So at this speed the size of the board matters. A signal crossing a few centimetres of copper spends a real fraction of a clock period simply travelling, and no amount of clever design makes it faster.
  • This is also why fast processors are physically small and why their clock is distributed with such care: parts of the chip would otherwise disagree about what time it is.
  • None of this changes the shapes above. The same sixteen-count sequence happens either way, and only the axis changes.
Reading the picture both ways
  • Down a column of the table is across a row of the waveforms. They are the same data in two arrangements.
  • The table is the better one for answering "what is the count at step 11".
  • The waveforms are the better one for answering "what does this bit look like on an oscilloscope".
  • You will be asked both, and the second one is what you would actually measure on a bench.
  • Notice that Q0 changes at every falling edge, Q1 at every second one, Q2 at every fourth and Q3 at every eighth.
  • Notice also when each bit changes: only ever when all the bits below it are going from 1 back to 0. That observation is what builds the counter.
Why this is worth the fuss
  • A clock is not a power supply and it is not a start button. It is a shared opinion about when "now" is.
  • Every flip-flop in a machine looks at its inputs at the same instant, does one thing, and then waits. Between edges, nothing happens at all.
  • That is what makes a large circuit predictable: instead of signals arriving whenever they please, everything happens in step.
  • The price is that the slowest path in the whole design sets the clock period, and therefore the speed of the machine.
  • Which is why a processor is quoted in gigahertz, and why that number alone tells you rather less than the advertising suggests.

Open The binary count sequence and press play, or step through it one clock at a time.

Follow Q0 first. It changes at every falling edge of the clock: 0, 1, 0, 1, all the way along. Two clock periods make one complete cycle of Q0, so Q0 is a square wave at half the clock frequency.

Now follow Q1. It changes half as often, so its period is four clock periods and its frequency is a quarter of the clock. Q2 is an eighth. Q3, the most significant bit, changes just twice in the whole sequence, giving one cycle in sixteen clock periods.

Read the frequency table on the right and check those against the numbers. Then look at the highlighted row of the count table and confirm it agrees with the waveforms at the cursor.

Press Time at 1 GHz and watch the axis labels change while the waveforms stay where they are. It is the same picture with different units.

Now drag the frequency slider around, and read the two figures under the clock panel:

  • At 1 Hz, one period is a second and light travels 299,792 km in it, most of the way to the Moon.
  • At 32.768 kHz, a watch crystal, one period is 30.5 µs and light gets 9 km, across a city.
  • At 16 MHz, an Arduino Uno, one period is 62.5 ns and light gets 19 m, the width of a lecture theatre.
  • At 1 GHz, a Raspberry Pi 2 or 3, one period is 1 ns and light gets 30 cm.

Look more closely at that last one. In one clock period of a 1 GHz machine, light crosses about the length of your forearm, and a signal in copper on a circuit board manages only about two thirds of that, so 20 cm.

A Raspberry Pi is roughly 8 cm across. A signal getting from one side of it to the other therefore spends about half a clock period in transit. Nothing about the design can make that faster; it is the speed of light and the size of the board.

This is why fast computers are physically small, why a processor die is a few millimetres across, and why distributing a clock across a large chip so that the edge arrives at every part of it at the same time is one of the harder problems in the field.

Open The JK as a black box.

There are no gates here any more. There is a rectangle with three inputs and two outputs, and two pieces of notation that define its behaviour:

  • The small triangle against the clock input is the dynamic input indicator. It indicates that this input responds to an edge, not to a level. A latch has no triangle; that is how you tell the two apart on a schematic.
  • A bubble on the outside of the boundary means active low. On the clock input it moves the action from the rising edge to the falling one.

Set J = 1 and K = 1, then click the clock button twice and watch what happens. One of those two clicks toggles the output and the other has no effect, because a falling-edge device responds at one instant per clock cycle and ignores the rest of it.

Now switch to Rising edge and do it again. The device is now triggered by the other click. Compare the two symbols in the panel beside it: same box, same triangle, and one has a bubble.

Try each row of the table in turn, clicking the clock after each change:

JKWhat happens at the active edge
00Hold. The output keeps whatever it had.
01Reset. The output is forced to 0.
10Set. The output is forced to 1.
11Toggle. The output changes to the opposite of what it was.

Then change J or K without clicking the clock, and notice the output does not move. J and K do not act immediately: they set what happens at the next active edge. That separation is the reason for having a clock: the inputs can settle while the flip-flop ignores them.

The row that matters for everything after this is the last one. Hold, set and reset are all things a plain latch could do. Toggle is the one that needs the feedback, because the output depends on its own previous value, and that is what makes the circuit sequential rather than combinational.

Finally, press Pulse CLR low. The output goes to 0 immediately, with no clock edge involved. That is what asynchronous means, and it is how a counter is reset to zero without having to clock through the rest of the sequence. Note the bubble on that input too: it is active low, so an unused clear is tied high, which applies the pull-up resistor demonstration in a new context.

Open Dividing the clock by two.

J and K are now tied permanently to logic 1, so the only row of the state table available is toggle. At every active edge, the output toggles. That is the whole circuit.

Count the edges and the ratio follows:

  1. There is one active edge per clock period.
  2. There is one output transition per active edge.
  3. Every complete cycle of a square wave contains two transitions, one up and one down.
  4. So one output cycle needs two active edges, which is two input periods. Divide by exactly two.

Not approximately two, and not two on average. It is a matter of counting rather than of measurement, and nothing about it depends on the shape of the clock, how long it stays high, or the frequency.

There is a useful side effect: the output has a 50% duty cycle even if the input duty cycle was not 50%, because the output changes only at edges and is unaffected by what happens between them. Dividers are sometimes put into a circuit for that reason alone.

Now compare the Q waveform on this tab with the Q0 waveform on the first tab.

They are identical: one flip-flop in toggle mode produces the least significant bit of a binary count.

That raises a question. If one of these gives you the first column, what gives you the second? Q1 is half the frequency of Q0, and you have a device that halves frequencies, so feed Q0 into another one. Then a third, and a fourth.

Four flip-flops in a chain, each clocking the next, and the four outputs are the four columns of the count table. That is a counter, and it is the next demonstration.

Quiz
Select 0/1

In a four-bit binary count driven by a 1 GHz clock, what is the frequency of the most significant bit Q₃?

Quiz
Select 0/1

A JK flip-flop symbol has a triangle against its clock input and a bubble on the outside of that same input. What does that combination mean?

Quiz
Select 0/1

Why does a JK flip-flop with both inputs tied high divide its clock frequency by exactly two, rather than approximately two?

Concept Match

Match each item to what it is

Quiz
Select 0/4

Which of these are true of a clocked flip-flop between one active clock edge and the next? Select all that apply.

Five things to take away.

  1. The columns of a binary count are square waves at halving frequencies. The LSB runs at half the clock, the next at a quarter, the next at an eighth. Read down the columns rather than across the rows to see this.
  2. A bit changes only when every bit below it goes from 1 back to 0. That observation is the basis of the counter that the next demonstration builds.
  3. The triangle means edge triggered and the bubble means the falling edge. Two marks, two independent facts, and misreading the bubble halves the number of edges you thought you had.
  4. Toggle mode divides by exactly two, by a counting argument that has nothing to do with time, duty cycle or frequency. One toggling flip-flop produces the least significant bit of a binary count.
  5. A clock period is a length of time. One nanosecond at a gigahertz, in which light travels about 30 cm and a signal on a board about 20. That is the reason fast computers are small.

The next step follows from this. If one divider gives you the first column of the count, chain four of them and you have all four, which is an asynchronous or ripple counter. It works, and it has a fault: each flip-flop’s output arrives a propagation delay after its clock, so in a chain those delays accumulate, and for a few tens of nanoseconds the four outputs show a count that is not in the sequence. The synchronous counter fixes it by clocking every stage from the same signal and using gates to select which stages toggle. Both have demonstrations of their own, and both start from the two ideas on this page.