$30
1
ECE2029: Introduction to Digital Circuit Design
Lab 5 - Garage Occupancy Counter
1. Objective
The objective of this lab is to design an occupancy counter to display how many cars are
currently parked in the garage. Figure 1 shows a typical garage entrance with sensors on both
entrance and exit gates.
Figure 1. Garage entrance and exit with photo sensors
2. Detecting Vehicle Entering the Garage
The basic design is to use a pair of photo sensors. When an object is between the optical transmit
and optical receiver, the light is blocked and the corresponding output is asserted to ‘1’.
Otherwise, the output is ‘0’. As shown in Fig. 1, we can determine if a car has entered the garage
by monitoring the events (orders) of these 2 sensors.
The sequence can be described as the following:
a) Initially, both sensor are unblocked (i.e., a and b signals are “00”)
b) Sensor a is blocked (signals are “10”)
c) Sensor b is blocked (signals are “01”)
d) Both sensors are unblocked (“00”)
a
b
c
d
2
Although it is not required for this lab design, you may consider the question: What if the car is
very long (a limousine) or very short (a smart)?
3. Detecting Vehicle Exiting the Garage
The sequence will be the opposite as that of entering:
a) Initially, both sensor are unblocked (i.e., c and d signals are “00”)
b) Sensor d is blocked (signals are “01”)
c) Sensor c is blocked (signals are “10”)
d) Both sensors are unblocked (“00”)
Although it is not required for this lab design, you may consider the questions: What if the car is
very long (a limousine) or very short (a smart)? Could a pair of sensors be “11” or “00” in
between steps b) and c)?
3
4. Top-Level Design Diagram
Figure 2. Top-level design diagram for the garage occupancy counter.
• The “Enter FSM” and “Exit FSM” should have been designed in your prelab.
• The “Counter Block” in your prelab has 2 inputs: inc (increment) and dec (decrement). When
a car enters the garage, inc set to ‘1’ for one clock period. Similarly, when a car leaves the
garage, dec set to ‘1’ for one clock period.
• The display drive is the same as in your Lab 4. It takes 8-bit binary input and displays it in
3decimal digits on 7-segment LEDs. For 8-bit binary input, the maximal number of cars the
counter can count is 255.
5. Implement and Test the System
We use 4 push buttons on the Basys 3 board to simulate the 4 photo sensors (a, b, c, and d).
When the button is pressed, its output value is set to ‘1’. The buttons are located at the right side
of the Basys 3 board.
We also need a “reset” signal for the counter and state machines. We use the center push button
as a reset.
Enter
FSM
Exit
FSM
Parking
Counter
Display
Driver
a
b
d
c
clk reset
seg[6:0]
an[3:0]