Forum Discussion
Verilog 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 previous states, but it is stuck at "filter_data_64" state . See complete code below :
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
5 Replies
- Fpga_Egr_2025
Occasional Contributor
Here is the simulation results
- RichardT_altera
Super Contributor
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
- Fpga_Egr_2025
Occasional Contributor
HI Richard,
Yes changed the fsm to have two separate always block :
////////////////////////////////////always @ (posedge clk) beginif (~rst) beginstate <= idle;endelse beginstate <= nextstate;endend////////////////////////////////////always @(*) beginnextstate <= idle;case(state)idle:beginif(vld)beginrdy_sig <= 1'b1;nextstate <= buffer_data;endelse if (last)beginrdy_sig <= 1'b0;valid_no_reg <= valid_no;nextstate <= filter_data_state;end
- RichardT_altera
Super Contributor
Dropping a note to ask if my last reply was helpful to you.
Do you able to resolve the issue?
Regards,
Richard Tan
- RichardT_altera
Super Contributor
Thank you for acknowledging the solution provided. I'm pleased to know that your question has been addressed.
Now, I will transitioning this thread to community support. If you have any further questions or concerns, please don't hesitate to reach out. Please login to https://supporttickets.intel.com/s/?language=en_US , view details of the desire request, and post a feed/response within the next 15 days to allow me to continue to support you. After 15 days, this thread will be transitioned to community support.
The community users will be able to help you on your follow-up questions.
Thank you and have a great day!
Best Regards,
Richard Tan