← ProblemsCircuits / Sequential Logic / Finite State Machines

Lemmings 4: splat

5%fsmfsm-designcounters

Lemmings, alas, are mortal. A fall that lasts too long ends badly.

Extend the Lemming of the previous exercise (walk / fall / dig, with the same priorities: falling > digging > switching direction) with a splat rule:

  • Count how many clock cycles the Lemming spends falling (cycles during which aaah = 1).
  • If the fall lasted 20 cycles or fewer, the Lemming resumes walking in its previous direction when it lands (ground = 1), as before.
  • If the fall lasted more than 20 cycles (21 or more), the Lemming splats when it lands: from then on all four outputs (walk_left, walk_right, aaah, digging) are 0 forever, and all inputs are ignored, until the asynchronous reset areset brings it back to life (walking left).

Timing precisely: the fall length is the number of consecutive clock cycles in a falling state. Landing on the edge that ends the 20th falling cycle → survive and walk; landing on the edge that ends the 21st (or later) falling cycle → splat. While falling, aaah = 1 regardless of how long the fall has been.

The active-high areset is asynchronous and resets the Lemming to walking left.