题解 | #输入序列连续的序列检测#

输入序列连续的序列检测

https://www.nowcoder.com/practice/d65c2204fae944d2a6d9a3b32aa37b39

`timescale 1ns/1ns
module sequence_detect(
	input clk,
	input rst_n,
	input a,
	output reg match
	);
	parameter A=4'd0,b=4'd1,c=4'd2,d=4'd3,e=4'd4,f=4'd5,g=4'd6,h=4'd7,i=4'd8;
	reg [3:0]state,next;
	always@(posedge clk,negedge rst_n)
		begin
			if(!rst_n)
				state<=A;
			else
				state<=next;
		end
	always@(*)
	begin
		case(state)
			A: next<=a?A:b;
			b: next<=a?c:b;
			c: next<=a?d:b;
			d: next<=a?e:b;
			e: next<=a?A:f;
			f: next<=a?A:g;
			g: next<=a?A:h;
			h: next<=a?i:b;
			i: next<=A;
		endcase
	end
	always@(posedge clk,negedge rst_n)
		begin
			if(!rst_n)
				match<=0;
			else if(state==i)
				match<=1;
			else
			match<=0;
		end
endmodule

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务