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

输入序列连续的序列检测

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

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

	parameter IDEL = 0, S0 = 1, S1 = 2, S2 = 3, S3 = 4, S4 = 5, S5 = 6, S6 = 7, S7 = 8;
	reg [3:0] cstate,nstate;
	always@(posedge clk or negedge rst_n) begin
		if(!rst_n) begin
			cstate <= IDEL;
		end
		else begin
			cstate <= nstate;
		end
	end
	always@(*) begin
		case(cstate)
			IDEL: nstate = a?IDEL:S0;
			S0:	  nstate = a?S1:S0;
			S1:	  nstate = a?S2:S0;
			S2:   nstate = a?S3:S0;
			S3:   nstate = a?IDEL:S4;
			S4:   nstate = a?S1:S5;
			S5:   nstate = a?S1:S6;
			S6:   nstate = a?S7:S0;
			S7:   nstate = a?IDEL:S0;
			default: nstate = IDEL;
		endcase
	end
	always@(posedge clk or negedge rst_n) begin
		if(!rst_n) begin
			match <= 1'b0;
		end
		else begin
			match <= (cstate==S7);
		end
	end
  
endmodule

全部评论

相关推荐

起名字真难233:人家只有找猴子的预算,来个齐天大圣他们驾驭不住呀😂😂
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务