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的电气小兴兴2 小时前
基于FPGA的CORDIC旋转模式实现sin和cos运算
fpga开发·信号处理·数字信号处理·verilog·fpga·verilog hdl·cordic
blue_ice .5 小时前
DDS原理及简易实现
开发语言·经验分享·笔记·嵌入式硬件·fpga开发
明德扬5 小时前
AD9653采集模块怎样连接FPGA底板?从ADC采样到数据处理
学习·fpga开发·fpga
上海芯聚电子16 小时前
ADC与FPGA之间,如何减少板级设计复杂度?
fpga开发·adc
自小吃多19 小时前
高云FPGA ModelSim中的仿真
笔记·嵌入式硬件·fpga开发
通信王6619 小时前
适用于 FPGA 和 SoC 的UltraFast 设计方法指南(1)-UG949
fpga开发
明德扬19 小时前
AD9653采集模块、PCIe采集卡和完整采集系统怎么选?
fpga开发·fpga
智塑未来19 小时前
FPGA开发板选型:研发交付能力怎么看
人工智能·fpga开发
泛联新安1 天前
FPGA功能仿真:VShark正式亮相,换仿真器不用换习惯
fpga开发·编译·仿真·嵌入式软件·代码漏洞扫描
泛联新安1 天前
FPGA仿真加速:AccEmu正式亮相,一周的回归,一天跑完
机器学习·fpga开发·数据挖掘·回归·自动化·嵌入式软件·代码漏洞扫描