State Machine Factoring
One big FSM that handles both the command handshake and the data burst ends up with a state for every combination. Splitting it into a master FSM and a slave FSM keeps each one small.
The module solution coordinates read and write commands with a memory interface. The Master FSM waits for a valid command, captures the read or write type, issues a request to memory, and waits for an acknowledgment. Once acknowledged, the Master FSM delegates the data transfer to the Slave FSM and waits for it to complete. The Slave FSM manages a 4-beat data burst, driving an active flag and a 2-bit counter. By exposing the state registers of both FSMs as outputs, the factored architecture is strictly enforced.
Timing and Reset Rules:
- Clock edge:
posedge clk - Reset:
rst_nis an asynchronous, active-low reset. - Reset values:
master_stategoes to 0 (IDLE),slave_stategoes to 0 (IDLE),burst_cntgoes to 0, and the internal capturedcmd_rwregister goes to 0. All combinational outputs evaluate accordingly. - Master FSM Transitions:
2'b00(IDLE): Ifcmd_validis 1, capturescmd_rwinternally and transitions toWAIT_ACK.2'b01(WAIT_ACK): Ifmem_ackis 1, transitions toWAIT_DP.2'b10(WAIT_DP): Waits for the Slave FSM to complete. Whenburst_cntreaches 3, transitions toIDLE.
- Slave FSM Transitions:
1'b0(IDLE): When the Master FSM transitions fromWAIT_ACKtoWAIT_DP(i.e., Master is inWAIT_ACKandmem_ackis 1), the Slave FSM simultaneously transitions toBURST.1'b1(BURST):burst_cntincrements by 1 each clock cycle. Whenburst_cntis 3, transitions toIDLE.
Worked Trace (Single Read Command):
- Cycle 1:
rst_n=0 →master_state=0,slave_state=0,cmd_ready=1. - Cycle 2:
rst_n=1,cmd_valid=1,cmd_rw=0 → Master capturescmd_rw. - Cycle 3:
cmd_valid=0,mem_ack=1 →master_state=1 (WAIT_ACK),mem_req=1,mem_rw=0. - Cycle 4:
mem_ack=0 →master_state=2 (WAIT_DP),slave_state=1 (BURST),burst_cnt=0,dp_active=1. - Cycle 5: Inputs held →
master_state=2,slave_state=1,burst_cnt=1,dp_active=1. - Cycle 6: Inputs held →
master_state=2,slave_state=1,burst_cnt=2,dp_active=1. - Cycle 7: Inputs held →
master_state=2,slave_state=1,burst_cnt=3,dp_active=1. - Cycle 8: Inputs held →
master_state=0 (IDLE),slave_state=0 (IDLE),cmd_ready=1,dp_active=0.
FSM Architecture:
Cycle-by-cycle Waveform:
| Signal | Direction | Width | Description |
|---|---|---|---|
clk |
input | 1 | Positive-edge triggered clock |
rst_n |
input | 1 | Asynchronous active-low reset; all registers go to 0 |
cmd_valid |
input | 1 | Indicates a new command is available |
cmd_rw |
input | 1 | Command type: 0 for Read, 1 for Write |
mem_ack |
input | 1 | Memory acknowledges the request |
cmd_ready |
output | 1 | High when Master FSM is in IDLE (0) |
mem_req |
output | 1 | High when Master FSM is in WAIT_ACK (1) |
mem_rw |
output | 1 | Captured cmd_rw value; 0 when Master is in IDLE |
dp_active |
output | 1 | High when Slave FSM is in BURST (1) |
burst_cnt |
output | 2 | 0 to 3 counter active during BURST |
master_state |
output | 2 | Master FSM state: 0=IDLE, 1=WAIT_ACK, 2=WAIT_DP |
slave_state |
output | 1 | Slave FSM state: 0=IDLE, 1=BURST |
Constraints
- The design must strictly implement the two separate FSM state variables as defined in the port list.
cmd_rwmust be captured into an internal register only whencmd_validis asserted while the Master FSM is inIDLE.- The Slave FSM and Master FSM must transition simultaneously when handing off execution (i.e., Master enters
WAIT_DPon the exact same clock edge that Slave entersBURST). - All outputs except the state registers,
burst_cnt, and the capturedcmd_rwmust be combinational logic based on the current state.
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 Synthesis Intuition
Problem 20 of 25 in the Synthesis Intuition track.
Related problems
Browse all problems · Verilog practice problems · Learning tracks