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

`timescale 1ns/1ns
module sequence_detect(
	input clk,
	input rst_n,
	input a,
	output reg match
	);
    
    parameter seq_t = 8'b0111_0001;
    reg [7:0] seq_r;
    always @ (posedge clk, negedge rst_n) begin
        if (~rst_n) begin
            seq_r <= 'b0;
        end
        else begin
            seq_r <= {seq_r[6:0], a};
        end
    end
    
    always @ (posedge clk, negedge rst_n) begin
        if (~rst_n) begin
            match <= 'b0;
        end
        else begin
            match <= seq_r == seq_t;
        end
    end
    
    

  
endmodule

####笔试题思考,序列检测####


    always @ (posedge clk, negedge rst) begin
        if(~rst) begin
            cnt_16 <= 0;
        end
        else begin
            cnt_16 <= cnt + 1;
        end
    end
    
    always @ (posedge clk, negedge rst) begin
        if(~rst) begin
            cnt_240 <= 0;
        end
        else if(flag_t_seq) begin        
            cnt_240 <= cnt_240 + 1;
        end
        else begin
            cnt_240 <= 0;
        end
    end
    

    
    always @ (*) begin
        if(~rst) begin
            flag_t_seq <= 0;
            //fsync_o <= 0;
        end
        else if(tmp_seq == target_seq && cnt_240 < 239) begin
            flag_t_seq <= 1;
        end
        else begin
            flag_t_seq <= 0;
        end
    end
    
    always @ (posedge clk, negedge rst) begin
        if(~rst) begin
            cnt_3 <= 0;
            fsync_o <= 0;
        end
        else if(tmp_seq == target_seq) begin
            cnt_3 <= cnt_3 + 1;
        end
        else if (cnt_3 == 3) begin
            fsync_o <= 1;
            cnt_3 <= 0;
        end
    end
    
endmodule


全部评论

相关推荐

码农索隆:想看offer细节
点赞 评论 收藏
分享
06-11 14:15
已编辑
门头沟学院 后端
田心今心:打招呼改一下,把实习半年以上随时到岗放第一行,因为ssob的hr不点击看的时候只能看前面几个字,你前面几个字hr获取不到什么信息,也就不会点进来看
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务