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

输入序列连续的序列检测

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

`timescale 1ns/1ns
module sequence_detect(
	input clk,
	input rst_n,
	input a,
	output reg match
	);
	parameter [3:0]
	IDLE = 4'd0, S1 = 4'd1,
	S2 = 4'd2, S3 = 4'd3,
	S4 = 4'd4, S5 = 4'd5,
	S6 = 4'd6, S7 = 4'd7, S8 = 4'd8;
	reg [3:0] NS, CS;

	always @(posedge clk or negedge rst_n)
	begin
		if(!rst_n)
		CS <= IDLE;
		else
		CS <= NS;
	end

	always @(*)
	begin
		NS = IDLE;
		case(CS)
		IDLE: NS = a? IDLE : S1;
		S1: NS = a? S2 : S1;
		S2: NS = a? S3 : S1;
		S3: NS = a? S4 : S1;
		S4: NS = a? IDLE : S5;
		S5: NS = a? S2 : S6;
		S6: NS = a? S2 : S7;
		S7: NS = a? S8 : S1;
		S8: NS = a? S3 : S1;
		default: NS = IDLE;
		endcase
	end


	always @(posedge clk or negedge rst_n)
	begin
		if(!rst_n)
		match <= 1'b0;
		else begin
			if(CS == S8)
			match <= 1'b1;
			else
			match <= 1'b0;
		end
	end

	/*reg [7:0] a_temp;
	always@(posedge clk or negedge rst_n)begin
		if(!rst_n)
		a_temp <= 8'b1111_1111;
		else
		begin
			a_temp <= {a_temp[6:0], a};
		end
	end

	always @(posedge clk or negedge rst_n)begin
		if(!rst_n)
		match <= 1'b0;
		else begin
			if(a_temp == 8'b0111_0001)
			match <= 1'b1;
			else 
			match <= 1'b0;
		end
	end*/
  
endmodule

全部评论

相关推荐

06-23 11:28
门头沟学院 Java
牛客91966197...:也有可能是点拒绝的时候自动弹的话术
点赞 评论 收藏
分享
Java大菜狗:纯纯招黑奴,一天还不到两百那么多要求,还不迟到早退,以为啥啊,给一点工资做一堆活,还以不拖欠员工工资为荣,这是什么值得骄傲的事情吗,纯纯***公司
点赞 评论 收藏
分享
昨天 16:15
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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