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

输入序列连续的序列检测

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

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

parameter idle=4'd0, A=4'd1, b=4'd2, c=4'd3, d=4'd4, e=4'd5, f=4'd6, g=4'd7, h=4'd8;
reg [3:0] state,next;

always @ (posedge clk or negedge rst_n) begin
	if(~rst_n) begin
		state<=idle;
	end
	else begin
		state<=next;
	end
end

always @ (*) begin
	case(state)
	4'd0: next = a? idle:A;
	4'd1: next = a? b:A;
	4'd2: next = a? c:A;
	4'd3: next = a? d:A;
	4'd4: next = a? idle:e;
	4'd5: next = a? b:f;
	4'd6: next = a? b:g;
	4'd7: next = a? h:A;
	4'd8: next = a? c:A;
	default: next = idle;
	endcase
end

always @ (posedge clk or negedge rst_n) begin
	if(~rst_n) begin
		match <= 0;
	end
	else begin
		match <= state==h;
	end
end
  
endmodule

#verilog刷题记录#
全部评论

相关推荐

运营3年修炼中接简历辅导:你的科研项目经历里,只写了你的动作,没有写你的思考和成果,不要只写使用什么进行了什么,这等于罗列你的任务,简历是为了突出你的优秀,你在什么样的任务背景下,克服了什么样的困难,针对性地做了哪些事情,最后达成了什么成果(用数据体现你的成果和效率)
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务