Lemmings 3
1.Decade counter2.Four-bit binary counter3.Decade counter again4.Slow decade counter5.Counter 1-126.Counter 10007.4-digit decimal counter8.12-hour clock9.Hdlbits博文分布10.4-bit shift register11.Left/right rotator12.Left/right arithmetic shift by 1 or 813.5-bit LFSR14.3-bit LFSR15.32-bit LFSR16.Shift register17.Shift register(2)18.3-input LUT19.Rule 9020.Rule 11021.Conway's Game of Life 16x1622.Simple FSM1(asynchronous reset)23.Simple FSM1(synchronous reset)24.Simple FSM2(asynchronous reset)25.Simple FSM2(synchronous reset)26.Simple state transition 327.Simple one-hot state transition 328.Simple FSM 3(asynchronous reset)29.Simple FSM 3(synchronous reset)30.Design a Moore FSM31.Lemmings 132.Lemmings 2
33.Lemmings 3
34.Lemmings 435.One-hot FSM36.PS/2 packet parser37.PS/2 packet parser and datapath38.Serial receiver39.Serial receiver and datapath40.Serial receiver with parity checking41.Sequence recognition42.Q8:Design a Mealy FSM43.Q5a:Serial two's complementer(Moore FSM)44.Q5b:Serial two's complementer(Moore FSM)45.Q3a:FSM46.Q3b:FSM47.Q3c:FSM logic48.Q6b:FSM next-state logic49.Q6c:FSM next-state logic50.Q6:FSM51.Q2a:FSM52.Q2:One-hot FSM equations53.Q2a: FSM54.Q2b:Another FSM55.Counter with period 100056.4-bit shift register and down counter57.FSM:Sequence 1101 recognizer58.FSM:Enable shift register59.FSM:The complete FSM60.The complete timer61.FSM:One-hot logic equations62.UARTSee also: Lemmings1 and Lemmings2.
In addition to walking and falling, Lemmings can sometimes be told to do useful things, like dig (it starts digging when dig=1). A Lemming can dig if it is currently walking on ground (ground=1 and not falling), and will continue digging until it reaches the other side (ground=0). At that point, since there is no ground, it will fall (aaah!), then continue walking in its original direction once it hits ground again. As with falling, being bumped while digging has no effect, and being told to dig when falling or when there is no ground is ignored.
(In other words, a walking Lemming can fall, dig, or switch directions. If more than one of these conditions are satisfied, fall has higher precedence than dig, which has higher precedence than switching directions.)
参见:Lemmings1 和 Lemmings2。
除了走路和跌倒之外,旅鼠有时还可以被告知做一些有用的事情,比如挖掘(当 dig=1 时它开始挖掘)。如果旅鼠目前在地面上行走(地面=1且没有坠落),则可以挖掘,并将继续挖掘,直到到达另一侧(地面=0)。在这一点上,由于没有地面,它会掉下来(啊!),然后在它再次落地后继续向原来的方向行走。与跌倒一样,在挖掘时被撞到是没有效果的,在跌倒或没有地面时被告知挖掘是被忽略的。
(换句话说,行走的旅鼠可以跌倒、挖掘或改变方向。如果满足这些条件中的多个条件,则 fall 的优先级高于 dig,而 dig 的优先级高于切换方向的优先级。
扩展有限状态机以对此行为进行建模。
题目网站
状态转换如下:
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=6'b000_001,
RIGHT=6'b000_010,
FALL_L=6'b000_100,
FALL_R=6'b001_000,
DIG_L=6'b010_000,
DIG_R=6'b100_000;
reg [5:0]state,nstate;
reg [3:0]judge;
assign judge={ground,dig,bump_left,bump_right};
always@(*)begin
case(state)
LEFT:begin
casex(judge)
4'b0xxx:nstate=FALL_L;
4'b11xx:nstate=DIG_L;
4'b101x:nstate=RIGHT;
default:nstate=LEFT;
endcase
end
RIGHT:begin
casex(judge)
4'b0xxx:nstate=FALL_R;
4'b11xx:nstate=DIG_R;
4'b1001:nstate=LEFT;
default:nstate=RIGHT;
endcase
end
FALL_L:begin
casex(judge)
4'b1xxx:nstate=LEFT;
default:nstate=FALL_L;
endcase
end
FALL_R:begin
casex(judge)
4'b1xxx:nstate=RIGHT;
default:nstate=FALL_R;
endcase
end
DIG_L:begin
casex(judge)
4'b0xxx:nstate=FALL_L;
default:nstate=DIG_L;
endcase
end
DIG_R:begin
casex(judge)
4'b0xxx:nstate=FALL_R;
default:nstate=DIG_R;
endcase
end
endcase
end
always@(posedge clk or posedge areset)begin
if(areset)begin
state<=LEFT;
end
else begin
state<=nstate;
end
end
assign walk_left=(state==LEFT);
assign walk_right=(state==RIGHT);
assign digging=(state==DIG_L||state==DIG_R);
assign aaah=(state==FALL_L||state==FALL_R);
endmodule
完美,终于可以完全自己写出来了,理解了逻辑就好办了
合集:
Verilog学习
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理