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

不重叠序列检测

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 结果错误,这是为什么呢?

#悬赏#
全部评论

相关推荐

不愿透露姓名的神秘牛友
02-16 22:33
杉川机器人 嵌入式工程师 18.0k*13.0, 年终奖1~9个月浮动
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务