Hi Community!
This project consists of creating a code for a pedestrian traffic light using the concepts of state machines, this project will detail step by step the creation and logic behind each line of code and how it was reached, the guide tells us that we must have a light normally green and pressing a button will change the light to red for 20 seconds, then display the last 5 seconds on the display.
Step 1
We create a new project called TrafficLights, in the following screen we choose the type of card to use, in this case it would be the Nexys3 card.
Step 2
We create a VHDL file to start our activity, we will call it TrafficLights too
Step 3
In the VHDL file we introduce the following code:
Step 4
After starting our code with the corresponding libraries, we will begin to point out the inputs and outputs in our code. Clock and Button are to simulate the clock and a user pressing this in real life. With the lights we will see which ones leave on time of the count and pressing the button and the display will give us the countdown from 15 to 20:
Step 5
We continue with our architecture where you will see the signs that will be part of our simulation, also the states, and the counts:
Step 6
We begin our architecture area with the first process that our program, which this time is to verify the states of our program, the program consists of 3 states, first when it is always green, then when the button is pressed button and finally when the display shows the 5 seconds countdown:
Step 7
The next process to take into account is that of the account, since it counts when the status is in process or when it is in green light. This step goes along with another process for it to work as expected:
Step 8
After these processes we place the lights that come out when going through each process:
Step 9
Finishing with our code, another process is carried out in which they are indicated when it is that If you want to start the countdown of 5 seconds, we indicate when meet the 15 seconds and then begin to indicate in the 7 segments the 5 seconds.
Step 10
Once the program is finished we can simulate the code to see the behavior and explain operation. When the button is 1, the light begins to change to "2" which would be red in this case, in the display will not see any number until reaching 15 seconds, it can be seen in the states How does this behavior work? It is seen in more detail when it starts being 16, that the count starts from 5 until it reaches 1, and then a reset is made where the "1" is seen as green, but there is no constant since the button is still 1.