Professional Documents
Culture Documents
INTRODUCTION
The traffic light controller design based on Xilinx is simply a
state diagram implementation of 2*n states for n lights. The
state diagram depicts the change of state of the traffic signal.
The signal light values which are available as registers are
triggered based on the state, whereas the state value is
changed in accordance with a clock pulse. The implementation
involves switching the green light on each side for 8 clock
pulses and yellow light for 3 clock pulses.
CODE
BEHAVIOURAL:
`timescale 1ns / 1ps
module
traffic_control(n_lights,n_ped,e_lights,e_ped,s_lights,s_ped,w_lights,w_ped,clk,rst_a)
;
clk;
input
rst_a;
end
end
north_y :
begin
if (count==3'b011)
begin
count=3'b000;
state=west;
end
else
begin
count=count+3'b001;
state=north_y;
end
end
south :
begin
if (count==3'b111)
begin
count=3'b0;
state=south_y;
end
else
begin
count=count+3'b001;
state=south;
end
end
south_y :
begin
if (count==3'b011)
begin
count=3'b0;
state=east;
end
else
begin
count=count+3'b001;
state=south_y;
end
end
east :
begin
if (count==3'b111)
begin
count=3'b0;
state=east_y;
end
else
begin
count=count+3'b001;
state=east;
end
end
east_y :
begin
if (count==3'b011)
begin
count=3'b0;
state=north;
end
else
begin
count=count+3'b001;
state=east_y;
end
end
west :
begin
if (count==3'b111)
begin
state=west_y;
count=3'b0;
end
else
begin
count=count+3'b001;
state=west;
end
end
west_y :
begin
if (count==3'b011)
begin
state=south;
count=3'b0;
end
else
begin
count=count+3'b001;
state=west_y;
end
end
endcase // case (state)
end // always @ (state)
end
always @(state)
begin
case (state)
north :
begin
n_lights = 3'b001;
s_lights = 3'b100;
e_lights = 3'b100;
w_lights = 3'b100;
n_ped = 2'b10;
s_ped = 2'b10;
e_ped = 2'b10;
w_ped = 2'b01;
end // case: north
north_y :
begin
n_lights = 3'b010;
s_lights = 3'b100;
e_lights = 3'b100;
w_lights = 3'b100;
n_ped = 2'b10;
s_ped = 2'b10;
e_ped = 2'b10;
w_ped = 2'b01;
end // case: north_y
south :
begin
n_lights = 3'b100;
s_lights = 3'b001;
e_lights = 3'b100;
w_lights = 3'b100;
n_ped = 2'b10;
s_ped = 2'b10;
e_ped = 2'b01;
w_ped = 2'b10;
end // case: south
south_y :
begin
n_lights = 3'b100;
s_lights = 3'b010;
e_lights = 3'b100;
w_lights = 3'b100;
n_ped = 2'b10;
s_ped = 2'b10;
e_ped = 2'b01;
w_ped = 2'b10;
end // case: south_y
west :
begin
n_lights = 3'b100;
s_lights = 3'b100;
e_lights = 3'b100;
w_lights = 3'b001;
n_ped = 2'b10;
s_ped = 2'b01;
e_ped = 2'b10;
w_ped = 2'b10;
end // case: west
west_y :
begin
n_lights = 3'b100;
s_lights = 3'b100;
e_lights = 3'b100;
w_lights = 3'b010;
n_ped = 2'b10;
s_ped = 2'b01;
e_ped = 2'b10;
w_ped = 2'b10;
end // case: west_y
east :
begin
n_lights = 3'b100;
s_lights = 3'b100;
e_lights = 3'b001;
w_lights = 3'b100;
n_ped = 2'b01;
s_ped = 2'b10;
e_ped = 2'b10;
w_ped = 2'b10;
end // case: east
east_y :
begin
n_lights = 3'b100;
s_lights = 3'b100;
e_lights = 3'b010;
w_lights = 3'b100;
n_ped = 2'b01;
s_ped = 2'b10;
e_ped = 2'b10;
w_ped = 2'b10;
end // case: east_y
TEST BENCH:
module Traffic_test2;
// Inputs
reg clk;
reg rst_a;
// Outputs
wire [2:0] n_lights;
wire [2:0] w_lights;
wire [2:0] s_lights;
wire [2:0] e_lights;
wire [1:0] w_ped;
wire [1:0] s_ped;
wire [1:0] e_ped;
wire [1:0] n_ped;
.s_ped(s_ped),
.w_lights(w_lights),
.w_ped(w_ped),
.clk(clk),
.rst_a(rst_a)
);
initial begin
// Initialize Inputs
clk = 0;
rst_a = 0;
#10;
clk = 0;rst_a = 0;
forever #10 clk = ~clk;
end
endmodule
STATE DIAGRAM
RTL SCHEMATIC
SIMULATION