之前一直想当然的认为序列检测器就应该用状态机来实现,后面在qq群里看到有人面试的时候被问,除了用状态机实现序列检测外,还能使用什么方法实现序列检测?后面查找了资料,发现可以使用序列检测器,自己就动手写了一个。
1、代码思路:
将输入的数据存储在移位寄存器中,如果寄存器中的序列是我们要检测的序列就输出1.
2、代码

`timescale 1ns / 1ps
//
// Company: 
// Engineer: 
// 
// Create Date: 2021/08/03 00:11:26
// Design Name: 
// Module Name: sequence_move
// Project Name: 
// Target Devices: 
// Tool Versions: 
// Description: 
// 
// Dependencies: 
// 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// 假设是检查11001
//

module sequence_move(
input clk,
input rst_n,
input data_in,
output data_out
    );
reg [4:0]d_r;
assign data_out=(d_r==5'b11001)?1:0;

always@(posedge clk)
if(!rst_n)
	d_r<=5'd0;
else d_r<={d_r[3:0],data_in};	
endmodule

3、仿真文件

`timescale 1ns / 1ps
//
// Company: 
// Engineer: 
// 
// Create Date: 2021/08/03 00:19:41
// Design Name: 
// Module Name: sequence_move_tst
// Project Name: 
// Target Devices: 
// Tool Versions: 
// Description: 
// 
// Dependencies: 
// 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// 
//
module sequence_move_tst();
reg clk      ;
reg rst_n    ;
reg data_in  ;
wire data_out;
sequence_move U_sequence_move(
.clk      (clk     ),
.rst_n    (rst_n   ),
.data_in  (data_in ),
.data_out (data_out)
);
initial
begin
clk=1;
rst_n=0;
data_in=0;
#20 rst_n=1;
#20 data_in=1;
#20 data_in=0;
#20 data_in=0;
#20 data_in=1;
#20 data_in=1;
#20 data_in=0;
#20 data_in=0;
#20 data_in=1;
#20 data_in=1;
#20 data_in=0;
#20 data_in=0;
#20 data_in=1;
#20 rst_n=0;

end
always #10 clk=~clk;
endmodule

4、波形