Traffic Light Controller: Using VHDL
Traffic Light Controller: Using VHDL
Traffic Light Controller: Using VHDL
Submitted by-
Srishti- 2K7-Mrce-Aei-052
Bhavika Khanna-2k7-Mrce-Aei-051
Sumedha Sardana-2k7-Mrce-Aei-053
1.ABSTRACT.
The purpose of this project is to design and implement a traffic light controller for a single
intersection.
The controller is constructed from a finite state machine used to control the actual operation of
the
traffic lights. The remainder of the system consists of supporting subsystems, including RAM, a
Timer, Divider, and various synchronizers. Time values used by the finite state machine are
written
to and read from the RAM. The design used VHDL code compiled to a Cypress 374i CPLD and
various digital hardware parts from the 6.111 Kit.
II. Description
A. Functional Specifications
As mentioned earlier, the intersection to be controlled is between a busy (Main) street and a
somewhat less busy (Side) street. Both streets have ordinary (Red, Yellow, Green) signal lights.
The
intersection is fitted with a sensor for side-street traffic and with a walk request button. Figure 1
shows the layout of the intersection.
Another important unit is the Timer. It counts for a number one-second intervals that are
specified
by data stored in the SRAM. It then sends a signal, the EXPIRED bit; to the FSM notifying that
it
is time to change state. The Timer is implemented as a LS169 synchronous up/down counter and
some and-logic to generate the expired bit.
Lastly, there are various synchronizers that ensure that all inputs to the FSM are synchronized to
the
system clock. The synchronization is done using VHDL on the CPLD. The WALK signal is a
special case of synchronization, since it also has to be latched too. This way pressing the WALK
button once ensures that a WALK request will be queued. The logic to do this is also
implemented
in VHDL on the CPLD.
C. FSM
The inputs and outputs to the FSM are denoted in Table 2 and Table 3.
Table 2: FSM Inputs
RESET Go back to reset state (from switch)
GS Synchronized GO signal, start function (from pulse-shaper fed by pushbutton)
F1 and F0 Determines one or the four different functions (from switches)
L1 and L0 Specify a location in the SRAM (from switches)
WS Synchronized walk request signal (from re-settable latch fed by pushbutton)
TS Traffic Sensor (from flip-flop fed by switch)
EXPIRED Signals when a pre-specified time has elapsed (from Timer)
Table 3: FSM Outputs
A1 and A0 Specifies an address in SRAM (to SRAM address lines)
/WE Drives value from switches onto bus, write into SRAM
STARTTIMER Resets 1-second clock and Timer, enables loading of new value in Timer
Gm, Ym, Rm,
Gs, Ys, Rs
Traffic light control signals
The FSM has four functions, as listed in Table 1. Incorporating these functions and the various
states of the traffic light, a state transition diagram for the FSM was generated. It is reproduced
as
Figure 4 on the next page. The diagram shows the four separate functions of the FSM. The ‘idle’
state of the machine is something called the RESET state. In this state, none of the lights are on,
and the system does not do anything. The system will stay in the RESET state until the GO
button
is pressed. At this time the system will enter the state denoted by the F0 and F1 switches. We
will
now look at each of the functions of the FSM in greater detail.
RESET
Read RAM
Write RAM
BLINK MODE
Side Red
Main Yellow
BLINK MODE
Side Yellow
Main Red
Side Green
Main Red
TBASE
Side Yellow
Main Red/Yellow
TYEL
Side Red
Main Green
TBASE
Side Red
Main Green
TEXT
Side Yellow/Red
Main Yellow
TYEL
WALK
Side Yellow/Red
Main Yellow/Red
TEXT
TS = 1
TS = 0
WS = 1
WS = 0
F1 = 1, F0 = 0, GS = 1
GS = 0
F1 = 1, F0 = 1, GS = 1
F1 = 0, F0 = 0, GS = 1
F1 = 0, F0 = 1, GS = 1
X
X
X
X
X
X
X
X
State Transition Diagram
6.111 Laboratory 2
Sourav Dey
X denotes 'always make this transition
RESET is asynchronous, hitting reset in any state
will send system back to RESET state
1. Read (F1 = 0, F0 = 0)
The FSM can read locations in the RAM and display the contents to a HEX led. The data path
exercised is shown in Figure 5. A read is only executed upon a press of the GO button. If both F1
and F0 are 0 at this point, the FSM goes into the read state for ONE clock cycle, and then returns
to
the RESET state immediately afterwards. The value of the address read is kept showing on the
hex
LEDs.
Figure 4: FSM Read/Write Data Path
The exact timing issues are interesting. First off, there is an important aside. The GO signal is an
asynchronous signal generated by the user pressing a pushbutton. This signal is NOT directly
passed to the FSM. It first goes thru the gosync unit, which acts as a pulse-shaper. Gosync
asserts GS high for only ONE clock cycle, no matter how long GO is depressed. There is more
on
this in the Synchronizer section, but this fact must be mentioned here because the fact that GS is
only high for one clock cycle is used over and over again.
Once in the read state, the FSM asserts A1 = L1 and A0 = L0. Since the /OE on the RAM is
grounded, asserting the address bit immediately causes the RAM to dump the contents of that
address onto the I/O bus. This value is then sent to a HEX led where the user can see it. In
addition, the FSM remember what address was read and stores that value internally as a signal
called
HOLDADDR. After the Read the FSM goes immediately back to the RESET state. In the
RESET
state, A1 and A0 are set to HOLDADDR. Thus the value of the last address read is constantly
shown on the hex LEDs, even in the RESET state.
The timing diagram is shown in Figure 5. Note how the address A1-A0 read is held in the
RESET
state.
Figure 5: Timing Diagram for Read Operation
2. Write (F1 = 0, F0 = 1)
The FSM can write new timing parameters to the RAM. The data path exercised is also shown in
Figure 4. A write is only executed upon a press of the GO button. As long at F1 = 0 and F0 = 1
when GO is pressed, the FSM goes into the write state for only ONE clock cycle. It returns to the
RESET state immediately afterwards.
In the write state, the FSM asserts A1 = L1 and A0 = L0. In addition it asserts /WE low for the
one clock cycle of the write state. This enables the tri-state buffer, which pushes the values of
switches C0-C3 on the RAM I/O bus. The actual write to the RAM occurs when both the /CLK
and /WE are low. The exact timing details of this operation are discussed in the RAM section.
A timing diagram of the signals coming out of the FSM is shown in Figure 6. Note again, how
the
GS signal is only high for one clock cycle. Also note how the system returns to the original
addresses after the write is completed. This feature is a little annoying because the user cannot
see
what is written. Instead, the user must explicitly do another read on that address to see what was
written there. This can be easily changed, but I opted not do so in fear of breaking something else
in the process.
Most transitions in the traffic light cycle are taken no matter what. They are denoted by an X on
the
state transition diagram (Figure 3. However, in two cases an input matters. In the transition from
Side Green/Main Red to Side Yellow, the FSM checks first to see if the Traffic Sensor is
depressed.
If it is, the next state is set to Side Green/ Main Red again for TBASE. The traffic sensor is
simulated using a switch on the kit.
The second case occurs on the transition from Main Yellow/Side Red/Yellow. On this transition,
the FSM checks if there is a pending WALK request. If there is, the next state is the WALK
state,
where both Main and Side are Yellow/Red. Otherwise, if there is no Walk request present, the
FSM
just goes to Side Green/ Main Red. The Walk request is queued using a latch mechanism
attached
to a push button. Thus, in WALK mode this signal must be explicitly Unlatched. To do this and
ensure that no WALK requests can be taken while in the Walk state, the WALKRESET signal is
asserted high for the entire WALK state.
Fig
ure 14: Walk Latch Logic Diagram
The walk signal is latched so that when the user pushes the walk button once the signal is queued
until the FSM needs it. Figure 14shows this unit. It is implemented in VHDL on the CPLD. The
FSM can also reset the latch by asserting the WALKRESET signal. While the WALKRESET
signal
is high, the latch cannot hold any walk requests. The signal is passed through a flip-flop to
synchronize it to the system clock.
2. Go Sync
Figure 15: Go Pulse Shaper Logic Diagram
The gosync unit is a pulse-shaper. It ensures that no matter how long the GO button is depressed,
GS is only asserted for one clock cycle. It is implemented in VHDL on the CPLD. Figure 15
shows a close up of the unit. The design is taken from 6.111 Lecture 7 notes.
3. Traffic Sensor
The TRAFFIC SENSOR signal is synchronized by simply passing it through a flip-flop.
B. Hardware
1. Divider
The two counter chips and the crystal oscillator were fairly easy to set up. The period of the
clock
was verified using the oscilloscope. It was almost exactly the 440 Hz.
2. Tri-State Buffer and RAM
The tri-state and the RAM were tested together. A1 and A0 on the RAM were hooked up directly
to some switches and the outputs were routed to a HEX led. /WE and /CS2 were connected to
switches too. Using this setup the operation of the RAM was verified.
3. Timer
After this the LS169 was hooked up to RAM and its /LD and /ENT inputs were connected to
switches. Another HEX led was attached to the outputs of the LS169. The loading and counting
operations were then tested with the RAM.
IV. Conclusion
When the switch was flipped on the system for the first time, nothing worked. Thus began the
daunting task of debugging. Probing the system in a few places found that the one-second pulse
coming from the FSM was positive logic, whereas the LS169 needed negative logic for the /ENT
signal. Instead of changing the VHDL code to fix the problem, an inverter was placed on
SECPULSE.
This simple fix caused the system to ALMOST work. The only problem now was that the system
I
was counting one extra second in every state. This was thought to be a problem in my VHDL.
But
after some time looking over the code the VHDL was found to not be the problem. Instead it was
found that the RCO on the LS169 that was generating the EXPIRED signal was not being
asserted
for the two clock cycles expected. This was because /RCO is only asserted when /ENT is active.
Thus instead of using the RCO, external AND logic was used to determine when the Timer hit
0000. After these two relatively minor errors were fixed, the system worked perfectly.
An iterative approach was taken to the problem, building skeletal functionality and adding more
and
more features as more design issues came up. Each subcomponent was constructed and tested
thoroughly before moving onto the next one. Also, all the design issues were addressed as they
came up, instead of plugging it into the board and debugging from there. Progress went slowly,
but
in the end, this is the reason the lab went fairly smoothly.
All in all, the design is robust. There are no ‘hack’ solutions, and all the design decisions were
scrutinized thoroughly before implementation. Overall, the design and implementation of the
traffic
light controller is a good first step in designing more complex system. It stressed the importance
of
designing subsystems one at a time and drew attention to various control, data path, and timing
issues common in large digital systems. Most importantly though, the lab served to teach proper
techniques engineers should use when building complex systems.