题解 | #不重叠序列检测#

不重叠序列检测

https://www.nowcoder.com/practice/9f91a38c74164f8dbdc5f953edcc49cc

`timescale 1ns/1ns
module sequence_detect(input clk,
                       input rst_n,
                       input data,
                       output reg match,
                       output reg not_match);
    
    parameter idle = 4'd0 ,
    S1 = 4'd1 , S2 = 4'd2, S3 = 4'd3 ,S4 = 4'd5 ,S5 = 4'd6 , S6 = 4'd7,
    C1 = 4'd8 , C2 = 4'd9, C3 = 4'd10,C4 = 4'd11,C5 = 4'd12, C6 = 4'd13;
    
    reg [3:0] state , next_state;
    
    always @(*) begin
        case (state) 
            idle : next_state = data ? C1 : S1;
            S1   : next_state = data ? S2 : C2;
            S2   : next_state = data ? S3 : C3 ;
            S3   : next_state = data ? S4 : C4 ;
            S4   : next_state = data ? C5 : S5;
            S5   : next_state = data ? C6 : S6;
            S6   : next_state = data ? C1 : S1;
            C1   : next_state = C2;
            C2   : next_state = C3;
            C3   : next_state = C4;
            C4   : next_state = C5;
            C5   : next_state = C6;
            C6   : next_state = data ? C1 : S1;
        endcase
    end
    
    always @(posedge clk or negedge rst_n) begin
        if (!rst_n) begin
            state <= idle;
        end else begin
            state <= next_state;    
        end
    end
    
    always @(posedge clk or negedge rst_n) begin
        if(!rst_n) begin
            match <= 1'b0;
        end 
		else begin
            if(next_state == S6) begin
                match <= 1'b1;
            end 
			else begin
                match <= 1'b0;
            end
        end 
    end
    
       always @(posedge clk or negedge rst_n) begin
        if(!rst_n) begin
            not_match <= 1'b0;
        end 
		else begin
            if(next_state == C6) begin
                not_match <= 1'b1;
            end 
			else begin
                not_match <= 1'b0;
            end
        end 
    end
    
    
    
endmodule

全部评论

相关推荐

白火同学:1、简历可以浓缩成一页,简历简历先要“简”方便HR快速过滤出有效信息,再要“历”用有效信息突出个人的含金量。 2、教育背景少了入学时间~毕业时间,HR判断不出你是否为应届生。 3、如果你的平台账号效果还不错,可以把账号超链接或者用户名贴到对应位置,一是方便HR知道你是具体做了什么内容的运营,看到账号一目了然,二是口说无凭,账号为证,这更有说服力。
面试被问期望薪资时该如何...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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