3.2.5.9 Design a Moore FSM
问题描述
分析:
1.s=000时,打开fr1,fr2,fr3和补充水dfr
2.s=001时,打开fr1,fr2
3.s=011时,打开fr1
4.s=111时,关闭
5.当水位下降时,打开dfr
绘制一下状态转移图
代码:
cs
module top_module (
input clk,
input reset,
input [3:1] s,
output fr3,
output fr2,
output fr1,
output dfr
);
parameter A=0,B=1,C=2,D=3,E=4,F=5;
reg [2:0] state,next_state;
always @(posedge clk) begin
if(reset) state <= A;
else state <= next_state;
end
always @(*) begin
case(state)
A:next_state = s[1]?B:A;
B:next_state = s[2]?D:(s[1]?B:A);
C:next_state = s[2]?D:(s[1]?C:A);
D:next_state = s[3]?F:(s[2]?D:C);
E:next_state = s[3]?F:(s[2]?E:C);
F:next_state = s[3]?F:E;
endcase
end
always @(*) begin
case(state)
A:{fr3,fr2,fr1,dfr} = 4'b1111;
B:{fr3,fr2,fr1,dfr} = 4'b0110;
C:{fr3,fr2,fr1,dfr} = 4'b0111;
D:{fr3,fr2,fr1,dfr} = 4'b0010;
E:{fr3,fr2,fr1,dfr} = 4'b0011;
F:{fr3,fr2,fr1,dfr} = 4'b0000;
endcase
end
endmodule