Every control block is a finite state machine (FSM). The split that matters most in RTL is where outputs are computed: Moore machines drive outputs from state only; Mealy machines drive outputs from state plus current inputs. That one choice changes timing, area, and how you debug waveforms.
Moore: output = f(state). Registered, stable for the whole cycle in state.
Mealy: output = f(state, inputs). Can react combinationally to inputs within the same cycle.
Consider a simple controller: in IDLE wait for go; in GREEN assert light_green until timer_done; return to IDLE.
| Aspect | Moore | Mealy |
|---|---|---|
| Output source | Decoded from state only | Decoded from state + go, timer_done |
| Output timing | Changes only after state update (next posedge) | Can change same cycle as input (combo path) |
| Typical latency | +1 cycle vs minimal Mealy for same reaction | Can be 0-cycle reaction to inputs |
| State count | Often more states (output encoded in state) | Often fewer states (output on transitions) |
| Glitch risk | Lower if outputs registered from state | Higher if outputs are combo from inputs |
| Waveform debug | Outputs align cleanly with state bubbles | Outputs may pulse within a state |
Outputs live inside the state bubble. Transitions carry only input conditions — no output labels on arrows.
Moore: light_green is implied by being in GREEN — not written on the transition.
Outputs can appear on transition arcs — the machine asserts a signal while a condition is true, even before the state register updates.
Mealy: output actions ride on the edge label input / output.
Industry default: Prefer Moore (or Moore-style registered outputs) for chip-wide control signals. Use Mealy only when you need same-cycle response and you register or qualify the output path carefully.
// Moore traffic controller — outputs from state only
module moore_traffic (
input wire clk,
input wire rst_n,
input wire go,
input wire timer_done,
output wire light_green,
output wire light_red
);
localparam IDLE = 2'd0;
localparam GREEN = 2'd1;
reg [1:0] state, next;
always @(posedge clk or negedge rst_n)
if (!rst_n) state <= IDLE;
else state <= next;
always @(*) begin
next = state;
case (state)
IDLE: if (go) next = GREEN;
GREEN: if (timer_done) next = IDLE;
default: next = IDLE;
endcase
end
// Moore outputs — function of state ONLY
assign light_green = (state == GREEN);
assign light_red = (state == IDLE);
endmodule
// Mealy traffic controller — output from state + inputs
module mealy_traffic (
input wire clk,
input wire rst_n,
input wire go,
input wire timer_done,
output reg light_green
);
localparam S0 = 1'b0;
localparam S1 = 1'b1;
reg state, next;
always @(posedge clk or negedge rst_n)
if (!rst_n) state <= S0;
else state <= next;
always @(*) begin
next = state;
light_green = 1'b0; // default
case (state)
S0: begin
if (go) begin
next = S1;
light_green = 1'b1; // Mealy: assert on transition condition
end
end
S1: begin
light_green = 1'b1; // hold while in S1
if (timer_done) next = S0;
end
default: next = S0;
endcase
end
endmodule
Mealy outputs in always @(*) can glitch when inputs glitch. For external pins or long combo paths, register the output (always @(posedge clk)) — you get a "Moore-ish" timing profile with cleaner timing closure.
Outputs must be stable all cycle; easy waveform review; multi-clock or CDC output registers; protocol outputs sampled on clock edge.
You need minimum latency; fewer states matter (area in state reg); output is inherently tied to input condition (e.g. ack = req & ready).
Mealy next-state + Moore registered outputs: compute next_out combo, register to out. Best of debuggability and timing control.
next_state and output_decode blocks