题解 | #不重叠序列检测#
不重叠序列检测
https://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
);
parameter TARGET = 6'b001110;
reg [5:0] data_tmp;
reg [2:0] cnt;
always @(posedge clk or negedge rst_n) begin
if(!rst_n) begin
data_tmp <= 6'b0;
cnt <= 3'b0;
match <= 0;
not_match <= 0;
end else if(cnt == 3'b101) begin
cnt <= 3'b0;
if(data_tmp[5:0] === TARGET) begin
match <= 1;
end else begin
not_match <= 1;
end
end else begin
match <= 0;
not_match <= 0;
//cnt <= cnt + 1'b1;
data_tmp <= {data_tmp[4:0], data};
cnt <= cnt + 1'b1;
end
end
module sequence_detect(
input clk,
input rst_n,
input data,
output reg match,
output reg not_match
);
parameter TARGET = 6'b001110;
reg [5:0] data_tmp;
reg [2:0] cnt;
always @(posedge clk or negedge rst_n) begin
if(!rst_n) begin
data_tmp <= 6'b0;
cnt <= 3'b0;
match <= 0;
not_match <= 0;
end else if(cnt == 3'b101) begin
cnt <= 3'b0;
if(data_tmp[5:0] === TARGET) begin
match <= 1;
end else begin
not_match <= 1;
end
end else begin
match <= 0;
not_match <= 0;
//cnt <= cnt + 1'b1;
data_tmp <= {data_tmp[4:0], data};
cnt <= cnt + 1'b1;
end
end
endmodule
题目描述的序列有错,搞了一下午,坑死人了