检测代码:
module det_seq(clk,rst_n,din,dout);
input clk,rst_n;
input din;
output dout;
reg [4:0] shift_reg;
parameter s=5'b11010;
always@(posedge clk,negedge rst_n)begin
if(~rst_n)
shift_reg<=5'b0;
else
shift_reg<={shift_reg[3:0],din};
end
assign dout=(shift_reg==s)?1'b1:1'b0;
endmodule
tb 代码:
`timescale 1ns/1ns
module det_seq_tb();
reg clk,rst_n;
wire din;
reg [31:0]data;
wire dout;
always #1 clk=~clk;
always@(posedge clk)begin
data<={data[30:0],data[31]};
end
assign din=data[31];
initial
begin
clk=0;rst_n=0;data=32'b0;
#8 rst_n=1;
data=32'b1010_1100_1101_0110_1011_0011_0110_0001;
#500 $stop;
end
det_seq u1(.clk(clk),.rst_n(rst_n),.din(din),.dout(dout));
endmodule