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

输入序列不连续的序列检测

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

`timescale 1ns/1ns
module sequence_detect(
	input clk,
	input rst_n,
	input data,
	input data_valid,
	output reg match
	);

reg [2:0] curr_st;
reg [2:0] next_st;
parameter M0 = 3'b0;
parameter M1 = 3'b01;
parameter M2 = 3'b10;
parameter M3 = 3'b11;
parameter M4 = 3'b100;

always @(posedge clk or negedge rst_n)begin
	if(rst_n == 1'b0)
	   curr_st <= M0;
	else
	   curr_st <= next_st;
end

always@(*)begin
	case(curr_st)
	M0: 
	    if(data_valid)begin
		   if(data == 1'b0) next_st = M1;
		   else  next_st =  M0;
		end
		else
		   next_st = M0;

	M1:
	    if(data_valid)begin
			if(data == 1'b1) next_st = M2;
			else next_st = M1;
		end
		else
		    next_st = M1;
	M2: 
	    if(data_valid)begin
			if(data == 1'b1) next_st = M3;
			else next_st = M1;
		end
		else
		   next_st = M2;

	M3: 
	    if(data_valid)begin
			if(data == 1'b0) next_st = M4;
			else  next_st = M0;
		end
		else
		    next_st= M3;
	M4:
	    if(data_valid)begin
			if(data == 1'b0) next_st = M1;
			else  next_st = M0;
		end
		else
		   next_st = M0;

	endcase
end

always @(posedge clk or negedge rst_n)begin
	if(rst_n == 1'b0)
	   match <= 0;
	else if(next_st == M4)
	   match <= 1;
	else
	   match <= 0;
end
endmodule

全部评论

相关推荐

想干测开的tomca...:这份简历是“大一新生硬凹资深后端”的典型反面教材,槽点离谱到能让面试官直接笑出声: ### 1. 「年龄+入学时间」和项目复杂度完全脱节,可信度直接归0 你2024年7月才入学(现在刚读了1年多),19岁的大一新生,能把Vue3+Spring Boot+ShardingSphere+K8s+AI这些技术全塞进两个项目里?别说实际开发,光把这些技术的文档看完都得半年——这不是“能力强”,是“把招聘JD里的技术词全抄过来造假”,明摆着没碰过实际代码
点赞 评论 收藏
分享
11-11 16:40
已编辑
门头沟学院 人工智能
不知道怎么取名字_:这个有点不合理了,相当于已经毕业了,但还是没转正,这不就是白嫖
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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