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

不重叠序列检测

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
	);
	// cnt
	reg [2:0] cnt;
	always @(posedge clk, negedge rst_n) begin
		if(!rst_n) begin
			cnt <= 0;
		end
		else begin
			cnt <= (cnt == 5)? 0 : cnt + 1;
		end
	end

	// data shift
	reg [5:0] data_r;
	always @(posedge clk, negedge rst_n) begin
		if(!rst_n) begin
			data_r <= 0;
		end
		else begin
			data_r <= {data_r[4:0], data};
		end
	end

	// match
	always @(posedge clk, negedge rst_n) begin
		if(!rst_n) begin
			match <= 0;
			not_match <= 0;
		end
		else if(cnt == 5) begin
			match     <= ({data_r[4:0], data} == 6'b011100);
			not_match <= !match;//({data_r[4:0], data} != 6'b011100);
		end
		else begin
			match <= 0;
			not_match <= 0;
		end
	end

endmodule

第三段的 not_match <= !match 结果错误,这是为什么呢?

#悬赏#
全部评论

相关推荐

03-31 16:42
已编辑
郑州西亚斯学院 后端
Java抽象带篮子:你简历少了几个模块看上去就感觉信息很少,简历怎么写可以看看我发的帖子
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务