HDLbits--lemmings3

module top_module(
    input clk,
    input areset,    // Freshly brainwashed Lemmings walk left.
    input bump_left,
    input bump_right,
    input ground,
    input dig,
    output walk_left,
    output walk_right,
    output aaah,
    output digging ); 
    
    parameter left=0,right=1,fall_l=2,fall_r=3,dig_l=4,dig_r=5;
    reg[2:0] state,next_state;
    
    //state change logic
    always @(*)
        begin
            case(state)
                left:
                    next_state<=(ground)? (dig?dig_l:(bump_left?right:left)):fall_l;
                right:
                    next_state<=ground? (dig?dig_r: (bump_right?left:right)):fall_r;
                fall_r:
                    next_state<=ground? right:fall_r;
                fall_l:
                    next_state<=ground?left:fall_l;
                dig_l:
                    next_state<=ground? dig_l:fall_l;
                dig_r:
                    next_state<=ground? dig_r:fall_r;
            endcase
        end
    
    //
    always@(posedge clk,posedge areset)
        begin
            if(areset)
                state<= left;
            else
                state<=next_state;
        end
    
    //output logic
    assign walk_left=(state==left);
    assign walk_right=(state==right);
    assign digging= (state==dig_r|| state==dig_l);
    assign aaah=(state==fall_r ||state==fall_l);
                    
endmodule

反思:

        错误原因:对fall来说判断语句写错了 next<=ground?dig?...,多加了dig的判断。" As with falling, being bumped while digging has no effect, and being told to dig when falling or when there is no ground is ignored."当fall的时候,dig信号是无效的,即fall的下一个状态只有walk和fall,fall状态 不能跳到dig状态。

        对 ?:操作符来说,按照优先级顺序依次判断。

你可能感兴趣的:(fpga开发)