题解 | #含有无关项的序列检测#
含有无关项的序列检测
https://www.nowcoder.com/practice/cba67d06d6834a5d9b93e1087b56c8d8
`timescale 1ns/1ns module sequence_detect( input clk, input rst_n, input a, output reg match ); parameter S0=0,S1=1,S2=2,S3=3,S4=4,S5=5,S6=6,S7=7,S8=8,S9=9,S10=10; reg [3:0] state,state_next; always @(*) begin case(state) S0:begin if(a) state_next=S0; else state_next=S1; end S1:begin if(a) state_next=S2; else state_next=S1; end S2:begin if(a) state_next=S3; else state_next=S1; end S3: state_next=S4; S4: state_next=S5; S5:state_next=S6; S6:begin if(a) state_next=S7; else state_next=S1; end S7:begin if(a) state_next=S8; else state_next=S1;end S8:begin if(a) state_next=S0; else state_next=S9;end S9:begin if(a) state_next=S0; else state_next=S1;end default:begin if(a) state_next=S0; else state_next=S1;end endcase end always @(posedge clk or negedge rst_n) begin if(rst_n==0) state<=S0; else state<=state_next; end always @(posedge clk or negedge rst_n) begin if(rst_n==0) match<=0; else match<=(state==S9)?1:0; end endmodule