2021年4月29日 星期四

HBLbits_Verilog Basic_Fsm2s

HBLbits_Verilog Basic_Fsm2s

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

This exercise is the same as fsm2, but using synchronous reset.

Fsmjks.png

module top_module(

    input clk,
    input reset,    // Synchronous reset to OFF
    input j,
    input k,
    output out); //  

    parameter OFF=0, ON=1; 
    reg state, next_state;
    always @(posedge clk) begin
        // State flip-flops with synchronous reset
        if (reset) begin  
            // Fill in reset logic
            state <= OFF;
            out = 0;
        end else begin
            case (state)
                // Fill in state transition logic
                ON: next_state = (k)? OFF : ON;
                OFF: next_state = (j)? ON : OFF;
            endcase
            // State flip-flops
        state = next_state;  
        case (state)
            // Fill in output logic
            OFF: out = 0;
            ON: out = 1;
        endcase   
    end
    end  
endmodule


module top_module(
    input clk,
    input reset,    // Synchronous reset to OFF
    input j,
    input k,
    output out); //  
    parameter OFF=0, ON=1; 
    reg state, next_state;
    always @(posedge clk) begin
        // State flip-flops with synchronous reset
        if (reset) begin  
            // Fill in reset logic
           state = OFF;
        end else begin
            case (state)
        // State transition logic
                ON : begin
                if (k)  
                    next_state = OFF;
                else
                    next_state = ON;
            end
            OFF : begin
                if (j)  
                    next_state = ON;
                else
                    next_state = OFF;
            end  
                default:;
        endcase
  
        state = next_state;
    end  
            // Output logic
      case (state)
            // Fill in output logic
          OFF: out <= 1'b0;
            ON: out <= 1'b1;
            default:;
        endcase
    end
endmodule


沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...