Lemmings2

See also: Lemmings1.

In addition to walking left and right, Lemmings will fall (and presumably go "aaah!") if the ground disappears underneath them.

In addition to walking left and right and changing direction when bumped, when ground=0, the Lemming will fall and say "aaah!". When the ground reappears (ground=1), the Lemming will resume walking in the same direction as before the fall. Being bumped while falling does not affect the walking direction, and being bumped in the same cycle as ground disappears (but not yet falling), or when the ground reappears while still falling, also does not affect the walking direction.

Build a finite state machine that models this behaviour.

clkbump_leftbump_rightgroundwalk_leftwalk_rightaaah

See also: Lemmings3 and Lemmings4.

复制代码
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 ); 
	parameter LEFT=0, RIGHT=1,FALLL=2,FALLR=3;
    //fall分出左右更有利于编程
    reg [1:0]state, next_state;
	//这里两位状态寄存器,必须记住!
    always @(*) begin
        // State transition logic
        case(state)
            LEFT:next_state<=ground?(bump_left?RIGHT:LEFT):FALLL;
            RIGHT:next_state<=ground?(bump_right?LEFT:RIGHT):FALLR;
            //这里要记得ground判定在前
            FALLL:next_state<=ground?LEFT:FALLL;
            FALLR:next_state<=ground?RIGHT:FALLR;
        endcase
    end

    always @(posedge clk, posedge areset) begin
        // State flip-flops with asynchronous reset
        if(areset)
            state<=LEFT;
        else
            state<=next_state;
    end

    // Output logic
    assign walk_left = (state == LEFT);
    assign walk_right = (state == RIGHT);
    assign aaah=(state==FALLL||state==FALLR);
endmodule

fall分出左右是点睛之笔

相关推荐
FPGA小c鸡2 小时前
【FPGA深度学习加速】RNN与LSTM硬件加速完全指南:从算法原理到硬件实现
rnn·深度学习·fpga开发
Aaron15883 小时前
通信灵敏度计算与雷达灵敏度计算对比分析
网络·人工智能·深度学习·算法·fpga开发·信息与通信·信号处理
博览鸿蒙8 小时前
IC 和 FPGA,到底区别在哪?
fpga开发
思尔芯S2C8 小时前
FPGA原型验证实战:如何应对外设连接问题
fpga开发·risc-v·soc设计·prototyping·原型验证
Flamingˢ8 小时前
FPGA实战:VGA成像原理、时序详解与Verilog控制器设计与验证
fpga开发
FPGA_小田老师8 小时前
xilinx原语:OSERDES2(并串转换器)原语详解
fpga开发·lvds·xilinx原语·oserdese·并串转换
Blossom.1188 小时前
从数字大脑到物理实体:具身智能时代的大模型微调与部署实战
人工智能·python·深度学习·fpga开发·自然语言处理·矩阵·django
漂洋过海的鱼儿1 天前
HLS (High-Level Synthesis)对比PS运行速度
fpga开发
Aaron15881 天前
无线信道下的通信链路设计分析
大数据·网络·人工智能·算法·fpga开发·硬件工程·射频工程
碎碎思1 天前
当 FPGA 遇上 Python:Glasgow 如何玩转数字接口(开源硬件 & 软件)
fpga开发