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

不重叠序列检测

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

题目中的时序图和结果的时序图不一致,结果中需要在第6个数据到来的同时输出结果。
`timescale 1ns/1ns
module sequence_detect(
	input clk,
	input rst_n,
	input data,
	output reg match,
	output reg not_match
	);
    
        
    localparam S0 = 3'd0, S1 = 3'd1, S2 = 3'd2, S3 = 3'd3, S4 = 3'd4, S5 = 3'd5;
    reg [3:0] state, next_state;
    reg [3:0] match_cnt;
    
    always @(posedge clk or negedge rst_n) begin
        if(~rst_n) 
            state <= S0;
        else
            state <= next_state;
    end
    
    always @(*) begin
        if(~rst_n)
            next_state = S0;
        else begin
            case(state)
                S0  : next_state = S1;
                S1  : next_state = S2;
                S2  : next_state = S3;
                S3  : next_state = S4;
                S4  : next_state = S5;
                S5  : next_state = S0;
                default: next_state = S0;
            endcase
        end
    end
    
    always @(posedge clk or negedge rst_n) begin
        if(~rst_n)
            match_cnt <= 'd0;
        else begin
            case(state)
                S0  : begin
                        if(data == 1'b0)
                            match_cnt <= 3'd1;
                        else
                            match_cnt <= 3'd0;
                      end
                S1  : if(data == 1'b1 && match_cnt == 3'd1) match_cnt <= 3'd2;
                S2  : if(data == 1'b1 && match_cnt == 3'd2) match_cnt <= 3'd3;
                S3  : if(data == 1'b1 && match_cnt == 3'd3) match_cnt <= 3'd4;
                S4  : if(data == 1'b0 && match_cnt == 3'd4) match_cnt <= 3'd5;
                S5  : if(data == 1'b0 && match_cnt == 3'd5) match_cnt <= 3'd6;
                default: match_cnt <= 'd0;    
            endcase
        end
    end
    
    always @(posedge clk or negedge rst_n) begin
        if(~rst_n)
            match <= 1'b0;
        else if(state == S5 && match_cnt == 3'd5 && data == 1'b0)
            match <= 1'b1;
        else
            match <= 1'b0;
    end
    
    always @(posedge clk or negedge rst_n) begin
        if(~rst_n)
            not_match <= 1'b0;
        else if(state == S5 && match_cnt != 3'd5)
            not_match <= 1'b1;
        else
            not_match <= 1'b0;
    end       
    
endmodule


#职场打工人实录#
全部评论

相关推荐

刷到过很多实习生和mentor处成哥们儿的帖子,看完大概率会羡慕这种亲近的上下级关系。但我想说,不管你跟带教的关系有多铁或者多僵,都得拎清课题分离这事儿,工作的边界感千万不能乱踩!📝&nbsp;下面这几条雷区,实习生们可千万别踩!1.别越级瞎提建议除非带教主动问你想法,否则别愣头愣脑地凑上去说&nbsp;“我觉得你应该咋样咋样”。咱就管好自己那一亩三分地,把本职工作干明白就够了,别瞎操心不属于自己的事儿。2.别卖队友换好感❌那种把实习生之间的小秘密捅出去,就为了换带教或者同事认可的操作,纯纯是作死。尤其是那些会影响到别人的话,比如&nbsp;“她就是嫌通勤远才请假”“他们偷偷建了个小群吐槽”,这话一出口,不仅把同事的信任踩碎了,自己还得惹一身麻烦。3.别养成反驳甩锅的臭毛病📗犯了错第一反应别是找借口、甩锅,那没啥用。不如沉下心复盘问题出在哪儿,琢磨个解决方案出来,保证下次不再掉坑里,这才是正经事。4.别瞎掺和正职的八卦我之前实习的组氛围贼好,正职们经常聊对象、聊恋爱进展啥的。但人家正职能聊,不代表咱实习生能跟着掺和。乖乖当个安静的吃瓜群众,竖起耳朵听着就行,别瞎插嘴,当个小透明准没错👂4.别随便评价别人的人品背后嚼舌根说别人咋样咋样,很容易让人觉得你没分寸。你聊啥,别人就可能觉得你认同啥,职场里保持中立,少议论人,才是最稳的。
omega@1112:唯一的大雷其实是不要问mentor的薪资待遇
mt对你说过最有启发的一...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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