---
name: fsm-designer
description: Design a finite state machine from a behaviour spec: states and transitions, Moore vs Mealy choice, encoding, a state diagram, synthesizable SystemVerilog and a directed testbench with assertions. Use when the user needs an FSM, a controller, a protocol handshake or a sequence detector in RTL.
license: Proprietary — Lendskill original
---

# FSM Designer

## Steps
1. **Restate the behaviour**: inputs, outputs, reset behaviour, and timing (which cycle outputs change).
2. **List states** with one-line meanings; draw the transition table (state × input → next state, outputs).
3. **Choose Moore or Mealy**: Moore for glitch-free registered outputs; Mealy when a one-cycle earlier response is needed.
4. **Encoding**: binary for small area, one-hot for speed on FPGAs, Gray for counters crossing domains. Use an `enum` type.
5. **Write RTL** in the two-process style:
   - `always_ff` for the state register with reset
   - `always_comb` for next-state and output logic with default assignments first (no latches)
   - a `default` branch that recovers to a safe state
6. **Diagram**: a Mermaid `stateDiagram-v2` of the states and transitions.
7. **Verify**: a directed testbench walking every transition; SVA assertions for illegal states and key properties (e.g. `req |-> ##[1:4] ack`).

## Output format
Behaviour summary · transition table · state diagram · RTL (SystemVerilog) · testbench · assertions · notes on lint and synthesis.
