[HDLbirts] Lemmings2

本题波形似乎与题干有所不符


波形显示,下落同时碰到相同方向上的障碍物会对后续的移动有影响,即先按照下落前移动一拍,然后反向移动。

符合波形的解题思路

module top_module(
    input clk,
    input areset,    // Freshly brainwashed Lemmings walk left.
    input bump_left,
    input bump_right,
    input ground,
    output walk_left,
    output walk_right,
    output aaah ); 
    
    reg [3:0] state, next_state;
    
    parameter A = 4'b0001;	//left
    parameter B = 4'b0010;	//right
    parameter UG_A = 4'b0100;	//unground left
    parameter UG_B = 4'b1000;	//unground right

    
    
    always @(posedge clk, posedge areset) begin
        if(areset)
            state <= A;
        else
            state <= next_state;     
    end
    
    always @* begin
        case (state)
            A : next_state = ground ? (bump_left ? B : A) : (bump_left ? UG_B : UG_A);
            B : next_state = ground ? (bump_right ? A : B) : (bump_right ? UG_A : UG_B);
            UG_B: next_state = ground ? B : UG_B;
            UG_A: next_state = ground ? A : UG_A;
            default: next_state = 'x;
        endcase
    end
    
    always @(posedge clk, posedge areset) begin
        if(areset)
        	{walk_left, walk_right, aaah} <= 3'b100;
        else begin
            walk_left <= next_state[0];
            walk_right <= next_state[1];
            aaah <= |next_state[3:2];   
        end
    end

endmodule

符合题干的解题思路

module top_module(
    input clk,
    input areset,    // Freshly brainwashed Lemmings walk left.
    input bump_left,
    input bump_right,
    input ground,
    output walk_left,
    output walk_right,
    output aaah ); 
    
    reg [3:0] state, next_state;
    
    parameter A = 4'b0001;	//left
    parameter B = 4'b0010;	//right
    parameter UG_A = 4'b0100;	//unground left
    parameter UG_B = 4'b1000;	//unground right

    
    
    always @(posedge clk, posedge areset) begin
        if(areset)
            state <= A;
        else
            state <= next_state;     
    end
    
    always @* begin
        case (state)
            A : next_state = ground ? (bump_left ? B : A) : UG_A;
            B : next_state = ground ? (bump_right ? A : B) : UG_B;
            UG_B: next_state = ground ? B : UG_B;
            UG_A: next_state = ground ? A : UG_A;
            default: next_state = 'x;
        endcase
    end
    
    always @(posedge clk, posedge areset) begin
        if(areset)
        	{walk_left, walk_right, aaah} <= 3'b100;
        else begin
            walk_left <= next_state[0];
            walk_right <= next_state[1];
            aaah <= |next_state[3:2];   
        end
    end

endmodule

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

666BOY666

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值