• HDLbits: Lemmings2


    苦思冥想怎么把FALLING下落的逻辑加进去,下落是状态吗?好像是,因为人物状态就是这三种:LEFT、RIGHT、FALLING,但又好像不是,因为FALLING的时候还要“记住”之前是LEFT还是RIGHT。苦思冥想不知道怎么加进去。于是写出了下面的代码,当ground和bump_left/bump_right同时为1时会报错:

    1. module top_module(
    2. input clk,
    3. input areset, // Freshly brainwashed Lemmings walk left.
    4. input bump_left,
    5. input bump_right,
    6. input ground,
    7. output walk_left,
    8. output walk_right,
    9. output aaah );
    10. parameter LEFT=0, RIGHT=1;
    11. reg state,next_state;
    12. always@(*)begin
    13. casez(state)
    14. LEFT: next_state = ground?(bump_left?RIGHT:LEFT):LEFT;
    15. RIGHT: next_state = ground?(bump_left?LEFT:RIGHT):RIGHT;
    16. endcase
    17. end
    18. always@(posedge clk or posedge areset)begin
    19. if(areset)
    20. state <= LEFT;
    21. else
    22. state <= next_state;
    23. end
    24. always@(posedge clk)begin
    25. if(!ground)
    26. aaah = 1;
    27. else
    28. aaah = 0;
    29. end
    30. assign walk_left = ((~aaah) && (state == LEFT));
    31. assign walk_right = ((~aaah) && (state == RIGHT));
    32. endmodule

    参考了大神的答案,思路是把人物状态扩充到四种:LEFT、RIGHT、LEFT_FALLING、RIGHT_FALLING。

    1. module top_module(
    2. input clk,
    3. input areset, // Freshly brainwashed Lemmings walk left.
    4. input bump_left,
    5. input bump_right,
    6. input ground,
    7. output walk_left,
    8. output walk_right,
    9. output aaah );
    10. parameter LEFT=4'b0001, RIGHT=4'b0010, LEFT_FALLING=4'b0100, RIGHT_FALLING=4'b1000;
    11. reg [3:0] state,next_state;
    12. always@(*)begin
    13. case(state)
    14. LEFT: next_state = ground?(bump_left?RIGHT:LEFT):LEFT_FALLING;
    15. RIGHT: next_state = ground?(bump_right?LEFT:RIGHT):RIGHT_FALLING;
    16. LEFT_FALLING: next_state = ground?LEFT:LEFT_FALLING;
    17. RIGHT_FALLING: next_state = ground?RIGHT:RIGHT_FALLING;
    18. default: next_state = LEFT;
    19. endcase
    20. end
    21. always@(posedge clk or posedge areset)begin
    22. if(areset)
    23. state <= LEFT;
    24. else
    25. state <= next_state;
    26. end
    27. /*always@(posedge clk)begin
    28. if(!ground)
    29. aaah = 1;
    30. else
    31. aaah = 0;
    32. end */
    33. assign walk_left = (state == LEFT);
    34. assign walk_right = (state == RIGHT);
    35. assign aaah = (state == LEFT_FALLING || state == RIGHT_FALLING);
    36. endmodule
  • 相关阅读:
    YOLOv7改进---注意力机制: EMA基于跨空间学习的高效多尺度注意力、效果优于ECA、CBAM、CA | 小目标涨点明显 | ICASSP2023
    花生壳内网穿透+Windows系统,如何搭建网站?
    JVM-堆中线程私有空间TLAB(Thread Local Allocation Buffer)
    面对密集型的I/O任务处理,python该如何提高执行效率
    【C++】哈希表
    自己编写神经网络
    前端最全面试题【最新版本2024-7月】
    SOLIDWORKS 专业显卡要求
    【摘抄】quant4j
    Metabase学习教程:入门-3
  • 原文地址:https://blog.csdn.net/weixin_41004238/article/details/133780643