题解 | #不重叠序列检测#

不重叠序列检测

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
	);

	reg [5:0] sequence;		  
	reg res;  //compare result for data inputed currently!
	reg [2:0] cnt;
	reg in_data, ctrigger;

	initial begin
		match <= 0;
		not_match <= 0;
		in_data <= 0;
		res <= 0;
		cnt[2:0] <= 3'b000;
		sequence[5:0] <= 6'b001110;
		ctrigger <= 0;
	end

	always @(rst_n) begin
		if (rst_n == 0) begin
			match <= 0;
			not_match <= 0;
			in_data <= 0;
			res <= 0;
			cnt[2:0] <= 3'b000;
		end
	end

	always @(posedge clk) begin 
		if (rst_n == 1) begin
			if ( cnt == 3'b110) 
				cnt <= 1;
			else cnt <= cnt + 1'b1;

			in_data  <= data;
		end
	end

	always @(cnt) begin
		if ( (cnt == 1) | ((cnt > 1) && (res == 1))) begin
		    if (in_data == sequence[cnt-1]) res <= 1;
		    else  res <= 0;
	    end
		ctrigger <= ~ctrigger;
	end
		
	always @(ctrigger) begin
		if ((cnt == 6) && (res == 0)) not_match <= 1;
		if ((cnt == 6) && (res == 1)) match <= 1;
	end

	always @(posedge clk) begin
		match <= 0;
		not_match <= 0;
	end
endmodule

全部评论

相关推荐

牛牛不会牛泪:脉脉太多这种了,纯水军
点赞 评论 收藏
分享
阿武同学:基本信息保留前面三行,其他的可以全部删掉,邮箱最重要的你没写,主修课程精简到8个以内,实习里面2/3/4都是水内容的,非要写的话建议两到三句话,项目经历排版优化下,自我评价缩到三行
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务