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

不重叠序列检测

http://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
    );
    reg [3:0] curr_state;
    reg [3:0] next_state;
    always @ (posedge clk, negedge rst_n)begin
        if (~rst_n)begin
        curr_state<=4'd0;
        end
        else begin
            curr_state<=next_state;
        end
    end
    
    always @ (*)begin
        case(curr_state)
            4'd0:next_state=(data==1'b1)?4'd7:4'd1;
            
            4'd1:next_state=(data==1'b1)?4'd2:4'd8;
            4'd2:next_state=(data==1'b1)?4'd3:4'd9;
            4'd3:next_state=(data==1'b1)?4'd4:4'd10;
            4'd4:next_state=(data==1'b1)?4'd11:4'd5;
            4'd5:next_state=(data==1'b1)?4'd12:4'd6;
            
            4'd6:next_state=(data==1'b1)?4'd0:4'd1;
            
            4'd7:next_state=4'd8;
            4'd8:next_state=4'd9;
            4'd9:next_state=4'd10;
            4'd10:next_state=4'd11;
            4'd11:next_state=4'd12;
            
            4'd12:next_state=(data==1'b1)?4'd7:4'd1;
            default:next_state=4'd0;
        endcase
    end
    always @ (posedge clk, negedge rst_n)begin
        if (~rst_n)begin
            match <= 1'b0;
            not_match<= 1'b0;
        end
        else begin
            match<=(next_state==4'd6);
            not_match<= (next_state==4'd12);
        end
    end    

endmodule
全部评论

相关推荐

uu们,拒offer时hr很生气怎么办我哭死
爱睡觉的冰箱哥:人家回收你的offer,或者oc后没给你发offer的时候可不会愧疚你,所以你拒了也没必要愧疚他。
点赞 评论 收藏
分享
头顶尖尖的程序员:我是26届的不太懂,25届不应该是找的正式工作吗?为什么还在找实习?大四还实习的话是为了能转正的的岗位吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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