Three-Process Moore FSM
The three-process style splits an FSM into the state register, the next-state logic and the output logic, each in its own block. It is wordier than one block but much easier to read and review.
This module acts as a simple cyclical counter governed by a state machine. It has four states: S0, S1, S2, and S3. When the enable signal is asserted, the machine advances to the next state in the cycle (S0 to S1, S1 to S2, S2 to S3, S3 to S0). When the enable signal is de-asserted, the machine remains in its current state. The output is purely dependent on the current state, outputting 0 for S0, 1 for S1, 2 for S2, and 3 for S3.
The module is triggered on the positive edge of clk and uses an asynchronous active-low reset rst_n. On reset, the FSM enters S0 and the output goes to 0. The output logic must be combinational and based solely on the current state.
Cycle 1: rst_n=0 → state=S0, count=0
Cycle 2: rst_n=1, en=1 → state=S1, count=1
Cycle 3: en=1 → state=S2, count=2
Cycle 4: en=0 → state=S2, count=2 (hold)
Cycle 5: en=1 → state=S3, count=3
Cycle 6: en=1 → state=S0, count=0
Cycle 7: en=1 → state=S1, count=1
Cycle 8: en=1 → state=S2, count=2
| Signal | Direction | Width | Description |
|---|---|---|---|
clk |
input | 1 | Positive-edge triggered clock |
rst_n |
input | 1 | Asynchronous active-low reset; FSM enters S0 when asserted |
en |
input | 1 | Enable signal; FSM advances to next state on posedge clk when 1 |
count |
output | 2 | Current count value corresponding to the FSM state; combinational |
Constraints
- Clock edge must be
posedgeand reset must be asynchronousnegedge. - The FSM logic must be separated into exactly three blocks: one sequential block for the state register, one combinational block for next-state logic, and one combinational block for output logic.
- The
countoutput must strictly depend on the current state. - When
enis 0, the FSM must maintain its current state and output.
Topics
Solve this problem
Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.
Free to solve. A Codiode account keeps your progress.
The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.
Part of FSM Coding
Problem 1 of 15 in the FSM Coding track.
Related problems
Browse all problems · Verilog practice problems · Learning tracks