题解 | #含有无关项的序列检测#

含有无关项的序列检测

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

完美,一次过,画好时序图就可以了啊。
注意点1:在加载完9个输入之后每次都要进行检测。其他参考答案好像没考虑这个点?需要考虑吗?
注意点2:有优化的空间,cnt位宽之类的。
注意点3:match 的输出滞后一个周期
`timescale 1ns/1ns
module sequence_detect(
	input clk,
	input rst_n,
	input a,
	output reg match
	);
    reg [8:0] cnt;
    reg [8:0] seq_r;
    always @ (posedge clk, negedge rst_n) begin
        if(~rst_n) begin
            cnt <= 0;
        end
        else begin
            cnt <= (cnt == 8'h1FF) ? 9 : cnt + 1;
        end
    end
    
    always @ (posedge clk, negedge rst_n) begin
        if(~rst_n) begin
            seq_r <= 0;
        end
        else begin
            seq_r <= {seq_r[7:0], a};
        end
    end
    
    always @ (posedge clk, negedge rst_n) begin
        if(~rst_n) begin
            match <= 0;
        end
        else begin
            match <= (cnt >= 9) && ({seq_r[8:6], seq_r[2:0]} == 6'b011110);
        end
    end

  
endmodule


全部评论

相关推荐

大叔叔1:你把自己说的话打码,所以你想表达什么
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务