Intro: Stoplight LED
For our CPE 133 Digital Design final project, we decided to make a Stoplight using an Basys 3 FPGA board and some LED microcontrollers with an external breadboard. We have switches corresponding to the inputs for the "cars that stop at the light" and are essentially the sensors for this project. The lights are the outputs and will light up accordingly.
This project was inspired by the Stoplight question on one of the FSM quizzes in class and also by the fact that I get slightly impatient waiting at a vacant intersection, knowing that the logic for the Traffic Light Intersection needs to be implemented with better logic and efficiency.
Step 1: Materials
3 LEDs (Red, Yellow, and Green)
Basys 3 FPGA Board
4 male-male wires
3 330Ω resistors (so you don't burn out your LEDs, safety issues)
Xilinx 2016.2 or later version (preferably)
Step 2: OVERVIEW of COMPONENTS
Below is a list of the components and their function for the stoplight:
Clock divider -- The clock divider is used in order to keep the circuit running at a constant speed. Without it, our state machine wouldn’t have much order to it and would light up the LEDs at times we wouldn’t want it to. Using the clock divider helped us go from one state to the other without very many issues and allowed humans to physically see a difference in the changes of state.
Finite State Machine(FSM) -- This is the main control center of our design. It takes in two inputs that we control on the Basys Board and then outputs to the corresponding LEDs. It also outputs to our decoder which letters need to be lit up on the seven segment display.
Standard Seven Segment Display -- The seven segment display is important for displaying the words for each state of the stop light. For yellow it displays SLOW, red it displays STOP, and green it displays GO. It depends on the FSM in order to run properly.
Step 3: Black Box Diagram
Above is all the components connected together to help us run our stoplight.
- The overall block diagram has three inputs: EN, RESET, and CLK. It also has 3 outputs: C, AN, PMOD1, PMOD2, and PMOD3.
- The EN stands for Enable switch and the RESET is for the reset switch. The clock divider takes in the clock signal and outputs another clock signal to the FSM. The EN and RESET both go to the input of the FSM.
- The FSM outputs the colored LEDs for the corresponding PMODs(i.e. PMOD1 is RED, PMOD2 is YELLOW, etc.). Along with outputting the PMODs it also sends 2 bits to the seven segment display.
- These two bits let the seven segment display know what state it is in in order to display the correct word/letter. For instance, if RED was the output from PMOD1, the FSM would send “00” to the seven segment display and the seven segment display will give display STOP.
- This goes for each state. And there you have it!
Step 4: Code
Now that the block diagram is finished, everything else should be easy! I wouldn’t say it’s easy but you definitely got the harder part out of the way. The main thing you have to do in the coding is make sure you have all your components in the same module in order to define and connect them in the overall module.
- For example, in our FSM we established our inputs and outputs of the FSM. After that, we logically figured out how to go from one state to the next using the switches. A copy of our code is shown above for the light FSM.
- We used the seven segment display module and clock divider module from our labs this quarter. The hard part was figuring out how these components wired up to the FSM.
- Once you figure that part out, you just port map inputs and outputs of the components accordingly using VHDL.
- Be careful if you are mapping outputs of one component to the inputs of another. You need to have a signal in order to do this because an input can’t be an output in VHDL at the same time. For example, we had to use a signal for our clock divider that went from the output of the clock divider to the input of the FSM.
Step 5: Connecting Everything to a Breadboard
Here is where you start putting those materials to use. In order to properly connect them, you must first locate 3 ports in the PMOD and decide which ports are best to use. The PMODs are located down in the picture below with the red arrow.
The first male end of the first wire goes into the first PMOD port(note: make sure your port you are plugging into corresponds to the constraints you use in VHDL). We used JA1 for the first port of our constraints. You can refer to the Basey Board user manual in order to get the rest of the ports of the VHDL constraints file.
The other end goes into positive terminal of bread board
Do these for each wire. You’re halfway there!
Remember the ground(goes in ground port of Basey Board and negative end of breadboard)
Put one end of resistor in negative terminal(connected to ground) and one end connected in the same line of breadboard as small end of LED
Longer end of LED is connected in the same line as resistor(in resistors polarity doesn’t matter but in LEDs it does)
Step 6: Play With the Stoplight!
After connecting everything accordingly and implementing the correct code, you should be good to go! If you want the stoplight to be more realistic you may need to mess with the frequency in the clock divider code to make it longer. Troubleshooting may be necessary in order to get them to go in the right sequence or the right letter/word is being displayed on the Basey Board. Once you get this working, you can move to more advanced projects! We’ve even included a few extra ideas to this project that are a little more challenging to implement.
Authors: Jonathan Lee, Ryan Morosa
Counter- helps with timing and displays on the seven segment display board counting down of seconds before next state
Build another stoplight and make the state of one stoplight depend on the state of the other