In this lecture, I am going to put the computational circuit design techniques into a real example of 1
a traffic light controller. 2
This figure shows the intersection of a main highway (the horizontal road) with a secondary access 3
road (the vertical road). 4
Four sensors along lanes U, L, D, and R detects vehicles. The sensor output is 0 when no vehicle 5
is presented and 1 if at least a car is on the corresponding lane. 6
There are two traffic lights on this junction, one for North-South traffic and another for East-West 7
traffic. 8
The logic value “1” set the traffic light to green and the logic value “0” set the traffic 9
light to red. The traffic lights should meet the following rules: 10
1. The EW traffic light is green, and NS traffic light is red if both lanes R and L are occupied 11
2. The EW traffic light is green, and NS traffic light is red if one of the lanes 12
R and L is occupied and both lanes U and D are also occupied. 13
3. The NS traffic light is green, and EW traffic light is red if both lanes U and D 14
are occupied, and cars are not detected on both lanes L and R. 15
4. 16
The NS traffic light is green, and EW traffic light is red if one of the lanes U 17
and D is occupied while both lanes L and R are vacant. 18
5. The EW traffic light is green, and NS traffic light is red if all lanes are vacant. 19
The final logic circuit has four inputs corresponding to the four sensors and two outputs for traffic 20
lights. 21
This table shows all combinations of input values and the corresponding rules that they apply to set 22
the traffic lights. 23
For example, if the sensors do not detect any cars then based on Rule 5, the EW traffic 24
light should be green, and the NS traffic light should be red. 25
Or if there is traffic on the U lane and other lanes are vacant then based on Rule 4, the EW 26
traffic light should be red, and the NS traffic light should be green. 27
Now let’s design the controller. For this purpose, we propose a logic circuit representing each rule 28
and then we will combine them to create the final traffic-light controller. 29
The first rule says EW is 1 30
if both R and L sensors are one. We can use an AND gate to implement this rule. 31
The second rule says EW is 1 if one of the R and L sensors is 1, and both U and D sensors 32
are not 1. An XOR can model the first part of the rule, 33
and a NAND gate can represent the second part. And then an AND gate can combine these two parts. 34
The third rule says NS light is 1 if both U and D sensors are 1 and both L and R sensors 35
are 0. A NAND can model the first part of the rule, and an AND gate represents the second 36
part. 37
Then an AND gate can combine them to make the rule. 38
Similarly, this logic circuit with three gate models the fourth rule. 39
Two XNOR gates combined by an AND gate can implement the fifth rule. 40
We have two groups of rules, Rules 1, 2 and 5 set the EW to 1 and Rules 3, and 4 41
set the NS to 1. 42
Now we should combine these rules to design the controller. First, let’s combine the rules inside a group. 43
Using OR gates, we can combine rules inside a group. Now we have the controller that generates EW 44
and NS outputs. 45
Now let’s write a C code to implement this controller. For this purpose, we write a C function for 46
Each function receives the values of four sensors and returns a value controlling the EW 47
or NS traffic light. 48
These are the codes for Rules 1, 2 and 3. 49
And these are the codes for Rules 4 and 5. 50
Now an HLS top function can call and combine these rules. The function has six arguments; two of them 51
are pointers to be connected to the traffic lights. 52
First, we call rules. 53
Then we combine them with OR operators. 54
Finally, we should add interfaces. This picture shows the HLS report after synthesis. The propagation 55
delay of the circuit is about 2.934 ns. 56
The hardware is a combinational circuit that utilises 34 LUTs. And ports are a set of single 57
wires without any specific protocol as we expected. 58
Now that we have designed the traffic light controller, we should see its behaviour in action. The 59
next lecture follows the implementation of this design on the Basys3 60
board. 61
This is our takeaway message. Dividing a complex problem and algorithm into a set of subfunctions is 62
the key to manage the design process. 63
Now the quiz question. The two traffic lights in an intersection must not be green at the same time. 64
Check that the FW signal is the opposite of the NS 65
signal in slide number 10.