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

不重叠序列检测

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]		line;//sequence
always@(*)
	if(!rst_n) begin
		line 	<= 6'd0;
	end
	else begin
		case(cnt)
			3'd0:line[0] = data;
			3'd1:line[1] = data;
			3'd2:line[2] = data;
			3'd3:line[3] = data;
			3'd4:line[4] = data;
			3'd5:line[5] = data;
			default : ;
		endcase
	end

reg 		[2:0] 		cnt;
always@(posedge clk or negedge rst_n)begin
	if(!rst_n) begin
		cnt <= 3'd0;
	end
	else if(cnt >=5 )
		cnt <= 3'd0;
	else
		cnt <= cnt + 1'b1;
end
always@(posedge clk or negedge rst_n)begin
	if(!rst_n) begin
		match 		<= 1'b0;
		not_match 	<= 1'b0;
	end 
	else if(cnt == 3'd5)begin
			if(line == 6'b001110)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


// 直接寄存 是一定不和题目时序要求的

全部评论

相关推荐

06-04 09:27
门头沟学院 Java
点赞 评论 收藏
分享
06-02 15:53
阳光学院 Java
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 22:30
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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