目录
- 理论解读
- 写几段式状态机?
- 设计实战
- 两种state的FSM(异步复位)
理论解读
写几段式状态机?
设计实战
两种state的FSM(异步复位)
实现下图所示的摩尔状态机,复位为异步复位。
代码实现:
module top_module(
input clk,
input areset, // Asynchronous reset to state B
input in,
output out);//
parameter A=0, B=1;
reg state, next;
// State transition logic
always@(*)begin // This is a combinational always block
case(state)
A: next = in ? A : B;
B: next = in ? B : A;
endcase
end
// State flip-flops with asynchronous reset
always @(posedge clk or posedge areset) begin // This is a sequential always block
if(areset == 1'b1)begin
state <= B;
end else begin
state <= next;
end
end
// Output logic
assign out = (state == B);
endmodule
- 验证结果