Consider the state diagram shown below.
Write complete Verilog code that represents this FSM. Use separate always blocks for the state table and the state flip-flops, as done in lectures. Describe the FSM output, which is called z, using either continuous assignment statement(s) or an always block (at your discretion). Assign any state codes that you wish to use.
下面展示一些 内联代码片
。
// An highlighted block
// An highlighted block
module top_module (
input clk,
input reset, // synchronous reset
input w,
output z);
parameter A=0,B=1,C=2,D=3,E=4,F=5;
reg [2:0]state,n_state;
//状态转化
always@(posedge clk)begin
if(reset)
state <= A;
else
state <= n_state;
end
//状态转化的条件
always@(*)begin
case(state)
A: n_state = w? B:A;
B: n_state = w? C:D;
C: n_state = w? E:D;
D: n_state = w? F:A;
E: n_state = w? E:D;
F: n_state = w? C:D;
endcase
end
//输出
assign z = state==E||state==F;
endmodule