Learn

Practice

Tank Level Decoder (K-Map)

A rainwater tank needs a drain pump at levels 10 to 15 and a low-level warning at levels 0 to 3. Implement both outputs with gates, using a Karnaugh map to simplify them. The 4-bit input level_i runs from 0 (empty) to 15 (full).

Optional practice if you already use K-maps comfortably.

Truth Table

Levell3 l2 l1 l0pumplowLevell3 l2 l1 l0pumplow
00000018100000
10001019100100
200100110101010
300110111101110
401000012110010
501010013110110
601100014111010
701110015111110

Interface

PortDirectionTypeDescription
level_iin4-bit vectorTank fill level, 0 to 15
pump_oout1 bitDrain pump on
low_oout1 bitLow-level warning

Behavior

  • pump_o and low_o match their truth-table columns for every one of the 16 input values; the testbench sweeps them all
  • The outputs are pure functions of level_i: no state, no clock

Constraints

OPERATORS: build each output from individual bits of level_i using only and, or, and not; no arithmetic and no comparisons.

  • Use the largest legal K-map groups. The hints can help if you cannot simplify a group further.
  • The tests check the truth table. Check the grouping on your own map as well.
Loading editor...

Click Run to execute your code. Output will appear here.