Fpga_Egr_2025
Occasional Contributor
10 months agoVerilog FSM stuck on one State forever
I am developing a fsm to latch on to incoming data and compute its average in verilog, but my fsm seems to be just stuck at one state. Although the simulation shows it did shifted perfectly in previ...
- 10 months ago
You have nextstate in your case statement, but state never updates to nextstate.
Fix it by adding a sequential block to update state at every clock edge.
always @(posedge clk) begin
if (~rst)
state <= idle;
else
state <= nextstate;
endI would recommend to checkout 'Two Always Block FSM coding style' from the article below.
It uses two separate always blocks:
- State Register Block: A sequential (always_ff ) block that updates the current state (state_reg) on the clock edge.
- Next State & Output Logic Block: A combinational (always_comb) block that determines the next state and the outputs based on the current state and inputs.
http://www.sunburst-design.com/papers/CummingsSNUG2019SV_FSM1.pdf
Regards,
Richard Tan