hdlbits-Exams/ece241 2013 q8
考试/ece241 2013 Q8 - HDLBits (01xz.net)
这就是一个序列检测器,并且是一个连续的检测器
1 module top_module ( 2 input clk, 3 input aresetn, // Asynchronous active-low reset 4 input x, 5 output z ); 6 7 parameter S0 = 2'd0,S1 = 2'd1,S2 = 2'd2; 8 reg [1:0] current_state,next_state; 9 10 always @(*) begin 11 case(current_state) 12 S0: next_state = x ? S1 : S0; 13 S1: next_state = x ? S1 : S2; 14 S2: next_state = x ? S1 : S0; 15 endcase 16 end 17 18 always @(posedge clk or negedge aresetn) begin 19 if(~aresetn)begin 20 current_state <= S0; 21 end 22 else begin 23 current_state <= next_state; 24 end 25 end 26 27 always @(*) begin 28 z = (current_state == S2) ? x : 1'b0; 29 end 30 31 endmodule