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

不重叠序列检测

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 s0=0,s1=1,s2=2,s3=3,s4=4,s5=5;
parameter sn0=6,sn1=7,sn2=8,sn3=9,sn4=10,sn5=11;
parameter idle=12;
reg [3:0]cs,ns;
always@(posedge clk or negedge rst_n)begin
	if(!rst_n)begin
		cs<=idle;
	end
	else begin
		cs<=ns;
	end
end
always@(*)begin
	if(!rst_n)begin
		ns=s5;
		match=0;
		not_match=0;
	end
	else begin
		case(cs)
		s0:begin
			ns=(data)?s1:sn1;
			match=0;
			not_match=0;
		end
		s1:begin
			ns=data?s2:sn2;
			match=0;
			not_match=0;
		end
		s2:begin
			ns=data?s3:sn3;
			match=0;
			not_match=0;
		end
		s3:begin
			ns=data?sn4:s4;
			match=0;
			not_match=0;
		end
		s4:begin
			ns=data?sn5:s5;
			match=0;
			not_match=0;
		end
		s5:begin
			ns=data?sn0:s0;
			match=1;
			not_match=0;
		end
		sn0:begin
			ns=sn1;
			match=0;
			not_match=0;
		end
		sn1:begin
			ns=sn2;
			match=0;
			not_match=0;
		end
		sn2:begin
			ns=sn3;
			match=0;
			not_match=0;
		end
		sn3:begin
			ns=sn4;
			match=0;
			not_match=0;
		end
		sn4:begin
			ns=sn5;
			match=0;
			not_match=0;
		end
		sn5:begin
			ns=data?sn0:s0;
			match=0;
			not_match=1;
		end
		idle:begin
			ns=data?sn0:s0;
			match=0;
			not_match=0;
		end
		default:begin
			ns=idle;
			match=0;
			not_match=0;			
		end
		endcase
	end
end
endmodule

全部评论

相关推荐

不愿透露姓名的神秘牛友
06-18 16:32
quench@0916:一顿操作猛如虎,一看工资2500
点赞 评论 收藏
分享
05-12 16:04
已编辑
江西财经大学 Java
点赞 评论 收藏
分享
自由水:笑死了,敢这么面试不敢让别人说
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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