题解1 | #输入序列连续的序列检测#
输入序列连续的序列检测
https://www.nowcoder.com/practice/d65c2204fae944d2a6d9a3b32aa37b39
用了8位一组缓存再判断。由于用了高位大序号[7:0] a_temp 和正序if循环 a_temp[i] <=a,a在vector里面会从低位往高位存,与题目的序列顺序刚好相反,判断的时候要注意一下条件,将序列反过来写。
参考组友写法,用拼接的方式可以省下if 循环和 一个复位,详见题解2。
`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 i = 0; 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