`timescale 1ns/1ns
module sequence_detect(
input clk,
input rst_n,
input a,
output reg match
);
//此题采用序列寄存法 也可以采用状态机解法
reg [8:0] reg_num ;
// 通过移位和拼接 构造序列输入
always@(posedge clk or negedge rst_n)begin
if(!rst_n)
reg_num <= 9'b0 ;
else
reg_num <= {reg_num[8:0], a};
end
//进行序列匹配,这里使用了一个casex 的语法 xxx为可以理解为无关项
always@(posedge clk or negedge rst_n)begin
if(!rst_n)
match <= 1'b0;
else begin
casex(reg_num)
9'b011_xxx_110: match <= 1'b1;
default: match <= 1'b0;
endcase
end
end
endmodule

京公网安备 11010502036488号