About finite state machine

C

Chih-Hsu Yen

Guest
Typically, the text book told to program a FSM as follows:
always @( posedge clk )
begin
if ( reset )
cur_state <= S0;
else
cur_state <= next_state;
end

always @( cur_state or ..... )
begin
case ( cur_state )
S0: begin statement1; next_state = S1; end
S1: begin statement2; next_state = S2; end
.
.
.
endcase
end

However, if there have feedback assignments in next_state combination, e.g.,
enable = ~ enable, counter = counter + 1.
Could the FSM be programed as follows or have others alternative ways to
solve the combinational loop problems??
always @( reset or next_state )
begin
if ( reset )
cur_state <= S0;
else
cur_state <= next_state;
end

always @( posedge clk )
begin
case ( cur_state )
S0: begin statement1; next_state = S1; end
S1: begin statement2; next_state = S2; end
.
.
.
endcase
end
 
This is completely wrong.
To implement " enable = ~ enable" you have to add FF into the first
always as "enable <= enable_comb" and use it as " enable_comb = ~
enable" in the second one.

You can also use one always instead of two. Then all FSM outputs will
be a outputs from the FFs.
 

Welcome to EDABoard.com

Sponsor

Back
Top