Q3b:FSM

a
题目网站

module top_module (
    input clk,
    input reset,   // Synchronous reset
    input x,
    output z
);

    parameter S0 = 3'b000, S1 = 3'b001, S2 = 3'b010;
    parameter S3 = 3'b011, S4 = 3'b100;
    reg [2:0] current_state, next_state;

    always @(*) begin
        case(current_state)
            S0:     next_state = x ? S1 : S0;
            S1:     next_state = x ? S4 : S1;
            S2:     next_state = x ? S1 : S2;
            S3:     next_state = x ? S2 : S1;
            S4:     next_state = x ? S4 : S3;
            default:next_state = S0;
        endcase
    end

    always @(posedge clk) begin
        if(reset)begin
            current_state <= S0;
        end
        else begin
            current_state <= next_state;
        end
    end

    always @(posedge clk) begin
        if(reset)begin
            z <= 1'b0;
        end
        else begin
            case(next_state)
                S3:     z <= 1'b1;
                S4:     z <= 1'b1;
                default:z <= 1'b0;
            endcase
        end      
    end

endmodule

posted @   江左子固  阅读(22)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示