Lemmings

HDLBITS笔记34:Lemmings1、Lemmings2、Lemmings3、Lemmings4 题目1:Lemmings1 游戏Lemmings涉及具有相当简单大脑的小动物。如此简单,以至于我们将使用有限状态机对其进行建模。 在Lemmings的2D世界中,Lemmings可以处于以下两种状态之一:向左行走或向右行走。如果它碰到障碍物,它会改变方向。特别是,如果一只旅鼠在左边被撞到,它会向右走。如果它在右边被撞到,它将向左走。如果它同时在两侧碰撞,它仍然会改变方向。 实现具有两个状态、两个输入和一个输出的摩尔状态机,用于模拟此行为。 模块声明 module top_module( 阅读详情

 1.Lemmings1

module top_module(
    input clk,
    input areset,    // Freshly brainwashed Lemmings walk left.
    input bump_left,
    input bump_right,
    output walk_left,
    output walk_right); //  

    // parameter LEFT=0, RIGHT=1, ...
    reg state, next_state;
    parameter left = 1'b0;
    parameter right = 1'b1;
    

    always @(*) begin
        case(state)
            left:
                begin
                    if(!bump_left)  next_state = left;
                    else next_state = right;
                end
            right:
                begin
                    if(!bump_right) next_state = right;
                    else next_state = left;
                end
        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);

endmodule

2.Lemmings2

module top_module (
    input clk,
    input areset,
    input bump_left,
    input bump_right,
    input ground,
    output walk_left,
    output walk_right,
    output aaah
);
    parameter left = 2'b0;
    parameter right = 2'b1;
    parameter hleft = 2'b10;
    parameter hright = 2'b11;
    reg[1:0] state;
    reg[1:0] next_state;
    wire[1:0] p;
 
    assign p = {bump_left,bump_right};
 
    always @(*) begin
        case(state)
            left: 
                begin
                    if (ground == 1'b0) begin
                        next_state = hleft;
                    end
                    else if ((p == 2'b10)||(p == 2'b11)) begin
                        next_state = right;
                    end
                    else begin
                        next_state = left;
                    end
                end
            right:
                begin
                    if (ground == 1'b0) begin
                        next_state = hright;
                    end
                    else if ((p == 2'b01)||(p == 2'b11)) begin
                        next_state = left;
                    end
                    else begin
                        next_state = right;
                    end
                
                end
            hleft:
                begin
                    if (ground == 1'b0) begin
                        next_state = hleft;
                    end
                    else begin
                        next_state = left;
                    end
                
                end
            hright:
                begin
                    if(ground == 1'b0)
                        next_state = hright;
                	else
                    	next_state = right;
 				end
        endcase
    end
 
    always @(posedge clk or posedge areset) begin
        if (areset) begin
            state <= left;
        end
        else state <= next_state;
    end
 
    assign walk_left = (state == left);
    assign walk_right = (state == right);
    assign aaah  =((state == hleft)|(state == hright));
 
endmodule

3.Lemmings 3

module top_module(
    input clk,
    input areset,
    input bump_left,
    input bump_right,
    input ground,
    input dig,
    output walk_left,
    output walk_right,
    output aaah,
    output digging
);
 
    parameter left = 3'b0;
    parameter right = 3'b1;
    parameter d_left = 3'b10;
    parameter d_right = 3'b11;
    parameter f_left = 3'b100;
    parameter f_right = 3'b101;
 
    reg[2:0] state;
    reg[2:0] next_state;
    wire[1:0] bump;
    assign bump = {bump_left,bump_right};
 
    always @(*) begin
        case (state)
            left:begin
                if (ground == 1'b0) 
                    next_state = f_left;
                else if(dig == 1'b1)
                    next_state = d_left;
                else if((bump == 2'b10)||(bump == 2'b11))
                    next_state = right;
                else
                    next_state = left;               
            end 
 
             right:begin
                if (ground == 1'b0) 
                    next_state = f_right;
                else if(dig == 1'b1)
                    next_state = d_right;
                else if((bump == 2'b01)||(bump == 2'b11))
                    next_state = left;
                else
                    next_state = right;               
            end 
 
            d_left:begin
                if(ground == 1'b0)
                    next_state = f_left;
                else
                    next_state = d_left;
            end
             d_right:begin
                if(ground == 1'b0)
                    next_state = f_right;
                else
                    next_state = d_right;
 
            end
 
             f_left:begin
                if(ground == 1'b0)
                    next_state = f_left;
                else
                    next_state = left;
            end
            f_right:begin
                if(ground == 1'b0)
                    next_state = f_right;
                else
                    next_state = right;
 
            end       
            
        endcase
    end
 
    always @(posedge clk or posedge areset) begin
        if(areset)
            state <= left;
        else
            state <= next_state;
    end
 
    assign walk_left = (state == left);
    assign walk_right = (state == right);
    assign digging = ((state == d_left)||(state == d_right));
    assign aaah = ((state == f_left)||(state == f_right));
 
 
endmodule

4.Lemmings4

module top_module(
    input clk,
    input areset,
    input bump_left,
    input bump_right,
    input ground,
    input dig,
    output walk_left,
    output walk_right,
    output aaah,
    output digging
);
 
    parameter left = 3'b0;
    parameter right = 3'b1;
    parameter d_left = 3'b10;
    parameter d_right = 3'b11;
    parameter f_left = 3'b100;
    parameter f_right = 3'b101;
    parameter dead = 3'b110;
    parameter splatter = 3'b111;
 
    reg[2:0] state;
    reg[2:0] next_state;
    reg[4:0] count;
    
    wire[1:0] bump;
    assign bump = {bump_left,bump_right};
 
    always @(*) begin
        case(state)
            left:begin
                if(ground == 1'b0)
                    next_state = f_left;
                else if(dig == 1'd1)
                    next_state =  d_left;
                else if((bump == 2'b10)||(bump == 2'b11 ))
                    next_state = right;
                else
                    next_state = left;
            end
 
            right:begin
                if(ground == 1'b0)
                    next_state = f_right;
                else if(dig == 1'd1)
                    next_state =  d_right;
                else if((bump == 2'b01)||(bump == 2'b11 ))
                    next_state = left;
                else
                    next_state = right;
            end
 
            d_left:begin
                if(ground == 1'b0)
                    next_state = f_left;
                else
                    next_state = d_left; 
            end
            d_right:begin
                if(ground == 1'b0)
                    next_state = f_right;
                else
                    next_state = d_right; 
            end
 
            f_left:begin
                if((ground == 1'b0)&&(count < 5'd20 ))
                    next_state = f_left;
                else if((ground == 1'b0)&&(count >= 5'd20))
                    next_state = splatter;
                else 
                    next_state = left;
            end
 
            f_right:begin
                if((ground == 1'b0)&&(count < 5'd20 ))
                    next_state = f_right;
                else if((ground == 1'b0)&&(count >= 5'd20))
                    next_state = splatter;
                else 
                    next_state = right;
            end
 
            splatter:begin
                if(ground == 1'b1)
                    next_state = dead;
                else
                    next_state = splatter; 
            end
            dead:
                next_state = dead;
        endcase
    end 
    always @(posedge clk or posedge areset) begin
        if(areset)
            state <= left;
        else
            state <= next_state;
    end
    always @(posedge clk or posedge areset) begin
        if(areset)
            count <= 5'd0;
        else if((next_state == f_left)||(next_state == f_right))
            count <= count + 1'b1;
        else
            count <= 5'd0;
    end
 
    assign walk_left = (state == left);
    assign walk_right = (state == right);
    assign aaah = ((state == f_left)||(state == f_right)||(state == splatter));
    assign digging = ((state == d_left)||(state == d_right));
    
 
 
endmodule   

HDLBits-Exams/ece241 2013 q4、Lemmings1、Lemmings2、Lemmings3、Lemmings4 目录 Exams/ece241 2013 q4 Lemmings1 Lemmings2 Lemmings3 Lemmings4 Exams/ece241 2013 q4 题目见网页图片。 module top_module ( input clk, input reset, input [3:1] s, output fr3, output fr2, output fr1, output dfr ); parameter . 阅读详情

相关推荐

HDLbits中Lemmings4的一种解法及问题反思

显然,从这个案例中,可以发现在编写代码时,一定要注意一些会无限制增加的量,注意它是否会溢出。而面对这个问题,是直接增加参数的带宽(我也看到一些解决方案是直接提高一位位宽),还是通过进一步的判断或是赋值操作,来突破这样的位宽限制的问题,也是一个值得思考的问题,相信在不同情况下,不同的解决方案也各自有它的优劣势。当然,最重要的还是要意识到,是否会出现由于参数的位宽不足而导致的数据溢出的情况发生。

keenfan的博客 1164

HDLBits 系列(35)Lemmings Game

目录 背景 Lemmings1 前言 原题复现 我的设计 Lemmings2 Lemmings3 背景 这是一个Lemmings的简单游戏,我们通过状态机可以设计这个游戏,从简单到复杂,一步一步实现这个游戏。 Lemmings1 前言 Lemmings1想要往左走,可是遇到左侧的障碍后,便向右转向;在向右走的过程中,如果遇到右侧的障碍,同理左转向。头脑简单的Lemmings...

Reborn Lee 1896

Verilog专题(二十四)Lemmings3

Lemmings3游戏

Andy_ICer的博客 1120

HDLbits Lemmings4

Question:(具体题目请参见HDLbits Lemmings1/2/3/4)Although Lemmings can walk, fall, and dig, Lemmings aren’t invulnerable. If a Lemming falls for too long then hits the ground, it can splatter. In particular, if a Lemming falls for more than 20 clock cycles then hi

gonnabojiang的博客 897

Verilog专题(二十五)Lemmings4

Lemmings4游戏最后一个系列了

Andy_ICer的博客 1467

告别理论!手把手教你用Patran/Nastran搞定悬臂翼的颤振分析(附完整模型文件)

本文提供了一份详细的Patran/Nastran悬臂翼颤振分析实战指南,涵盖从几何建模到结果解读的全过程。通过手把手教学和完整模型文件,帮助工程师和学生快速掌握气动弹性分析技术,特别适合需要实际操作的初学者。文章重点介绍了模态分析、气动建模和颤振求解等关键步骤,并提供了常见问题排查和优化建议。

weixin_30879169的博客 494

Lemmings1

【代码】Lemmings1。

eachanm的博客 214

CYUSB3065配置CMOS

按照OG02B10的时序电路,在通过SCCB配置CMOS之前,需要三个电源上电,Xshutdown高电平和配置时钟电路。找到手册的第6章SCCB(跟IIC很像),可以看到SCCB的地址与SID引脚有关,这个需要到硬件原理图上确认下。这是Cypress的一个支持MIPI和UVC的模块,有例程支持OV5640,现在要替换替换成OG02B10。寄存器参数需要找到厂家的FAE,由他们提供,OG02B10的资料已经上传。(2)参考得宏的电路,时钟由主控提供,目前程序未实现。这里有两个重要参数需要搞定,摄像头的。

qq_40773212的博客 2949

HDLBits练习——Lemmings2

HDLBits练习

tanxinxin512的博客 444

DVWA全级别详细通关教程

dvwa全级别详细通关教程,暴力破解,命令注入,CSRF跨站请求伪造,文件包含,文件上传​,SQL注入,XSS

m0_62063669的博客 1万+

CentOS 7下kkFileView 4.4.0离线部署全攻略(含LibreOffice 7.5配置避坑指南)

本文详细介绍了在CentOS 7环境下离线部署kkFileView 4.4.0的全流程,包括LibreOffice 7.5的配置避坑指南、中文字体解决方案以及企业级运维实践。通过本指南,用户可以在内网环境中快速搭建稳定可靠的文档在线预览服务,提升办公效率。

weixin_28481133的博客 292

[HDLBits] Lemmings4

【代码】[HDLBits] Lemmings4。

烧烤团子 303

Windows平台COLMAP实战:从零到三维重建的避坑指南

本文详细介绍了在Windows平台上使用COLMAP进行三维重建的完整流程,包括安装指南、数据准备技巧、图形界面操作及常见问题解决方案。特别针对Windows用户提供了CUDA版本与非CUDA版本的性能对比,帮助用户高效完成从照片到三维模型的重建过程。

weixin_29090677的博客 191

HDLBits:lemmings4

这里则多了一个状态为s,且只能从下落的两个状态跳转,因此额外设置计数时间num,在时钟上升沿,处于下落时num加一,其余状态num=0,跳转时判断是否大于等于20即可。lemmings3里设置了六个状态,left、right、fallleft、fallright、digleft、digright。

gou98745的博客 251

FAST-LIVO2 源码精读(五):IMU 运动模型、离散传播与去畸变原理

本文是「FAST-LIVO2 激光-惯性-视觉里程计源码精读」专栏第五篇,数学基础篇章(第 4–7 篇)的第二篇。上一篇在 SO(3) 流形上建立了姿态表示与右扰动模型;本篇聚焦 IMU 预积分的核心问题:一帧激光扫描横跨约 100 ms,帧内每一个点的采集时刻各不相同,如何利用 200 Hz 的 IMU 量测将全帧点云统一对齐到帧末时刻?答案完整封装在(587 行)的函数中,本篇逐段拆解其四阶段逻辑,并推导协方差矩阵随误差状态转移矩阵F_x逐帧演化的物理含义。

PX4-SLAM-PNC 162

dji psdk开发 关于SDK认证芯片的使用

Payload SDK V3.10.0 于 2025-1-8 发布,增加了 Matrice 4T/4E 机型支持,同时也增加了 DJI SDK 认证芯片(DJI SDK CC)功能支持。关于认证芯片的介绍大疆 SDK 认证芯片(DJI SDK Certified Chip),简称 DJI SDK CC,用于认证基于 DJI Eport/Eport-Lite 接口开发的第三方负载设备,确保设备能够正常工作并与无人机可以进行有效通信,起到负载安全认证和功能授权的作用。

热爱生活,忠于自己 2155

HDLBits刷题_Lemmings4

See also:Lemmings1,Lemmings2, andLemmings3. Although Lemmings can walk, fall, and dig, Lemmings aren't invulnerable. If a Lemming falls for too long then hits the ground, it can splatter. In particular, if a Lemming falls for more than 20 clock cycles ...

m0_65438107的博客 528

人形机器人维护保养指南:硬件工程师必备手册

随着科技的不断进步,人形机器人在各个领域的应用越来越广泛。本指南的目的是为硬件工程师提供一份系统、全面的人形机器人维护保养手册,涵盖从基础概念到实际操作的各个方面,帮助工程师们更好地理解和处理人形机器人在使用过程中出现的各种问题,确保机器人的正常运行。本文将首先介绍人形机器人维护保养涉及的核心概念,解释各硬件组件的原理和它们之间的关系;接着阐述维护保养的核心算法原理和具体操作步骤,结合数学模型进行详细讲解;然后通过项目实战案例展示如何在实际中应用这些知识;

AI天才研究院 966

Lemmings3

题目:https://hdlbits.01xz.net/wiki/Lemmings3。

weixin_46769062的博客 505

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Lemmings4

如果去掉j==20的时候 j<=j ,在下面的rightfall和leftfall中判断条件改为j>=20,为什么是错误的。

zcy000810的博客 931

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

HDLBits刷题之:Lemmings1-3

Lemmings1: The game Lemmings involves critters with fairly simple brains. So simple that we are going to model it using a finite state machine. In the Lemmings’ 2D world, Lemmings can be in one of two states: walking left or walking right. It will switch d

qq_43156536的博客 953

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

HDLBits_Lemmings3

解析:和Lemmings2类似,增了个挖地的功能,dig为0时,会进行挖地,一直挖到ground为0。思路类似,将左右挖地分开。 代码: module top_module( input clk, input areset, // Freshly brainwashed Lemmings walk left. input bump_left, input bump_right, input ground, input dig, outp...

bbbman7的博客 339

HDLBits刷题_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, whenground=0, the Lemming will..

m0_65438107的博客 443

HDLBits-Lemmings2

由于增加了坠落(fall)状态,所以可以通过增加两个状态 即 L2G 和R2G 分别表示向左走时进入坠落状态,向右走时进入坠落状态。注意,areset为异步的,所以应该为always @(posedge clk or posedge areset)begin。

Kai666888的博客 344

习题笔记 Lemmings4

Lemmings4

Zephyr_R的博客 171
上一篇: FIR补偿滤波器——matlab的FDA实现
下一篇: 数字滤波器设计笔记1
且听风吟567
博客等级 码龄7年 231粉丝 77原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值