题解 | #不重叠序列检测#
不重叠序列检测
http://www.nowcoder.com/practice/9f91a38c74164f8dbdc5f953edcc49cc
`timescale 1ns/1ns
module sequence_detect(
input clk,
input rst_n,
input data,
output reg match,
output reg not_match
);
reg[5:0]data_a;
reg[2:0]count;
always@(posedge clk or negedge rst_n)begin
if(!rst_n)begin
data_a<='b0;
count<='b0;
end
else begin
data_a<={data_a[4:0],data};
count<=count+1;
end
end
always@(posedge clk or negedge rst_n)begin
if(!rst_n)begin
match<=1'b0;
not_match<=1'b0;
end
else if(count==3'd5)begin
count<='b0;
if({data_a,data}==6'b011100)begin
match<=1'b1;
not_match<=1'b0;
end
else begin
match<=1'b0;
not_match<=1'b1;
end
end
else begin
match<=1'b0;
not_match<=1'b0;
end
end
endmodule
module sequence_detect(
input clk,
input rst_n,
input data,
output reg match,
output reg not_match
);
reg[5:0]data_a;
reg[2:0]count;
always@(posedge clk or negedge rst_n)begin
if(!rst_n)begin
data_a<='b0;
count<='b0;
end
else begin
data_a<={data_a[4:0],data};
count<=count+1;
end
end
always@(posedge clk or negedge rst_n)begin
if(!rst_n)begin
match<=1'b0;
not_match<=1'b0;
end
else if(count==3'd5)begin
count<='b0;
if({data_a,data}==6'b011100)begin
match<=1'b1;
not_match<=1'b0;
end
else begin
match<=1'b0;
not_match<=1'b1;
end
end
else begin
match<=1'b0;
not_match<=1'b0;
end
end
endmodule