← ProblemsCircuits / Sequential Logic / Finite State Machines

Water reservoir controller

15%fsmfsm-design

A water reservoir serves a small community. Three level sensors are mounted at different heights: s[1] is the lowest, s[2] the middle, and s[3] the highest. A sensor outputs 1 whenever the water is at or above its height, so the sensor vector is always thermometer-coded — only the values 000, 001, 011, and 111 ever occur (the test stimulus respects this, and the level only moves one range at a time).

Build a Moore FSM that controls three inflow valves fr1, fr2, fr3 and a supplemental-flow signal dfr. The lower the water, the more valves open:

Water levels[3:1]fr3fr2fr1
Above s[3]111000
Between s[2] and s[3]011001
Between s[1] and s[2]001011
Below s[1]000111

The dfr output adds hysteresis based on where the level came from:

  • If the level falls into the current range (the previous range was higher), dfr = 1, and it stays 1 for as long as the level remains in that range.
  • If the level rises into the current range (the previous range was lower), dfr = 0 while it remains in that range.
  • Below s[1], dfr is always 1. Above s[3], dfr is always 0.

This means the two middle ranges each need two states (one entered from above, one from below) — six states total.

The active-high reset is synchronous and puts the FSM in the state equivalent to the water having been below s[1] for a long time: all of fr1, fr2, fr3, and dfr asserted.