-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathTraffic_eng312_proj3.v
executable file
·172 lines (138 loc) · 3.18 KB
/
Traffic_eng312_proj3.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
`timescale 1ns / 1ps
/*
Group Members: Kevin Ingram and Warren Seto
Lab Name: Traffic Light Controller (Lab 3)
Project Name: eng312_proj3
Design Name: Traffic_eng312_proj3.v
Design Description: Verilog Module that uses the following modules to operate: nsCounter, ewCounter, yellowCounter
*/
module Traffic
(
input [4:0] nsCounter,
input [3:0] ewCounter,
input [1:0] yellowCounter,
input NS_VEHICLE_DETECT,
input EW_VEHICLE_DETECT,
output reg NS_RED,
output reg NS_YELLOW,
output reg NS_GREEN,
output reg EW_RED,
output reg EW_YELLOW,
output reg EW_GREEN
);
// Sets the start state at: 001100
initial begin
NS_RED <= 0;
NS_YELLOW <= 0;
NS_GREEN <= 1;
EW_RED <= 1;
EW_YELLOW <= 0;
EW_GREEN <= 0;
end
always @ (nsCounter) begin
// Sets the start state at: 010100
if (nsCounter == 31 & EW_VEHICLE_DETECT & NS_GREEN) begin
NS_RED <= 0;
NS_YELLOW <= 1;
NS_GREEN <= 0;
EW_RED <= 1;
EW_YELLOW <= 0;
EW_GREEN <= 0;
end
end
// Sets the start state at: 100010
always @ (ewCounter) begin
if (ewCounter == 15 & EW_GREEN) begin
NS_RED <= 1;
NS_YELLOW <= 0;
NS_GREEN <= 0;
EW_RED <= 0;
EW_YELLOW <= 1;
EW_GREEN <= 0;
end
end
// Sets the start state at: 001100
always @ (yellowCounter) begin
if (yellowCounter == 3 & NS_YELLOW) begin
NS_RED <= 1;
NS_YELLOW <= 0;
NS_GREEN <= 0;
EW_RED <= 0;
EW_YELLOW <= 0;
EW_GREEN <= 1;
end
// Sets the start state at: 100001
if (yellowCounter == 3 & EW_YELLOW) begin
NS_RED <= 0;
NS_YELLOW <= 0;
NS_GREEN <= 1;
EW_RED <= 1;
EW_YELLOW <= 0;
EW_GREEN <= 0;
end
end
endmodule
/*
A Counter for the North-South Traffic Light
Counts from 0-31
*/
module nsCounter
(
input clk,
output [4:0] count
);
wire clk;
reg[4:0] count;
initial
count = 0;
always @ ( negedge clk )
count[0] <= ~count[0];
always @ ( negedge count[0] )
count[1] <= ~count[1];
always @ ( negedge count[1] )
count[2] <= ~count[2];
always @ ( negedge count[2] )
count[3] <= ~count[3];
always @ ( negedge count[3] )
count[4] <= ~count[4];
endmodule
/*
A Counter for the East-West Traffic Light
Counts from 0-15
*/
module ewCounter
(
input clk,
output [3:0] count
);
wire clk;
reg[3:0] count;
initial
count = 0;
always @ ( negedge clk )
count[0] <= ~count[0];
always @ ( negedge count[0] )
count[1] <= ~count[1];
always @ ( negedge count[1] )
count[2] <= ~count[2];
always @ ( negedge count[2] )
count[3] <= ~count[3];
endmodule
/*
A Counter for the common yellow Traffic Light
Counts from 0-3
*/
module yellowCounter
(
input clk,
output [1:0] count
);
wire clk;
reg[1:0] count;
initial
count = 0;
always @ ( negedge clk )
count[0] <= ~count[0];
always @ ( negedge count[0] )
count[1] <= ~count[1];
endmodule