In my code, the output is taken on four 7 segment displays. “r” will represent Red, “y”
will represent Yellow, “g” will represent Green and “b” will represent both Green-Yellow. I have
designed 20 seconds process in which each green will on for 5 seconds, each red will on for 4
seconds and each yellow will on for 1 second.
Signal3 Signal2 Signal1 Signal0 Time Output
(sec)
R R R G 4 rrrg
R R Y YG 5 rryb
R R G R 9 rrgr
R Y YG R 10 rybr
R G R R 14 rgrr
Y YG R R 15 ybrr
G R R R 19 grrr
YG R R Y 20 brry
Block diagram:-
Main module:-
module traffic_signals(LED,an,forced,ready,clock_20ns,start);
output [6:0]LED;
output [3:0]an;
input ready,clock_20ns,start;
input [3:0]forced;
wire clock_1s,clock_4ms;
wire [3:0]data,signal3,signal2,signal1,signal0,m;
endmodule
Timer module:-
module timer(clock_1s,count,clock_20ns,start);
parameter n = 25;
parameter N = 25000000;
output reg clock_1s = 0;
output reg [n-1:0]count = 0;
input clock_20ns,start;
Controller module:-
module controller(signal3,signal2,signal1,signal0,forced,ready,clock_1s,start);
Multiplexer module:-
module mux(an,signal3,signal2,signal1,signal0,m);
always @(*)
begin
case(m[1:0])
2'b00:
an = signal0;
2'b01:
an = signal1;
2'b10:
an = signal2;
2'b11:
an = signal3;
endcase
end
endmodule
LED module:-
module LED_multiplex(LED,data);
output [6:0]LED;
input [3:0]data;
reg [6:0]temp = 0;
always @ (data)
begin
if(data == 4'b0100) // Red
begin
temp = 7'b0011001; // r
end
if(data == 4'b0010) // Yellow
begin
temp = 7'b1000100; // y
end
if(data == 4'b0011) // Yellow and green
begin
temp = 7'b1100000; // b
end
if(data == 4'b0001) // Green
begin
temp = 7'b0000100; // g
end
end
endmodule
UCF file:-
NET "clock_20ns" LOC = B8;