Lemmings Controller FSM
advanced · state_machine · 240 XP
Sign in to write your solution, run it in the simulator and submit it for grading.
Sign in or create a free account →Problem
Lemmings Controller FSM
A state machine that models a cartoon character (Lemming) with four possible behaviours, each outputting a control signal. The FSM must respond to environment inputs and remember state across transitions.
**States & Outputs**
| State | Output Signals | Triggers |
|-------------|----------------------------------------|--------------------------------------------|
| WALK_L | `walk_l=1, walk_r=0, aaah=0, digging=0` | walking left (default) |
| WALK_R | `walk_l=0, walk_r=1, aaah=0, digging=0` | walking right |
| FALL | `walk_l=0, walk_r=0, aaah=1, digging=0` | in air (ground=0) |
| DIG | `walk_l=0, walk_r=0, aaah=0, digging=1` | digging (manual action) |
**Transition Rules**
1. **Direction reversal:** `bump_left` signal → reverse direction (WALK_L ↔ WALK_R)
2. **Falling:** `ground=0` → enter FALL state (suspend current walk direction)
3. **Landing:** `ground=1` in FALL state → resume previous walk direction (must remember which!)
4. **Digging:** `dig=1` while walking → enter DIG state
5. **Resume:** `dig=0` or `ground=0` (falling while digging) → exit DIG, resume walk
6. **Bump priority:** bump signals override normal movement (test priority carefully)
**Inputs**
| Port | Type | Desc |
|-------------|------|----------------------------------------------|
| `clk` | 1b | Clock |
| `rst` | 1b | Sync reset → WALK_L |
| `ground` | 1b | 1=on ground, 0=in air (no gravity sim) |
| `bump_left` | 1b | Hit left wall: reverse direction |
| `bump_right`| 1b | Hit right wall: reverse direction |
| `dig` | 1b | Start digging (toggle action) |
**Outputs**
`walk_l, walk_r, aaah (falling), digging` (all 1-bit registered)
**Key insight:** This tests **state retention** (remembering walk direction across a fall), **priority** (ground takes precedence), and **multi-input conditioning** (all three inputs must be checked simultaneously).
Constraints
- Use at least 6 states: WALK_L, WALK_R, FALL, FALL_L (falling but was walking left), FALL_R (falling but was walking right), DIG.
- Falling (ground=0) takes priority — immediately transition to FALL state regardless of walk direction.
- Landing (ground=1 after fall) must resume the walk direction that was active before the fall.
- Bumps reverse walk direction immediately; if falling, change the "next walk" direction.
- Digging ends on any of: dig=0 (manual cancel), ground=0 (fall during dig), or bump signals.
Examples
Input: WALK_R, then bump_left=1
Output: → WALK_L
Direction reversal
Input: WALK_R, ground=0
Output: → FALL (was walking right)
Fall while walking
Input: FALL (was right), ground=1
Output: → WALK_R
Resume correct direction after landing
Input: WALK_L, dig=1
Output: → DIG
Start digging
Input: DIG, ground=0
Output: → FALL (was walking left)
Fall cancels dig; resume left on land
Common questions
- What does the Lemmings Controller FSM problem ask you to build?
- Lemmings Controller FSM A state machine that models a cartoon character (Lemming) with four possible behaviours, each outputting a control signal. The FSM must respond to environment inputs and remember state across transitions.
- What constraints does Lemmings Controller FSM have?
- Use at least 6 states: WALK_L, WALK_R, FALL, FALL_L (falling but was walking left), FALL_R (falling but was walking right), DIG.; Falling (ground=0) takes priority — immediately transition to FALL state regardless of walk direction.; Landing (ground=1 after fall) must resume the walk direction that was active before the fall.; Bumps reverse walk direction immediately; if falling, change the "next walk" direction.; Digging ends on any of: dig=0 (manual cancel), ground=0 (fall during dig), or bump signals.
- What is an example input and output for Lemmings Controller FSM?
- Input WALK_R, then bump_left=1 gives output → WALK_L. Direction reversal
- Which Verilog concepts does Lemmings Controller FSM practise?
- state_machine, FSM, multi-condition, game-logic, interview.