Skip to content

Finite State Machines (FSM)

With latches/flip-flops and registers/register files, we have the building blocks to store state. The next question is: how does state evolve over time, and how does a circuit make decisions based on input and current state?

A finite state machine (FSM) is a standard abstraction for such sequential systems. Compared with a register file (data storage), an FSM focuses on control and flow: it uses a finite set of states to represent the system’s phase, and transitions between states under a clock.

Hardware decomposition:

  • State register (flip-flops) storing current state S(t)S(t)
  • Combinational logic computing next state and outputs based on S(t)S(t) and inputs X(t)X(t)

Core behavior:

S(t+1)=f(S(t),X(t))S(t+1) = f(S(t), X(t))

Outputs:

Y(t)={g(S(t)),Moore FSMg(S(t),X(t)),Mealy FSMY(t)=\begin{cases} g(S(t)), & \text{Moore FSM}\\ g(S(t), X(t)), & \text{Mealy FSM} \end{cases}

A Moore FSM output depends only on state; a Mealy FSM output depends on both state and input.

Experiment: Sequence detector (pattern 101)

Section titled “Experiment: Sequence detector (pattern 101)”
  • Understand how to model an FSM.
  • Write a Mealy FSM state diagram and state transition/output table.
  • Implement and verify a sequence detector in Logisim Evolution.
  • Simulator: Logisim Evolution

Input is a 1-bit serial signal AA. Output B=1B=1 when the most recent three inputs form exactly 101; otherwise B=0B=0.

We use a Mealy structure so BB can assert immediately when the last bit is received.

Task 1: State abstraction and state diagram

Section titled “Task 1: State abstraction and state diagram”

Define three states based on matched prefix:

  • S0S_0: no match (no valid prefix)
  • S1S_1: matched “1”
  • S2S_2: matched “10”

Draw the state transition diagram.

Task 2: State encoding and state transition/output table

Section titled “Task 2: State encoding and state transition/output table”

Encode the 3 states using 2 bits (Q1Q0)(Q_1Q_0), for example:

  • S0=00S_0=00
  • S1=01S_1=01
  • S2=10S_2=10

State 11 is unused; for robustness, force it to transition unconditionally back to S0S_0.

Complete the state transition/output table below.

Q1Q_1Q0Q_0AAQ1+Q_1^+Q0+Q_0^+BB
000
001
010
011
100
101
110
111

Table 3.1: State transition and output table for a 101 sequence detector.

Task 3: Derive logic equations and build the circuit

Section titled “Task 3: Derive logic equations and build the circuit”

Use D flip-flops for the state register:

  • D1=Q1+D_1 = Q_1^+
  • D0=Q0+D_0 = Q_0^+

Derive boolean expressions for D1D_1, D0D_0, and BB based on Table 3.1, then implement the circuit in Logisim Evolution.

Manually set AA and toggle the clock to generate rising edges. Verify with sequences such as:

  • A=1,0,1A=1,0,1: BB should be 1 on the third tick.
  • A=1,0,1,0,1A=1,0,1,0,1: BB should assert twice.
  • A=0,0,1,0,1,1A=0,0,1,0,1,1: BB is 1 only on the tick that completes “101”.
  • State diagram, completed Table 3.1, and expressions for D1D_1, D0D_0, and BB.
  • Circuit screenshot (2 D flip-flops + combinational logic).
  • Test record for at least 3 input sequences with per-tick state (Q1Q0)(Q_1Q_0) and output BB.

Why is it recommended to force unused state 11 back to the initial state instead of transitioning arbitrarily? How does this relate to reliability?

Experiment: 3-digit decimal counter (000 → 999)

Section titled “Experiment: 3-digit decimal counter (000 → 999)”

A counter is a classic sequential module: state registers that evolve under a clock. This experiment asks you to design a 3-digit decimal counter and display it using three 7-segment displays, counting from 000 up to 999 in a loop. The counter should also stop automatically when a specified stop condition is met.

  • Understand 7-segment encoding and implement digit-to-segment decoding.
  • Learn to decompose a complex circuit into reusable modules (counting cell, carry logic, display decoding, etc.).
  • Simulator: Logisim Evolution

Treat the counter as three cascaded decimal digits: ones, tens, hundreds.

  • ones increments every clock
  • ones rolling 9→0 produces a carry to tens
  • tens rolling 9→0 produces a carry to hundreds
  • 999 rolls back to 000

This can be designed using an FSM mindset where each digit is a 090\ldots 9 FSM.

A 7-segment display uses 7 LEDs to form digits. Logisim Evolution’s display is shown in Figure 3.8.

7-segment display showing 4

Figure 3.8: Example 7-segment display showing the digit 4.

Inputs:

  • CLKCLK: clock
  • RSTRST: reset (after reset, the value should be 000)
  • ENEN: count enable (EN=1EN=1 counts; EN=0EN=0 holds)

Outputs:

  • Three 7-segment displays showing hundreds/tens/ones digits.
  1. Base functionality (000 → 999 loop)

    • When EN=1EN=1, increment by 1 on each clock edge.
    • Sequence: 000, 001, 002, …, 998, 999, 000, …
    • Display all three digits on three 7-seg displays.
  2. Stop functionality (stop at 500+N500 + N)

    • Choose a two-digit decimal number NN (00–99), e.g., last two digits of your student ID or day-of-month.
    • Stop threshold is 500+N500 + N (i.e., a number between 500 and 599).
    • When the counter reaches that value, it should stop (hold display) until reset or re-enabled.
    • Explain your chosen resume behavior in your report.
  • Encapsulate a single decimal-digit counting unit as a subcircuit and reuse it for tens/hundreds.
  • Carry signals are the key to cascading digits.
  • Top-level circuit screenshot showing:
    • three digit counters, three 7-seg displays
    • CLK/RST/ENCLK/RST/EN
    • the stop-control path
  • Subcircuit interface documentation (inputs/outputs and meanings).