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

输入序列连续的序列检测

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刷题记录#
全部评论

相关推荐

不愿透露姓名的神秘牛友
11-27 10:48
点赞 评论 收藏
分享
10-07 23:57
已编辑
电子科技大学 Java
八街九陌:博士?客户端?开发?啊?
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务