题解 | #含有无关项的序列检测#
含有无关项的序列检测
https://www.nowcoder.com/practice/cba67d06d6834a5d9b93e1087b56c8d8
注意seq应初始化为与待检测序列的第一位相反的值,即seq <= 9'h1ff; 防止在seq还没缓存满时便出现序列错误匹配的情况!!!
`timescale 1ns/1ns
module sequence_detect(input clk,
input rst_n,
input a,
output reg match
);
reg [8:0] seq;
always @(posedge clk, negedge rst_n)
begin
if(!rst_n) seq <= 9'h1ff;
else seq <= {seq[7:0],a};
end
always @(posedge clk, negedge rst_n)
begin
if(!rst_n) match <= 0;
else if({seq[8:6],seq[2:0]} == 6'b011110)
match <= 1;
else match <= 0;
end
endmodule