Traffic Light Controller Author: s1axter
Written: February 14th 2008, 9:03 pm PST
Overview
When I was in college our junior year lab included a project to construct a simple traffic light controller using only digital logic. This means no microcontroller, no 'if' statements nothing but pure hardcore logic. The intent of the lab was to implement a state machine in a realistic application. This article is a collection of pictures and a very general explanation of my solution, plus a VHDL implementation of it. NOTE: This is not a complete write up, it's mostly what I remember and found on my drives.

Scenario
A town needs to build an intersection between a heavily traveled East-West highway and a North-South country road. Since there are people in the town, the traffic light should have a pedestrian button which stops both roads for four (4) seconds and allow people to cross. When there is a car on the country road the highway should wait for five (5) seconds before turning red. The light for the country road should then be green for nine (9) seconds before going back to red. The highway is important to the area so the traffic lights should always return to green on the highway. The highway and country roads must have red, green and yellow lights, the pedestrian cross may only red and green.

The lab required a prototype using LEDs and seven-segment displays for the countdowns. The system could only use discrete digital logic chips and passive components.

Solution
The solution here uses two inputs, one for a car on the North-South road and one for the pedestrian. Since the default for the scenario is to enable the East-West road, no input is needed. If you make the state machine diagram for the inputs, you will see you have four possible outputs:



The equations at the bottom were determined using a karnal map. After the equations were determined it's just a matter of wiring up the logic chips to represent the equations



The entire circuit is clocked using a 32.786KHz crystal divided down to 1 hertz for the rest of the circuit. This one second clock controls a counting and display circuit designed to display the time remaining for each light in the system. This counting circuit uses countdown timers which assert a signal if the count reaches zero, this signal is then used as the control back to the state machine. The display circuit was also the control of the yellow lights in the system. When a countdown reached three seconds prior to the light turning red, a multiplexer chip switched disabled green and enabled yellow.



Aftermath:


VHDL:
Since most digital logic systems rely on simple boolean algebra they are really easy to port over to a hardware language like VHDL. A year after the traffic light controller project I created a VHDL version which runs on a Xilinx CoolRunner II development board. Attached to the dev board was a Digilent DIO1 board with LEDs, switches and four seven-segment displays. Three of the four seven-segment displays are used to count down the different times and the 8 LED bank is nicely R,Y,G,R,Y,G,R,R. Thus the upper 3 LEDs are the RYG for the East-West road, the next are for the North-South road and the final two red LEDs are for the pedestrian (we just pretend the last one is green). The project was perfect for the chip, using only 26% of the resources.

Here's a video if it in action:


And a zip file of the project using Xilinx's web pack ISE 7.1 software.

Traffic Project - Xilinx Web Pack ISE 7.1

If you know some VHDL feel free to download the code and play with it.
Joakim Olsson on Feb 24th, 2008 8:32am
Love this.
We did something similar but with a Mitsubishi PLC
when i went to school.
/Joakim
Daniel on Feb 24th, 2008 10:39am
So if its all logic, are all the gates programmed into that one IC?
s1axter on Feb 24th, 2008 11:10am
Yes, CPLDs are Complex Programmable Logic Devices, you can change the physical properties of the hardware inside. Thus you can implement almost any digital logic, even a CPU.

Check out these links:
http://www.opencores.org/
http://en.wikipedia.org/wiki/CPLD
Max on Feb 24th, 2008 4:31pm
Very cool project! I have been trying to teach myself digital logic over the past year or so. CPLD's look really cool. Any recommendation on which brands to look into?
Max on Feb 24th, 2008 5:29pm
Also, I am curious as to why you went with VHDL over Verilog?
s1axter on Feb 25th, 2008 8:42am
The CPLD is a Coolrunner II from Xilinx on a dev board from Digilent (http://www.digilentinc.com/). The reason it was put on a CPLD with VHDL was as an example to student for the following year as I was the TA for the course.
salam on Nov 22nd, 2008 11:39am
thank you
Leave a comment:

Comments have been taken down, too much spam. Sorry :-/
Name
Website (optional)

bold[TEXT] - italic[TEXT] - underline[TEXT] - big[TEXT]
Enter Number