πŸ“Œ Question

This is a Moore state machine with two states, two inputs, and one output. Implement this state machine.

This exercise is the same as fsm2s, but using asynchronous reset.

πŸ§‘β€πŸ’» Code Example

module top_module(
    input clk,
    input areset,    // Asynchronous reset to OFF
    input j,
    input k,
    output out); //  

    parameter OFF=1'b0, ON=1'b1; 
    reg state, next_state;

    always @(*) begin
        // State transition logic
        case (state)
            ON : next_state = (k==1'b0) ? ON : OFF;
            OFF: next_state = (j==1'b0) ? OFF : ON;
        endcase
    end

    always @(posedge clk, posedge areset) begin
        // State flip-flops with asynchronous reset
        if (areset) begin
           state <= OFF; 
        end else begin
           state <= next_state; 
        end
    end

    // Output logic
    assign out = (state == ON);

endmodule

πŸ”¬ Simulation Result

πŸ“š Reference