使用移位寄存器存储连续的输入a之后,使用casex……endcase判断输入序列是否正确。
`timescale 1ns/1ns
module sequence_detect(
input clk,
input rst_n,
input a,
output reg match
);
reg [8:0] seq_a;
always@(posedge clk or negedge rst_n) begin: reg_a
if(~rst_n)
seq_a <= 9'b0;
else
seq_a <= {seq_a[7:0], a};
end
always@(posedge clk or negedge rst_n) begin: judge_match
if(~rst_n)
match <= 0;
else begin
casex(seq_a)
9'b011xxx110: match <= 1;
default: match <= 0;
endcase
end
end
endmodule