Altera_Forum
Honored Contributor
10 years agoAbout styles of writing FSM
Hi,
I find many people on their blog suggest coding FSM as follow.
always @ (posedge clk or negedge rst_n)
if(!rst_n)
current_state <= IDLE;
else
current_state <= next_state;
always @ (*)
begin
next_state = x;
case(current_state)
S1: if(...)
next_state = S2;
...
endcase
end
always @ (posedge clk or negedge rst_n)
case(next_state)
S1:if(...)
out1 <= 1'b1;
else
out1 <= 1'b0;
default:...
endcase
end
Here is my style.
always @ (posedge clk or negedge rst_n)
if(!rst_n)
current_state <= IDLE;
else
case(current_state)
S1: if(...)
current_state <= S2;
...
endcase
always @ (posedge clk or negedge rst_n)
case(current_state)
S1:if(...)
out1 <= 1'b1;
else
out1 <= 1'b0;
default:...
endcase
end
My problem is that I cannot tell the advantages and disadvantages between them. Thank you in advance.