惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
人人都是产品经理
人人都是产品经理
小众软件
小众软件
博客园 - Franky
WordPress大学
WordPress大学
Jina AI
Jina AI
Google DeepMind News
Google DeepMind News
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Fortinet All Blogs
博客园 - 【当耐特】
IT之家
IT之家
G
Google Developers Blog
J
Java Code Geeks
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
云风的 BLOG
云风的 BLOG
Recent Announcements
Recent Announcements
有赞技术团队
有赞技术团队
V
Visual Studio Blog
U
Unit 42
阮一峰的网络日志
阮一峰的网络日志
月光博客
月光博客
GbyAI
GbyAI
雷峰网
雷峰网

博客园 - yf.x

超声波测距#倒车雷达#DE10-Lite 按键计数器#DE10-Lite 按键消抖#DE10-Lite 流水呼吸灯v2#DE10-Lite 流水呼吸灯-v1#DE10-Lite 呼吸灯-#DE10-Lite 流水灯#DE10-Lite#Verilog HDLBits_review 2015fsm 补码FSM-HDLbits 串行数据流输出其中的数据位-HDLbits 串行数据接收判断-HDLbits 输出PS2数据流-HDLbits PS2数据流检测状态机-HDLbits 独热码状态机-HDLbits 旅鼠游戏3-HDLbits 旅鼠游戏2-HDLbits 旅鼠游戏--HDLbits 水库水位控制问题-HDLbits 康威生命游戏-hdlbits
旅鼠4-HDLbits
yf.x · 2025-12-17 · via 博客园 - yf.x

在老鼠左右走,碰墙翻转,挖坑,掉落之外加了摔死的状态。要求掉落时长超过20个时钟并且撞地就死。

难点在于下落时长的计算,必须在2种下落状态计算是否超过20个时钟,另,计数器的位宽不方便定义很大,用int比较合适。

再者就是状态转换。

module top_module(
input clk,
input areset, // Freshly brainwashed Lemmings walk left.
input bump_left,
input bump_right,
input ground,
input dig,
output walk_left,
output walk_right,
output aaah,
output digging );
parameter LEFT=0,RIGHT=1,FALL_L=2,FALL_R=3,DIG_L=4,DIG_R=5,SPLAT=6;
reg [2:0]state,next_state;

always @(posedge clk,posedge areset)
if(areset)
state<=LEFT;
else
state<=next_state;

//20 clk counter
int cnt;

always @(posedge clk,posedge areset)
if(areset )
begin
cnt<=0;
end
else if(next_state==FALL_L || next_state==FALL_R)
begin
cnt<=cnt+1;
end
else if(cnt>20)
begin
cnt<=cnt;
end
else
cnt<=0;

always @(*)
case(state)
LEFT:next_state=ground?(dig?DIG_L:(bump_left?RIGHT:LEFT)):FALL_L;
RIGHT:next_state=ground?(dig?DIG_R:(bump_right?LEFT:RIGHT)):FALL_R;
FALL_L:next_state=ground?((cnt>20)?SPLAT:LEFT):FALL_L;
FALL_R:next_state=ground?((cnt>20)?SPLAT:RIGHT):FALL_R;
DIG_L:next_state=ground?DIG_L:FALL_L;
DIG_R:next_state=ground?DIG_R:FALL_R;
SPLAT:next_state=SPLAT;
default:next_state=3'bx;
endcase

assign walk_left=(state==LEFT && !(state==SPLAT));
assign walk_right=(state==RIGHT && !(state==SPLAT));
assign aaah=(state==FALL_L) || (state==FALL_R )&&!(state==SPLAT);
assign digging=(state==DIG_L) || (state==DIG_R)&& !(state==SPLAT);
endmodule