The following is the state transition table for a Moore state machine with one input, one output, and four states. Implement this state machine. Include an asynchronous reset that resets the FSM to state A.
下面是一输入一输出四状态的摩尔状态机的状态转移表。实现这个状态机。包括将 FSM 重置为状态 A 的异步重置。
module top_module(
input clk,
input in,
input areset,
output out); //
parameter A=2'd0,B=2'd1,C=2'd2,D=2'd3;
reg [1:0] state;
reg [1:0] next_state;
always @(posedge clk or posedge areset) begin
if (areset==1)
state<=A;
else
state<=next_state;
end
always @(*) begin
case (state)
A:if (in==0)
next_state=A;
else
next_state=B;
B:if (in==0)
next_state=C;
else
next_state=B;
C:if (in==0)
next_state=A;
else
next_state=D;
D:if (in==0)
next_state=C;
else
next_state=B;
default : next_state<=A;
endcase
end
always @(posedge clk or posedge areset) begin
if (areset == 1'b1)
out <= 1'b0;
else case (next_state)
A:out<=0;
B:out<=0;
C:out<=0;
D:out<=1;
default :out<=0;
endcase
end
endmodule