Skip to content

Demo 6.5: Synchronous Counters, and the Price of Getting It Right

The last demonstration left a counter with a fault. Its four flip-flops were clocked in a chain, each by the one before it, so their outputs changed one after another rather than together. For a few tens of nanoseconds at every transition the four wires read a number that was not in the sequence: going from 7 to 8 it passed through 6, then 4, then 0.

The cause: the stages were clocked at different times. The fix is to clock them together, as Kuphaldt states:

connect all the clock inputs together, so that each and every flip-flop receives the exact same clock pulse at the exact same time

Do that and the ripple is gone at any clock speed, because there is no longer any ordering between the stages, and so no interval in which a false state can appear. Without further changes, however, the circuit no longer counts.

In a ripple counter, a stage toggled because it had just been clocked, and it had just been clocked because the output of the stage below it had fallen. The wiring carried the information. No logic was needed to select which stage toggled next, because the clock connections determined it.

Tie all the clocks together and that information is gone. Every flip-flop now receives the same clock edge at the same instant, and if all four are left in toggle mode then all four change at every edge. The result is 0000, 1111, 0000, 1111, which is a reliable divide-by-two on four wires at once and not a counter at all.

So additional logic must select which stages toggle on each edge. The rule is in the count sequence, and Kuphaldt states it in one line:

just before a bit toggles, all preceding bits are “high”

Which is an AND of everything below it. It is also the carry from the demonstration on binary arithmetic: adding one flips the bottom bit always, and carries into the next bit only if that bit was already 1, and the carry keeps going for as long as it keeps meeting 1s. A counter is an adder that only ever adds one, and the AND chain is its carry chain.

All clocked together shows the fix and the failure it causes. One button switches between every stage armed all the time, which does not count, and the gated version, which does. The rule is derived from the count table beside it.

The gating is the circuit: two AND gates, the enable lines drawn as waveforms next to the outputs, and stage boxes that turn amber a whole clock period before they toggle.

Up and down adds the second AND network from the Q̄ outputs, an OR per stage, and one control line to choose between them.

What it costs puts the delays back and compares the same 7 → 8 transition under both architectures, with the timing budget in nanoseconds.

Synchronous Counters, and the Price of Getting It Right

One clock for every flip-flop, the AND chain that decides whose turn it is, a control line that reverses the count, and where the speed limit went.

Tie all four clock inputs together, and the ripple is gone. So is the counting.

  • The ripple counter went wrong because its stages were working to different times: each was clocked by the one before, so they changed one after another.
  • Kuphaldt's fix is to remove the cause: "connect all the clock inputs together, so that each and every flip-flop receives the exact same clock pulse at the exact same time".
  • Now every flip-flop is triggered at the same instant and every output changes at the same instant. There is no ordering left for a false state to hide in.
  • But a chain worked out for itself which stages should change, because a stage was only clocked when the one below it had done something. Take the chain away and that information goes with it.
  • Leave every stage in toggle mode and all four now change at every edge. Press play and watch what that gives you.
  • So something has to tell each stage whether this is its turn, and the rule for that is sitting in the count table.
The J and K inputs
What it does0, 15, 0, 15, 0, 15 …
Animation speed1.50 clocks/s
t = 0.00 of 16
CLKone clock, every flip-flop, the same instantJKFF0JKQQQ001JKFF1JKQQQ101JKFF2JKQQQ201JKFF3JKQQQ30111111111every stage armed, every edge, so all four toggle together
CLKQ3Q2Q1Q00150150150150150150150150count
Ungated: four flip-flops toggling in unison is not a counter
  • Every stage is armed all the time, so every stage toggles at every edge: 0, 15, 0, 15, 0, and so on for ever.
  • It alternates between all zeros and all ones. As a divide-by-two on four wires at once it works perfectly, and as a counter it is useless.
  • This is not a subtle failure and it is worth meeting head on, because it says precisely what the gating has to supply.
  • In the ripple counter, a stage knew to toggle because it had just been clocked, and it had just been clocked because the stage below had fallen. The wiring carried the information.
  • With one shared clock, the wiring carries no information at all. Every stage is told the same thing at the same time, so something else has to say which of them it is meant for.
The rule, read off the count0 → 15
nowQ₃Q₂Q₁Q₀which togglenext
00000···11
10001··112
20010···13
30011·1114
40100···15
50101··116
60110···17
7011111118
81000···19
91001··1110
101010···111
111011·11112
121100···113
131101··1114
141110···115
15111111110

The third column marks which bits toggle at the next edge. Compare it with the second column and the pattern is unmistakable.

What the table is telling you
  • Q0 toggles at every single edge, without exception. It needs no condition at all.
  • Q1 toggles whenever Q0 is 1. Look down the table: every row with a 1 in the Q0 column has Q1 marked.
  • Q2 toggles whenever Q0 and Q1 are both 1.
  • Q3 toggles whenever Q0, Q1 and Q2 are all 1.
  • Kuphaldt states it in one line: "just before a bit toggles, all preceding bits are high".
  • Which is an AND of everything below it. Four flip-flops and two AND gates, and the counter is finished.
Why that rule is the right one
  • Adding one to a binary number flips the least significant bit always, and carries into the next bit only if that bit was already 1.
  • The carry keeps propagating for as long as it keeps meeting 1s, and stops at the first 0.
  • So a bit changes exactly when every bit below it is 1, because that is exactly when the carry reaches it.
  • This is the same carry you met in the demonstration on binary arithmetic, and the same one that runs along a row of full adders.
  • A counter is an adder that only ever adds one, and the AND chain is its carry chain.

Open All clocked together with the J and K inputs set to All tied to 1, and press play.

The count reads 0, 15, 0, 15, and repeats. Every stage is armed at every edge, so every stage toggles at every edge, and the counter alternates between all zeros and all ones.

This failure shows what the gating has to supply. The clock chain in the previous demonstration determined which stage toggled next, and once it is removed that information has to come from additional logic.

Now press Gated by the rule and it counts 0 through 15 properly. Look at what has not changed: all four outputs still move on the same edge, at the same instant. The counting has been recovered without giving that up.

Look at the table on the right, and specifically at the “which toggle” column against the binary column beside it.

  • Q₀ is marked on every row. It toggles every time, with no condition at all.
  • Q₁ is marked on exactly the rows where Q₀ is 1.
  • Q₂ is marked where Q₀ and Q₁ are both 1.
  • Q₃ is marked where Q₀, Q₁ and Q₂ are all 1.

That is Kuphaldt’s rule, and notice that the enables are always a run of 1s from the bottom with no gaps. There is never a case where Q₂ is armed and Q₁ is not, because the condition for a stage contains the condition for the one below it.

That nesting is what makes the circuit cheap, and it is the subject of the next tab.

Open The gating.

Because each condition contains the one below it, each stage can borrow the work already done:

StageConditionWhat it needs
FF₀alwaysJ and K straight to logic 1
FF₁Q₀one wire, no gate
FF₂E₁ · Q₁one two-input AND
FF₃E₂ · Q₂one two-input AND

Four flip-flops and two gates. No wire runs further than one stage, and no gate has more than two inputs, which is what keeps this arrangement practical when the counter is sixteen bits wide instead of four.

Turn on the enable traces and step through. The thing to watch for is when an enable goes high: it rises a whole clock period before the toggle it authorises. The gates compute, from the current outputs, which stages toggle at an edge that has not arrived yet. That margin is the timing budget of the circuit, and it is what the last tab is about.

Step to count 7. All three enables are high, all four stages are armed, and the next edge changes every bit at once. Step again and only E₀ is left.

Open Up and down.

Kuphaldt’s down rule is the mirror image of the up rule: “all preceding bits are low prior to a toggle”. So the down network is the same AND chain reading Q̄ instead of Q, and nothing else changes.

The symmetry comes from binary arithmetic:

  • Adding one carries into a bit when everything below it is 1, because the lower bits are about to run out and wrap.
  • Subtracting one borrows from a bit when everything below it is 0, because the lower bits are all 0 and are about to wrap to 1s.

Carry and borrow are the same idea from opposite ends, and 1s and 0s swap between them.

Build both chains, put an OR after each pair, and use one control line to select which chain reaches the OR. U enables the up chain and U̅ enables the down chain, so exactly one term can reach the OR. Use the FF1/FF2/FF3 buttons to expand any stage’s selector and watch the two AND gates and the OR while you flip U.

Then flip U while it is running. It reverses direction from its current count, without a reset.

Open What it costs and slide the delay up from zero.

The two panels show the same 7 → 8 transition under the two architectures, with the same propagation delay applied to both, so the only difference is the wiring.

  • The ripple counter passes through 6, 4 and 0, as it did in the last demonstration.
  • The synchronous counter goes straight from 7 to 8, at every setting of the slider.

There is no delay at which the synchronous counter produces a false state, because all four flip-flops are clocked by the same wire at the same instant and all four outputs change together one propagation delay later. There is no ordering, so there is no interval in which some have changed and others have not.

That is a stronger claim than “it is faster”. A ripple counter clocked slowly is still wrong for a few tens of nanoseconds at every transition. The synchronous counter shows no false state at any clock speed.

The synchronous counter still has a maximum clock frequency, but the gating logic now sets it rather than the output chain.

The gate outputs that arm each stage have to settle before the next edge arrives. If they have not, a flip-flop gets clocked while its J and K are still moving, and what it does then is not defined.

Three numbers, for 74LS parts:

  • 20 ns from a clock edge until Q has settled
  • 10 ns through one AND gate
  • 20 ns of setup, meaning J and K must be stable that long before the edge

Add them for the four-bit chained version: 20 + (2 × 10) + 20 = 60 ns, so about 16.7 MHz. The ripple counter of the same width managed 12.5 MHz.

Now switch between Chained AND gates and One wide gate per stage and watch the table:

WidthRippleSynchronous, chainedSynchronous, wide gates
4 bits12.5 MHz16.7 MHz20.0 MHz
8 bits6.25 MHz10.0 MHz20.0 MHz
16 bits3.13 MHz5.56 MHz20.0 MHz

The ripple counter loses a whole flip-flop delay per bit. The chained synchronous counter loses one gate delay per bit, which for these parts is half as much. The wide-gate version has no per-bit penalty, because the carry passes through a single gate however wide the counter is. The cost is fan-in, since the top stage of a sixteen-bit counter would need a fifteen-input AND.

That trade is the counter’s version of the same choice adders make between ripple carry and carry lookahead. In both cases, more gates and higher fan-in reduce the propagation delay.

Quiz
Select 0/1

Four JK flip-flops have all their clock inputs tied to one clock, and all their J and K inputs tied to logic 1. What does this circuit do?

Quiz
Select 0/1

In a synchronous up-counter, what condition arms bit Q₃ to toggle at the next clock edge?

Quiz
Select 0/1

Why can a synchronous counter never show a false intermediate count, however fast it is clocked?

Concept Match

Match each item to what it is

Quiz
Select 0/4

A four-bit ripple counter and a four-bit synchronous counter are both built from 74LS parts and both clocked at 1 MHz, far below either one's limit. Which statements are true? Select all that apply.

Five things to take away.

  1. Tie every clock input together and the ripple is gone at any clock speed, because there is no ordering left between the stages.
  2. That removes the information the chain was carrying. Every stage now receives the same edge at the same time, so gates must select which stages toggle. Ungated, all four toggle at once and the circuit does not count.
  3. The rule is the carry from binary addition: a bit toggles when all the bits below it are 1. Because each condition contains the one below it, four flip-flops need only two two-input AND gates.
  4. The down rule is the up rule with every input inverted, so a second chain from the Q̄ outputs, an OR per stage, and one control line give a counter that reverses on demand.
  5. The limit moved from the outputs to the inputs. There are no false states at any speed, but the gates must settle before the next edge: period > flip-flop delay + logic + setup. Around 16.7 MHz for a chained four-bit design, against 12.5 MHz for the ripple version, and the gap widens with every bit added.

Look at the structure of this circuit, with the counting set aside for a moment. It is a set of flip-flops holding a state, a block of combinational logic that looks at that state and works out the next one, and a clock that steps from one to the other. Nothing in that description mentions counting.

Replace the AND chain with different logic and the circuit steps through a different sequence. That is what the next demonstration does, and it does it by taking the logic away almost entirely: four flip-flops sharing a clock, with nothing between them, where the only decision left is what each D input is connected to. That one decision is enough to turn the same hardware into a store, into a shift register, or into a counter that steps through a chosen sequence rather than a derived one.

Choose the sequence, add inputs that change which way it goes, and you have a finite state machine, which is what a processor is made of and where this material is heading. You already have the tools: a state table saying what follows what, and Karnaugh maps to turn it into gates.

A counter is that construction with the simplest possible sequence, which is why the subject starts with it.