Home
8State Machines & Sequential Circuit Design
8

Topic 8 of 13

State Machines & Sequential Circuit Design

Describe behaviour as states and transitions, reduce it, and turn it into flip-flops and gates.

← → move between slides · F full screen · M slide list

Before we start

Why this matters

How does a vending machine know you've paid exactly 75 cents, without caring one bit whether you fed it three quarters or fifteen sweaty nickels?

It isn't doing your maths homework — it just tracks which state it's in (0¢, 25¢, 50¢, 75¢…) and hops to the next one per coin, forgetting the coins the instant they're counted. That's a finite state machine, and the same trick runs traffic lights, video-game bosses, and your Wi-Fi's slightly awkward opening handshake.

Concept 1 of 4

States and machine types

A state is the stored condition of the system. A state diagram draws states as circles and transitions as arrows labelled with the input (and output). A state table lists present state, input, next state and output.

  • Moore machine: output = f(present state). Outputs are attached to states.
  • Mealy machine: output = f(present state, input). Outputs are attached to transitions and can react to the input immediately. Mealy machines often need fewer states.

N states need at least ⌈log₂N⌉ flip-flops. Five states need 3, ten states need 4.

Concept 1 of 4

States and machine types (cont.)

x=1x=1x=1x=0x=0x=0S0y=0S1y=0S2y=1
A generic 3-state Moore machine: the Moore output (y) is written inside each state circle since it belongs to the state itself, not to a transition. Input x=1 drives the machine around the cycle S0→S1→S2→S0; x=0 leaves it in place via the self-loop shown on each state.

Concept 2 of 4

State reduction

Two states are equivalent if, for every input, they give the same output and go to the same or equivalent states. Equivalent states can be merged, which saves flip-flops and logic. Procedure: build the state table, find rows that match, merge them (replace the removed state everywhere), and repeat until nothing more merges.

Concept 3 of 4

Design procedure

  1. Specification, then identify states.
  2. State diagram and state table.
  3. State reduction.
  4. State assignment (binary codes for states).
  5. Choose flip-flop type (D is often easiest, since D = next state).
  6. Derive excitation equations from the state table, using the excitation table for JK or T.
  7. Simplify with K-maps, draw the circuit, verify every transition and the reset behaviour.

Unused states appear when 2n exceeds the number of states. They can be treated as don’t-cares, but the design should be checked so that it returns to a valid state instead of locking up.

Concept 4 of 4

Sequence detectors

A sequence detector watches a serial input and raises its output when a target pattern, such as 101, appears. It must remember recent bits, so it needs states. With overlapping detection, the tail of one match can begin the next: 10101 contains two matches of 101. Try both machine types in the demo below and look at the D flip-flop equations it derives.

Concept 4 of 4

Sequence detectors (cont.)

x=1x=0x=1x=0x=0x=1x=0x=1S0y=0S1y=0S2y=0S3y=1
The exact state diagram for this chapter's Moore, overlapping, 101 detector (matching the truth table on the next slide and the interactive demo below): S0→S1 on x=1, S1→S2 on x=0, S2→S3 on x=1 (S3, highlighted, is the only state with y=1). The self-loops (S0 on x=0, S1 on x=1) and the two lower return arrows (S2→S0 on x=0, S3→S2 on x=0) round out the table; the accent arrow S3→S1 on x=1 is what makes detection overlapping — the last 1 of a finished “101” is reused as the start of the next possible match, so 10101 is found twice.

Truth tables

Truth tables (1 of 3)

101 detector, Moore (overlapping)

Present statex = 0x = 1Output y
S0S0S10
S1S2S10
S2S0S30
S3S2S11

101 detector, Mealy (overlapping)

Present statex = 0 → next / yx = 1 → next / y
S0S0 / 0S1 / 0
S1S2 / 0S1 / 0
S2S0 / 0S1 / 1

Truth tables

Truth tables (2 of 3)

Flip-flops needed for N states

States NFlip-flops ⌈log₂N⌉
21
32
42
53
83
94
104
164
175

Truth tables

Truth tables (3 of 3)

The 7-state table from Worked example 2, before and after merging equivalent states, with a binary code assigned to each surviving state.

Before reduction (7 states)

Present stateNext, x=0Next, x=1Out, x=0Out, x=1
aab00
bcd00
cad00
def01
eaf01
fgf01
gaf01

After reduction, with binary assignment (5 states)

Present stateNext, x=0Next, x=1Out, x=0Out, x=1
a  000a 000b 00100
b  001c 010d 01100
c  010a 000d 01100
d  011e 100d 01101
e  100a 000d 01101

Interactive

Demo: 101 sequence detector

Worked example 1 of 3

Worked example 1

How many flip-flops do 10 states need?
Show the solution
  1. 23 = 8 < 10 ≤ 24 = 16.
  2. 4 flip-flops.

Worked example 2 of 3

Worked example 2

Reduce this table (present state: next state for x=0, x=1 / output for x=0, x=1): a: a,b / 0,0. b: c,d / 0,0. c: a,d / 0,0. d: e,f / 0,1. e: a,f / 0,1. f: g,f / 0,1. g: a,f / 0,1.
Show the solution
  1. g matches e (same next states and outputs). Remove g and replace it with e.
  2. Now f has next states e,f and d has e,f with the same outputs, so f ≡ d. Replace f with d.
  3. States a, b, c, d, e remain: 7 states become 5, saving one flip-flop (3 still needed, but simpler logic).

Worked example 3 of 3

Worked example 3

Analysis (the reverse of design): a Moore circuit has two D flip-flops A, B, one input x, and output y = x′·(A + B), with next-state equations A(t+1) = A·x + B·x and B(t+1) = A′·x. Starting from A = 0, B = 0, what output does the circuit produce for the input sequence x = 1, 0, 1?
Show the solution
  1. x = 1: A(t+1) = 1·(0+0) = 0, B(t+1) = 1·1 = 1, y = 0·(0+0) = 0. State becomes A=0, B=1.
  2. x = 0: A(t+1) = 0, B(t+1) = 0, y = 1·(0+1) = 1. State becomes A=0, B=0.
  3. x = 1: A(t+1) = 0, B(t+1) = 1, y = 0·(0+0) = 0. State becomes A=0, B=1.
Output sequence y = 0, 1, 0; final state A=0, B=1. Analysis starts from a circuit's equations and derives its state table and diagram — the opposite direction from the design procedure.

Practice

Practice (1 of 2)

Try each one on paper first, then check your answer.

1. Convert a state diagram into a state table.
Show the answer
For each state and each input value, write the next state and the output. One row per (state, input) pair.
2. How do you identify equivalent states?
Show the answer
Compare rows: same outputs for every input, and next states that are the same or themselves equivalent.
3. How many flip-flops for 10 states?
Show the answer
4

Practice

Practice (2 of 2)

Try each one on paper first, then check your answer.

4. Design a 101 sequence detector.
Show the answer
Use the simulator to get the state table and D equations, then build the circuit with D flip-flops in Gate Forge.
Practice in Gate Forge

Build the 101 detector from D flip-flops using the equations from the simulator.

Open Gate ForgeGate ForgeA free circuit simulator — place and wire gates, generate truth tables and timing diagrams, and work through 90+ guided problems.

Check yourself

Quiz

Summary

Summary

  • Moore output depends on state. Mealy output depends on state and input.
  • Flip-flops needed = ⌈log₂N⌉.
  • Merge equivalent states before assigning codes.
  • With D flip-flops, the D input equals the next-state bit.
  • Check unused states for lock-up.