HDLBits Exams/2014 q3bfsm

HDLBits Exams/2014 q3bfsm_第1张图片

1、这个题简单按照图写出来状态切换就可以了

完整代码如下:

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

    reg[2:0]state,next_state;
    parameter A=0,B=1,C=2,D=3,E=4;
    always@(*)begin
        case(state)
            A:next_state=x?B:A;
            B:next_state=x?E:B;
            C:next_state=x?B:C;
            D:next_state=x?C:B;
            E:next_state=x?E:D;
            default: next_state=A;
        endcase
        
    end
    always@(posedge clk )begin
        if(reset)
            state<=A;
        else
            state<=next_state;
    end
    
    always@(*)begin
        
        z=(state==D||state==E);
    end
    
endmodule

 HDLBits Exams/2014 q3bfsm_第2张图片

 

你可能感兴趣的:(FPGA,HDLBits刷题,fpga开发)