What a State Machine Is
A combinational logic circuit evaluates outputs based only on current inputs. In contrast, sequential control circuits must remember historical sequences.
For example, a traffic signal displays colors in a strict sequence: green, yellow, red, and back to green. To select the next color, the controller must record the current color.
A Finite State Machine (FSM) provides a structured mathematical model for sequential control systems.
Mathematical Definition
Formally, a Finite State Machine is defined as a six-tuple:
$$\mathcal{M} = (S, I, O, \delta, \lambda, s_0)$$
| Symbol | Mathematical Definition | Functional Description |
|---|---|---|
| $S$ | Finite set of states | The collection of all valid internal states |
| $I$ | Finite set of inputs | The collection of all external input symbols |
| $O$ | Finite set of outputs | The collection of all output symbols |
| $\delta$ | $\delta: S \times I \to S$ | Next-state transition function |
| $\lambda$ | Output function | Generates outputs from state (and inputs) |
| $s_0$ | Initial state ($s_0 \in S$) | The starting state after circuit reset |
The transition function $\delta(s, i)$ determines the next state from the present state $s$ and input $i$.
The output function $\lambda$ calculates output signals. If $\lambda$ depends only on the present state $s$, the machine is a Moore machine. If $\lambda$ depends on both present state $s$ and input $i$, the machine is a Mealy machine.
Canonical Hardware Architecture
Every synchronous FSM maps onto three distinct hardware blocks (Figure 1):
- State Register: A bank of edge-triggered D flip-flops that stores the current state code.
- Next-State Logic: A combinational logic block that evaluates $\delta(s, i)$ to generate data inputs for the state register.
- Output Logic: A combinational logic block that evaluates $\lambda$ to generate external control outputs.
All sequential memory elements reside exclusively within the state register. The next-state and output logic blocks contain no internal feedback loops or latches. This separation simplifies timing verification and formal analysis.
Formal State Example: Traffic Signal Controller
Consider a simple traffic light controller:
- State set: $S = {\text{GREEN}, \text{YELLOW}, \text{RED}}$
- Input: Timer expiration pulse ($T$)
- Outputs: Lamp illumination controls ($\text{GreenLamp}$, $\text{YellowLamp}$, $\text{RedLamp}$)
- Initial state: $s_0 = \text{GREEN}$
Figure 2 shows the corresponding state diagram.
A deterministic state machine specifies exactly one valid transition for each (state, input) combination.
Importance of Explicit State Modeling
Formally defining state diagrams provides essential engineering benefits:
- Completeness: Forces the designer to specify circuit responses for every possible input in every state.
- Determinism: Prevents conflicting transitions where identical input conditions map to different destination states.
- Unused State Handling: Identifies illegal binary states so designers can implement safe recovery paths.
Ad-hoc sequential circuits written without formal state definitions often fail under corner-case input sequences.
Practical Applications of State Machines
Finite state machines control sequential operations across digital hardware:
- Communication Protocol Controllers: Standards such as UART, SPI, I²C, USB, and PCIe define bus interactions as formal state machines.
- Peripheral Handshaking: Arbiters, memory controllers, and bus bridges coordinate data transfers using FSM control units.
- Microprocessor Control Units: In a central processing unit (CPU), an FSM steps instructions through fetch, decode, execute, memory access, and writeback cycles.
Practice Exercises
Problem 1
A digital lock receives decimal digits sequentially and asserts an unlock signal upon receiving the sequence: 3, then 7, then 2. Determine the required states and outline the state diagram.
Solution
The sequence detector requires four states:
IDLE: Initial reset state; waiting for digit 3.GOT_3: Digit 3 detected; waiting for digit 7.GOT_37: Digits 3 and 7 detected; waiting for digit 2.UNLOCK: Valid sequence detected; assert unlock output.
From IDLE, receiving 3 transitions to GOT_3; other digits remain in IDLE.
From GOT_3, receiving 7 transitions to GOT_37; receiving 3 remains in GOT_3; other digits return to IDLE.
From GOT_37, receiving 2 transitions to UNLOCK; receiving 3 returns to GOT_3; other digits return to IDLE.
The UNLOCK state asserts the unlock signal and returns to IDLE.
Problem 2
An FSM uses three D flip-flops for state storage. What are the theoretical minimum and maximum numbers of states this machine can implement?
Solution
With $n = 3$ flip-flops:
- Maximum states: $2^n = 2^3 = 8$ states.
- Minimum states for a sequential machine: 2 states (a single-state machine performs no sequential transitions).
The remaining unused binary codes (up to $8 - |S|$) represent illegal states. Designers must define recovery transitions if noise pushes the circuit into an unused state.
Problem 3
A state machine follows the transition table below. Starting in state $S0$, determine the final state after applying the input sequence: 1, 0, 1, 1.
| Present State | Input | Next State |
|---|---|---|
| S0 | 0 | S0 |
| S0 | 1 | S1 |
| S1 | 0 | S2 |
| S1 | 1 | S0 |
| S2 | 0 | S0 |
| S2 | 1 | S2 |
Solution
Trace the sequence step by step:
- Start in state $S0$. Input is 1: transition to $S1$.
- In state $S1$. Input is 0: transition to $S2$.
- In state $S2$. Input is 1: transition to $S2$ (self-loop).
- In state $S2$. Input is 1: transition to $S2$ (self-loop).
The final state is $S2$.
The next article compares the two fundamental state machine classes: Moore and Mealy machines.