C7 · Lesson 38 · Analyzing sequential circuits
From a schematic of flip-flops and gates to a state table, a diagram, and what the circuit is for
Lesson 37 went from a description to a state machine; lesson 39 will turn a design into flip-flops and gates. This lesson runs the other way, which is what you do when you inherit a schematic, debug someone else's board, or check that a synthesized netlist does what the description said. The method is mechanical: the flip-flops' outputs are the state, their inputs are the next state, and a table of every state, including the ones that should never happen, tells you what the circuit does. Those "impossible" states matter. A circuit that powers up in one of them may never leave, and finding that on paper is much cheaper than finding it in the field.
- Two D flip-flops wired as and . Run the clock and read the state off the waveforms.
- It steps 00 → 01 → 11 → 10 → 00: a four-state counter in which only one bit changes per step, a two-bit Johnson counter.
Predict
A 3-bit ring counter has , , and is meant to circulate a single 1: 001 → 010 → 100. It powers up in state 000. What happens?
It stays at 000: every flip-flop copies a 0. The ring counter has eight states, but only three are in its intended cycle. 000 and 111 each lead to themselves, and 011 → 110 → 101 → 011 is a second, unwanted cycle. A circuit that can get stuck outside its intended cycle has lockout. The fix is to design the unused states' next states on purpose, or to guarantee a reset.
Name it
The procedure
- State variables: each flip-flop's output. flip-flops give up to states.
- Next-state equations: for D flip-flops, . For T flip-flops, . For JK flip-flops, .
- Output equations: if the outputs depend only on the state, it's a Moore machine; if they also depend directly on the inputs, Mealy.
- State table: for every present state and input, the next state and output. Include every state, not just the expected ones.
- State diagram: draw it, and describe the behavior: a counter, a detector, a controller.
- Unused states: check where each one leads. If any can't reach the main cycle, the circuit can lock out.
Timing
The analysis also gives the fastest clock: the longest path from a flip-flop's output through logic to a flip-flop's input must fit in one period (lesson 27):
Self-correcting designs
A circuit is self-correcting when every unused state leads, in some number of clocks, into the intended cycle. The cheapest fix is often to change one next-state equation so the unused states fall through. For the ring counter, instead of keeps the three-state cycle and sends every other state into it.
Worked example
Analyze three T flip-flops with , , . What does the circuit do, and how fast can it run with 80 ps clock-to-Q, 40 ps AND gates and 30 ps setup?
Show the solution
- What each flip-flop does. toggles every clock, toggles when = 1, and toggles when .
- Trace it. From 000: 001, 010, 011, 100, 101, 110, 111, 000: a 3-bit binary up counter, using all eight states, so no lockout is possible.
- Find the longest path. It runs from or through the AND gate to :
- Maximum frequency. Wider counters chain more ANDs, or use lookahead, as adders do.
Answer a 3-bit binary up counter, which can run at up to 6.67 GHz.
Worked example
A circuit has one input , two D flip-flops with and , and output . Build its state table and describe it.
Show the solution
- Read the equations. remembers the last input; is 1 when the current and previous inputs were both 1.
- Build the state table.
| = 0 | = 1 | ||
|---|---|---|---|
| 00 | 00 | 01 | 0 |
| 01 | 00 | 11 | 0 |
| 10 | 00 | 01 | 1 |
| 11 | 00 | 11 | 1 |
- Describe it. The output is 1 one clock after two consecutive 1s have arrived: a "11" detector.
- Classify it. depends only on the state, so it's a Moore machine.
- Check for lockout. All four states are reachable and every one goes to 00 on a 0, so there's no lockout.
Answer a Moore machine that detects "11": is 1 one clock after two consecutive 1s.
Worked example
Check the ring counter of the predict question with changed to . Is it self-correcting?
Show the solution
- Tabulate. Each state goes .
- The intended cycle. 001 → 010 → 100 → 001.
- The unused states. 000 → 001; 011 → 110 → 100; 101 → 010; 111 → 110 → 100.
- Check. Every unused state reaches the cycle within two clocks: self-correcting, with one 2-input NOR gate in place of a wire.
Answer yes: every unused state reaches the cycle within two clocks.
Check
Two D flip-flops have and . The present state is 01. What is the next state?
Check
A ring counter has , , . From state = 010, what's the next state?
Check
Write the next state of a JK flip-flop.
Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.
Check
A 3-bit binary up counter built from T flip-flops: write .
Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.
Check
A sequential circuit's flip-flops have 80 ps clock-to-Q and 40 ps setup, and its longest logic path is 100 ps. What's its maximum clock frequency?
Write units the way you normally would: 1.5 GHz, 1500 MHz and 0.0015 THz are the same answer.
Check
A 4-bit Johnson counter has and . How many states are in its main cycle?
Check
A circuit's output is , where is an input and a flip-flop. What kind of machine is it, and what does that mean for timing?
Check
Write analyze(next_state, n) for a circuit with no inputs, where next_state(s) gives the next state of an n-bit state s. Return (cycles, lockout): cycles is a sorted list of the cycles' lengths (each cycle counted once), and lockout is True if more than one cycle exists. Test it on a ring counter and a Johnson counter of 5 bits, setting ring and johnson to the results.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
A board's 4-bit Johnson counter works perfectly after power-up on the bench but sometimes produces a wrong sequence after an electrostatic discharge. Explain how analyzing its unused states explains the failure, and how to fix it.
A 4-bit Johnson counter uses only 8 of its 16 states. The other 8 form at least one separate cycle, for example 0010 → 0101 → 1011 → 0110 → 1101 → 1010 → 0100 → 1001 → 0010, which never passes through the intended states. A clean power-up reset puts the counter in 0000, inside the main cycle, so the bench tests pass. A discharge can flip a flip-flop, landing the counter in an unused state, and from there it follows the wrong cycle indefinitely. Tabulating all 16 states finds this on paper. The fix is to make it self-correcting by changing one next-state equation so the unused states fall into the main cycle, or to add a detector that forces a reset when an illegal state appears.
Practice
Keep practicing
7 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.