C729 of 57
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

C7 · Lesson 29 · Designing counters

Any sequence from flip-flops, with D, T and JK inputs

A binary counter counts 0, 1, 2, and so on. Real designs want other sequences: divide by 6 for a clock, count in Gray code for a crossing between clock domains, step a motor through a pattern. Any sequence is a little state machine with no inputs, and designing one is mechanical: list the transitions, write the next-state logic from a table, and check what happens if the counter wakes up in a state you didn't plan for.

Play

  • This counter counts 0 to 5 and starts over: a divide-by-6. Its three flip-flops follow the next-state equations below.
  • Watch the waveforms: Q2 is high for two counts of six, so its frequency is a sixth of the clock's.
  • The two unused codes, 6 and 7, never appear. The third example below shows what would happen if they did.

Predict

A divide-by-6 counter uses three flip-flops, so codes 6 and 7 are never meant to occur. If noise at power-up leaves it in state 7, what should a careful design guarantee?

Name it

The procedure

  1. List the states in order and the flip-flops needed, ⌈log2⁡(states)⌉.
  2. Write a table of each present state and its next state. Unused states are don't-cares.
  3. For each flip-flop, find the input that produces the next state (see below), and minimize it with a Karnaugh map.
  4. Check every unused state: where does it go? Fix any that don't lead into the cycle.

Flip-flop inputs

  • D: D=Q+, the next state itself.
  • T (toggle): T=Q⊕Q+, 1 when the bit must change.
  • JK: from 0, J decides (J=Q+, K don't-care); from 1, K decides (K=Q+¯, J don't-care). The many don't-cares often make JK logic the simplest.

A binary counter with T flip-flops needs T0=1, T1=Q0, T2=Q1Q0: each bit toggles when all the bits below it are 1.

Synchronous against ripple

A ripple counter clocks each flip-flop from the one before: no logic, but the top bit settles only after every stage's delay, ntcq, and the outputs pass through false values on the way. A synchronous counter clocks every flip-flop together, so all its outputs change within one tcq.

Worked example

Derive the divide-by-6 counter's next-state equations with D flip-flops, using states 6 and 7 as don't-cares.

Show the solution
  1. The cycle. 000 → 001 → 010 → 011 → 100 → 101 → 000.
  2. Bit 0. Q0 toggles every time: Q0+=Q¯0
  3. Bit 1. Q1+ is 1 after states 1 and 2 only: Q1+=Q¯2(Q1⊕Q0)
  4. Bit 2. Q2+ is 1 after states 3 and 4: Q2+=Q1Q0+Q2Q¯0
  5. The don't-cares. Each is as simple as the don't-cares allow; in the map, cells 6 and 7 were free to be either.

Answer Q0+=Q¯0, Q1+=Q¯2(Q1⊕Q0) and Q2+=Q1Q0+Q2Q¯0.

Worked example

Design a 3-bit binary counter with JK flip-flops.

Show the solution
  1. Bit 0. It toggles every clock: from 0 it goes to 1 (J = 1) and from 1 to 0 (K = 1), so J0=K0=1.
  2. Bit 1. It changes only when Q0 = 1, so J1=K1=Q0.
  3. Bit 2. It changes when Q1Q0 = 1, so J2=K2=Q1Q0.
  4. Compare with the T counter. A JK flip-flop with J = K is a T flip-flop, so this is the T-counter's logic again.

Answer J0=K0=1, J1=K1=Q0 and J2=K2=Q1Q0.

Worked example

Where do the divide-by-6 counter's unused states go? And how long does an 8-bit ripple counter take to settle, with 1 ns per flip-flop?

Show the solution
  1. From 110. Q0+=1Q1+=1¯⋅(1⊕0)=0Q2+=1⋅0+1⋅1=1 giving 101 = 5.
  2. From 111. The same equations give Q0+, Q1+, Q2+ = 0, 0, 1, which is 100 = 4.
  3. Check the cycle. Both rejoin the cycle in one clock: self-starting.
  4. The ripple counter. Its top bit changes 8 ns after the clock edge when a carry ripples through all eight stages, and in between the count passes through wrong values.
  5. A synchronous counter. A synchronous 8-bit counter settles in one flip-flop delay, 1 ns, plus its logic, and never shows a wrong value at its outputs after that.

Answer 110 goes to 101 and 111 to 100, so the counter is self-starting; the 8-bit ripple counter takes 8 ns to settle.

Check

A divide-by-6 counter counts 000 to 101 and wraps. Write Q1+, using states 6 and 7 as don't-cares.

Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.

Check

For the same counter, write Q2+.

Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.

Check

A flip-flop is at 0 and must go to 0 on the next clock.

(a)

What T input does that need?

(b)

What D input?

Check

An n-bit counter with n = 8 uses flip-flops with 0.5 ns of clock-to-Q delay.

(a)

As a ripple counter, how long does its top bit take to settle?

Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.

(b)

What's the highest clock at which its count can be read reliably after each edge?

Check

A counter must divide a clock f by N, using flip-flops with delay t.

Step 1

How many flip-flops?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Check

Write next_state(q) for the divide-by-6 counter (q from 0 to 7, bits Q2 Q1 Q0) using the equations from the first example, and settles(q) returning how many clocks it takes from state q to reach a state in 0 to 5 (0 if it's already there).

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

Why must a counter designer check the states the counter never uses?

Practice

Keep practicing

4 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.