Design Process

In order to better under the digital design process with respect to real-world applications, a two-way traffic light controller was designed. The traffic light operated in two modes:

  1. Timed signal changing cycle with weight sensor input
    The primary mode of operation is the standard timed signal changing. Additional logic was added to implement a weight sensor input (via push-button switch), causing a red light to change green faster when asserted.
  2. Hazard Condition
    During hazardous conditions, one traffic light flashes yellow, while the other flashes red—disrupting the traditional timed cycle. This mode was implemented using a flip switch to signify hazard condition.

To simplify troubleshooting processes, the traffic light controller was built in stages. The initial timed cycle for one traffic light was modeled using a finite-state machine. After implementing and testing this initial design, the weight sensor feature was added for the sole traffic light. Finally, the logic for the hazard condition was added, which was fairly simple.

Once a single traffic light was fully implemented using a finite state machine, a second traffic light was added using identical conditions respective to the second light. The change between the two traffic lights’ logic was changing which light flashes in hazard mode: yellow for light1, red for light2.

To coordinate the two lights to work together, the logic for each light was changed for the transition from red to green. A timer (Q26) was added to allow for both lights to remain red shortly before one transitions to green—a pretty standard feature. Since the lights share the same logic for transitioning from red to green, a light enable bit was added to distinguish which light should switch. When the light enable is low, light2 changes, when the light enable is high, light1 changes. This light enable input is toggled whenever a light transitions from yellow to red.

The following are letter assignments for the different varibles:

RED1 – R1
YELLOW1 – Y1
GREEN1 – G1
RED2 – R2
YELLOW2 – Y2
GREEN2 – G2
RESET – Re
HAZARD – H
CLOCK – Q##
WEIGHTSENSOR 1 – W1clock
WEIGHTSENSOR 2 – W2clock

The complete logic for each of the 6 lights is below, with the assignments on the right:

Red1
1. (R1)(H) – If red1 is on and hazard switch is on, turn red1 off
2. (R1)(R2)(H’)(E)(Q26) – If red1 and red2 are on, and it’s traffic light #1’s turn, then switch red1 off and go to green1
3. (Y1)(Q27) – When yellow1 is done, switch to red
4. (R1’)(H’)(Re) – When reset is pushed, make sure red1 is turned on

Yellow1
1. (Y1)(Q27) – When yellow1 is done, switch to red1
2. (G1)(Q29) – When green1 is done, switch to yellow1
3. (H)(Q26) – When hazard switch is on, toggle yellow1 for every Q26
4. (Y)(Re) – If reset is pushed and yellow1 is on, turn it off
5. (G1)(W¬2clock = 1 sec) – If green1 is on and weight sensor 2 is pressed for one second, then switch to yellow in preparation for traffic light 2 changing to green

Green1
1. (R1)(R2)(H’)(E)(Q26) – If red1 and red2 are on, and it’s traffic light #1’s turn, then switch red1 off and go to green1
2. (G1)(H) – If green1 is on and hazard switch is on, turn green1 off
3. (G1)(Re) – If reset is pushed and green1 is on, turn it off
4. (G1)(W2¬clock = 1 sec) – If green1 is on and weight sensor 2 is pressed for one second, then switch to yellow in preparation for traffic light 2 changing to green
5. (G1)(Q29) – When green1 is done, switch to yellow1

Red2
1. (H)(Q26) – When hazard switch is on, toggle red2 for every Q26
2. (R1)(R2)(H’)(E’)(Q26) – If red1 and red2 are on, and it’s traffic light #2’s turn, then switch red2 off and go to green2
3. (Y2)(Q27) – When yellow2 is done, switch to red
4. (R2)(Re) – If reset is pushed and red2 is on, turn it off

Yellow2
1. (Y2)(Q27) – When yellow2 is done, switch to red2
2. (G2)(Q29) – When green2 is done, switch to yellow2
3. (H)(Y2) – If yellow2 is on and hazard switch is on, turn yellow2 off
4. (Y2)(Re) – If reset and pushed and yellow2 is on, turn it off
5. (G2)(W1clock = 1 sec) – If green2 is on and weight sensor 1 is pressed for one second, then switch to yellow in preparation for traffic light 1 changing to green

Green2
1. (R1)(R2)(H’)(E’)(Q26) – If red1 and red2 are on, and it’s traffic light #2’s turn, then switch red2 off and go to green2
2. (G2’)(H’)(Re) – If green2 is not on, hazard switch is not on, and the reset button is pushed, then turn green2 on
3. (G2)(W1clock = 1 sec) – If green2 is on and weight sensor 1 is pressed for one second, then switch to yellow in preparation for traffic light 1 changing to green
4. (H)(G2) – If green2 is on and hazard switch is on, turn green2 off.
5. (G2)(Q29) – When green2 is done, switch to yellow2

Light Enable
1. (Y2)(Q27) – When yellow2 switches to red2
2. (Y1)(Q27) – When yellow1 switches to red1
3. Set Light Enable Low – Whenever reset is pushed

32-bit Counter Reset
When any of the conditions are met for any light (i.e. all conditions for Red1, Red2, Yellow1, etc…)

The following is a block diagram of the design’s functional units:

Traffic Light Controller - Block Diagram

Testing, Debugging, and Problems Encountered

There were several obstacles in the design, the first being how to implement the weight sensor. When someone stops at a red light and makes a turn on red, then the weight sensor should not trigger. Therefore, the weight sensor should only trigger the logic to change the light after it has been pressed for a period of time. To perform this timing function, the group deployed the Xilinx CB8CE counter macro with the weight sensor input tied to the counter enable (CE) of the macro. Therefore, the weight counter would only run when the sensor was pressed. When the output of the weight counter reached the desired value, it triggered the logic to change the light. The weight counter was reset anytime a light transitioned, so it always started at zero.

The second bug encountered occurred when the weight sensor was pressed half-way into the green light’s timed cycle, causing both the yellow and red light to come on at the same time. The only explanation for this bug was caused by a timing hazard, where two logic statements were being met at the same time when they shouldn’t be: (Y2)(Q27) and (G2)(W1clock = 1 sec). To solve this problem, the group added an additional logic statement to each red light: if yellow and red are both on, then turn red off.

Improvements and Conclusion

There are several ways to improve the design. First, the counters used for the light were for demonstration purposes only to display functionality. A real traffic light would likely operate much slower. This change in speed can easily be accommodated by using different values on the 32-bit counter and on the weight sensor. Additional lights can be added, such as a turn signal. A vision could replace the weight sensor as a lower cost alternative; it could easily be implemented with a photoresistor replacing the push-button as the input. Finally, a very extravagant feature would network the traffic light with the computer for remote control and activity monitoring.

Designing the traffic light adequately tested the group’s knowledge of digital design. The project gave insight into the digital design process in addition to just digital logic. The group learned that digital logic can be used to implement a lot of practical applications—not simply from the traffic light, but from all the projects designed by the class. There is surprisingly more logic involved in a traffic light than expected. However, by starting very early and following a modular design process, the project was very manageable. The project gave particular insight to finite state machines implemented with numerous counters. Overall, the design project was a very rewarding experience; a positive learning opportunity.

Pictures available here.

EDIT: 2/16/08 – I zipped the code and put it online to download. There’s a few macros in there. I believe the main program is called TrafficLightTwo

Share
Add to:
| Digg it | RawSugar | Reddit | Slashdot | Y! MyWeb

4 Responses to “DIY: Traffic Light Controller Using Digital Logic”  

  1. 1 Grant Pitel

    You should post your code in in a zip file.

  2. 2 Adnash

    Can you post or e-mail the codes please. I am new to Xilinx I want to design same thing will be good lesson for me.

    Regards

    Adnash

  3. 3 Adam Pitel

    Posted. See the edit at the bottom of the article for the link.

  4. 4 kirby

    how does light sensors work with the traffic light? please answer me as soon as possible because i will be needing your answer for my science investigatory project ..thank you in advance

Leave a Reply