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

含有无关项的序列检测

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

`timescale 1ns/1ns
module sequence_detect(
	input clk,
	input rst_n,
	input a,
	output reg match
	);
    parameter S0 = 4'd0;
    parameter S1 = 4'd1;
    parameter S2 = 4'd2;
    parameter S3 = 4'd3;
    parameter S4 = 4'd4;
    parameter S5 = 4'd5;
    parameter S6 = 4'd6;
    parameter S7 = 4'd7;
    parameter S8 = 4'd8;
    parameter S9 = 4'd9;
    reg [3:0] cstate, nstate;
    always@(posedge clk or negedge rst_n) begin
        if(!rst_n) begin
            cstate <= S0;
        end
        else begin
            cstate <= nstate;
        end
    end
    always@(*) begin
        case(cstate)
            S0: nstate = a?S0:S1;
            S1: nstate = a?S2:S1;
            S2: nstate = a?S3:S1;
            S3: nstate = S4;
            S4: nstate = S5;
            S5: nstate = S6;
            S6: nstate = a?S7:S1;
            S7: nstate = a?S8:S1;
            S8: nstate = a?S0:S9;
            S9: nstate = S0;
            default: nstate = S0;
        endcase
    end
    always@(posedge clk or negedge rst_n) begin
        if(!rst_n) begin
            match <= 1'b0;
        end
        else begin
            match <= (cstate==S9);
        end
    end
endmodule

全部评论

相关推荐

07-13 14:45
南华大学 Java
北斗导航Compas...:英文和中文之间加个空格,有的句子有句号 有的没。其他没啥问题
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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