0
1
00:00:00,520 --> 00:00:06,550
In this lecture, I am going to put the computational circuit design techniques into a real example of 
1

2
00:00:06,550 --> 00:00:07,960
a traffic light controller.
2

3
00:00:09,580 --> 00:00:15,490
This figure shows the intersection of a main highway (the horizontal road) with a secondary access
3

4
00:00:15,490 --> 00:00:17,110
road (the vertical road). 
4

5
00:00:18,770 --> 00:00:28,550
Four sensors along lanes U, L, D, and R detects vehicles. The sensor output is 0 when no vehicle
5

6
00:00:28,550 --> 00:00:33,260
is presented and 1 if at least a car is on the corresponding lane. 
6

7
00:00:34,790 --> 00:00:42,050
There are two traffic lights on this junction, one for North-South traffic and another for East-West 
7

8
00:00:42,050 --> 00:00:42,650
traffic.
8

9
00:00:43,010 --> 00:00:48,560
The logic value “1” set the traffic light to green and the logic value “0” set the traffic
9

10
00:00:48,560 --> 00:00:52,340
light to red. The traffic lights should meet the following rules:
10

11
00:00:54,080 --> 00:01:02,090
1. The EW traffic light is green, and NS traffic light is red if both lanes R and L are occupied
11

12
00:01:03,240 --> 00:01:09,960
2. The EW traffic light is green, and NS traffic light is red if one of the lanes 
12

13
00:01:09,960 --> 00:01:14,880
R and L is occupied and both lanes U and D are also occupied.
13

14
00:01:16,220 --> 00:01:24,440
3. The NS traffic light is green, and EW traffic light is red if both lanes U and D 
14

15
00:01:24,440 --> 00:01:30,320
are occupied, and cars are not detected on both lanes L and R.
15

16
00:01:31,680 --> 00:01:32,250
4.
16

17
00:01:33,450 --> 00:01:40,800
The NS traffic light is green, and EW traffic light is red if one of the lanes U 
17

18
00:01:40,800 --> 00:01:45,660
and D is occupied while both lanes L and R are vacant.
18

19
00:01:47,180 --> 00:01:54,980
5. The EW traffic light is green, and NS traffic light is red if all lanes are vacant. 
19

20
00:01:57,420 --> 00:02:04,380
The final logic circuit has four inputs corresponding to the four sensors and two outputs for traffic 
20

21
00:02:04,380 --> 00:02:04,860
lights.
21

22
00:02:05,490 --> 00:02:12,490
This table shows all combinations of input values and the corresponding rules that they apply to set 
22

23
00:02:12,510 --> 00:02:13,440
the traffic lights.
23

24
00:02:15,690 --> 00:02:22,740
For example, if the sensors do not detect any cars then based on Rule 5, the EW traffic 
24

25
00:02:22,740 --> 00:02:27,540
light should be green, and the NS traffic light should be red.
25

26
00:02:29,760 --> 00:02:36,490
Or if there is traffic on the U lane and other lanes are vacant then based on Rule 4, the EW 
26

27
00:02:36,520 --> 00:02:41,430
traffic light should be red, and the NS traffic light should be green.
27

28
00:02:44,210 --> 00:02:50,330
Now let’s design the controller. For this purpose, we propose a logic circuit representing each rule 
28

29
00:02:50,540 --> 00:02:54,450
and then we will combine them to create the final traffic-light controller.
29

30
00:02:55,190 --> 00:02:58,010
The first rule says EW is 1 
30

31
00:02:58,430 --> 00:03:04,730
if both R and L sensors are one. We can use an AND gate to implement this rule. 
31

32
00:03:07,710 --> 00:03:16,950
The second rule says EW is 1 if one of the R and L sensors is 1, and both U and D sensors
32

33
00:03:16,950 --> 00:03:21,990
are not 1. An XOR can model the first part of the rule, 
33

34
00:03:22,680 --> 00:03:30,240
and a NAND gate can represent the second part. And then an AND gate can combine these two parts. 
34

35
00:03:32,530 --> 00:03:42,070
The third rule says NS light is 1 if both U and D sensors are 1 and both L and R sensors 
35

36
00:03:42,070 --> 00:03:48,340
are 0. A NAND can model the first part of the rule, and an AND gate represents the second
36

37
00:03:48,340 --> 00:03:48,760
part.
37

38
00:03:49,870 --> 00:03:53,670
Then an AND gate can combine them to make the rule. 
38

39
00:03:55,510 --> 00:04:01,030
Similarly, this logic circuit with three gate models the fourth rule. 
39

40
00:04:02,610 --> 00:04:07,080
Two XNOR gates combined by an AND gate can implement the fifth rule. 
40

41
00:04:08,520 --> 00:04:15,720
We have two groups of rules, Rules 1, 2 and 5 set the EW to 1 and Rules 3, and 4
41

42
00:04:15,840 --> 00:04:17,040
set the NS to 1.
42

43
00:04:18,610 --> 00:04:24,130
Now we should combine these rules to design the controller.
First, let’s combine the rules inside a group.
43

44
00:04:25,390 --> 00:04:32,350
Using OR gates, we can combine rules inside a group. 
Now we have the controller that generates EW 
44

45
00:04:32,350 --> 00:04:33,640
and NS outputs.
45

46
00:04:34,940 --> 00:04:40,760
Now let’s write a C code to implement this controller. For this purpose, we write a C function for 
46

47
00:04:40,760 --> 00:04:48,320
Each function receives the values of four sensors and returns a value controlling the EW
47

48
00:04:48,350 --> 00:04:49,910
or NS traffic light.
48

49
00:04:50,060 --> 00:04:53,570
These are the codes for Rules 1, 2 and 3.
49

50
00:04:55,220 --> 00:04:58,310
And these are the codes for Rules 4 and 5.
50

51
00:05:00,420 --> 00:05:08,160
Now an HLS top function can call and combine these rules.
The function has six arguments; two of them 
51

52
00:05:08,160 --> 00:05:10,890
are pointers to be connected to the traffic lights. 
52

53
00:05:11,500 --> 00:05:13,380
First, we call rules.
53

54
00:05:16,980 --> 00:05:20,170
Then we combine them with OR operators.
54

55
00:05:20,730 --> 00:05:28,950
Finally, we should add interfaces. This picture shows the HLS report after synthesis. The propagation 
55

56
00:05:28,950 --> 00:05:33,210
delay of the circuit is about 2.934 ns.
56

57
00:05:33,840 --> 00:05:41,340
The hardware is a combinational circuit that utilises 34 LUTs. And ports are a set of single 
57

58
00:05:41,340 --> 00:05:44,910
wires without any specific protocol as we expected.
58

59
00:05:46,940 --> 00:05:52,850
Now that we have designed the traffic light controller, we should see its behaviour in action. The 
59

60
00:05:52,850 --> 00:05:56,870
next lecture follows the implementation of this design on the Basys3 
60

61
00:05:56,870 --> 00:05:57,280
board.  
61

62
00:05:59,490 --> 00:06:05,070
This is our takeaway message.  Dividing a complex problem and algorithm into a set of subfunctions is 
62

63
00:06:05,070 --> 00:06:07,070
the key to manage the design process.
63

64
00:06:09,100 --> 00:06:14,770
Now the quiz question. The two traffic lights in an intersection must not be green at the same time.
64

65
00:06:15,400 --> 00:06:19,090
Check that the FW signal is the opposite of the NS 
65

66
00:06:19,090 --> 00:06:21,190
signal in slide number 10.
