题解3 | #输入序列连续的序列检测#
输入序列连续的序列检测
https://www.nowcoder.com/practice/d65c2204fae944d2a6d9a3b32aa37b39
修正一下题解1
题解1只能判断一个序列,下一个序列会空一拍才开始存数,导致会漏存下一个序列的第一个数,进而导致错位
更正为当i更新为8后,下一拍进入else直接将i更新为1,同时存入上一拍的a的值
`timescale 1ns/1ns module sequence_detect( input clk, input rst_n, input a, output reg match ); reg a_temp; reg [7:0] store; integer i = 0; always @(posedge clk or negedge rst_n) begin if(!rst_n) store <= 8'b0; else if (i <8) begin store[i] <= a; i <= i+1; end else begin i <= 1; store[0] <=a; end end always @(posedge clk or negedge rst_n) begin if (!rst_n) match <= 0 ; else if (i ==8) case (store) 8'b10001110: match <= 1; default: match <= 0; endcase else match <= 0; end endmodule