Experiment 6
Experiment 6
Submitted By:
Section: ECS-2
Year: 2020-2021
Experiment No.: 06
implementation.
Aim of the Experiment:
Design of traffic light controller, using Verilog, and it’s FPGA
implementation.
Theory:
1
traffic to proceed in the direction denoted. YELLOW- Provides warning
that the signal will be changing from green to red. RED- Prohibits any
traffic from proceeding.
A sensor on the farm is to detect if there are any vehicles and change the
traffic light to allow the vehicles to cross the highway. Otherwise, highway
light is always green since it has higher priority than the farm.
Code:
TASK:
TESTBENCH CODE:
module traffic_light_tb();
reg rst,clk;
wire h_red,h_yellow,h_green,s_red,s_yellow,s_green;
2
traffic_light L0(rst,clk,h_red,h_yellow,h_green,s_red,s_yellow,s_green);
initial begin
$dumpfile("dump.vcd");
$dumpvars;
clk=0;
rst=1;#10;
rst=0;#1000
$finish;
end
endmodule
DESIGN CODE:
input rst,clk;
parameter s0=0,s1=1,s2=2,s3=3;
initial state=0;
initial h_red=0;
initial h_yellow=0;
3
initial h_green=0;
initial s_red=0;
initial s_yellow=0;
initial s_green=0;
initial count=0;
if(rst)
state=s0;
else
case(state)
s0: begin
if(count==20) begin
count=0;
state=s1;
end
else begin
state=s0;
count=count+1;
end
end
s1: begin
if(count==10) begin
4
count=0;
state=s2;
end
else begin
state=s1;
count=count+1;
end
end
s2: begin
if(count==10) begin
count=0;
state=s3;
end
else begin
state=s2;
count=count+1;
end
end
s3: begin
if(count==5) begin
count=0;
state=s0;
5
end
else begin
state=s3;
count=count+1;
end
end
endcase
end
case(state)
s0: begin
h_green=1;
s_red=1;
h_red=0;
h_yellow=0;
s_yellow=0;
s_green=0;
end
s1: begin
h_green=0;
s_red=1;
h_red=0;
6
h_yellow=1;
s_yellow=0;
s_green=0;
end
s2: begin
h_green=0;
s_red=0;
h_red=1;
h_yellow=0;
s_yellow=0;
s_green=1;
end
s3: begin
h_green=1;
s_red=0;
h_red=0;
h_yellow=0;
s_yellow=1;
s_green=0;
end
endcase
end
7
endmodule
Output/Graph:
Synthesis Result:
Simulation Result:
8
Discussion/Inference of the experiment:
Designing of traffic light controller, using Verilog, and it’s FPGA
implementation, and obtaining their circuit design using Yosys 0.9.0 (for
synthesis) and their EPwaveform using Aldec Riviera Pro 2019.10 (for
simulation).
Conclusion:
This experiment enabled us to design the Verilog code for traffic light
controller, using Verilog, and it’s FPGA implementation. Also the test
bench for verification is written, in the alternative online Verilog
simulator, EDA Playground. The EPwaveform is observed and the code is
synthesized with the technological library and verified.
9
____________________
_
Signature of Faculty
10