80. Synchronous Slot Counter for Stadium Parking Management

Loading simulator…

Solution Explanation

  • Falling-Edge Detection: Since ENT and EXT are active-LOW sensors, each input uses two D flip-flops and NAND-based combinational logic to generate one pulse for every 1 → 0 transition. The detector outputs are ENTP and EXTP.
  • Valid Direction Control: Sensor detection and boundary protection are combined into two signals:

UPV = ENTP · EXTP' · EMPTY'

DNV = ENTP' · EXTP · FULL'

UPV increases the available-space count when a vehicle exits, while DNV decreases it when a vehicle enters. If both sensors activate together, the counter holds its current value.

  • Boundary Detection: The counter outputs are monitored using:

FULL = Q2' · Q1' · Q0'

EMPTY = Q2 · Q1 · Q0

FULL = 1 when the count is 000, meaning no parking spaces are available. EMPTY = 1 when the count is 111, meaning all seven spaces are available.

  • Count Enable: A common counting signal is generated as:

COUNTEN = UPV + DNV

COUNTEN becomes HIGH only when a valid entrance or exit event occurs.

  • 3-Bit Synchronous Up/Down Counter: Three positive-edge-triggered T flip-flops store the available-space count. All flip-flops use the same Clock.

T0 = COUNTEN

T1 = COUNTEN · (Q0 XNOR UPV)

T2 = COUNTEN · (Q0 XNOR UPV) · (Q1 XNOR UPV)

T0 toggles during every valid count. T1 and T2 toggle according to the current lower-bit states and the counting direction selected by UPV.

  • Underflow Protection: At 000, FULL = 1, which forces DNV = 0 and prevents the available-space count from decreasing below zero.
  • Overflow Protection: At 111, EMPTY = 1, which forces UPV = 0 and prevents the available-space count from increasing above seven.
  • Reset Operation: When ~Reset = 0, the counter is initialized to 111, representing all seven parking spaces available.
  • Parking Indicators:

parking_full = FULL

parking_available = FULL'

The red parking_full LED turns ON when the count is 000. The green parking_available LED remains ON whenever at least one parking space is available.