Traffic Light Controller Program
Traffic Light Controller Program
// 8. Initial Conditions
initial
begin
clk = 1'b0;
rst_n = 1'b0;
sensor = 1'b0;
// count = 0;
//// count1=0;
// a=0;
end
// 9. Generating Test Vectors
initial
begin
main;
end
task main;
fork
clock_gen;
reset_gen;
operation_flow;
debug_output;
endsimulation;
join
endtask
task clock_gen;
begin
forever #`DELAY clk = !clk;
end
endtask
task reset_gen;
begin
rst_n = 0;
# 20
rst_n = 1;
end
endtask
// fpga4student.com FPGA projects, VHDL projects, Verilog projects
task operation_flow;
begin
sensor = 0;
# 600
sensor = 1;
# 1200
sensor = 0;
# 1200
sensor = 1;
end
endtask
// 10. Debug output
task debug_output;
begin
$display("----------------------------------------------");
$display("------------------ -----------------------");
$display("----------- SIMULATION RESULT ----------------");
$display("-------------- -------------------");
$display("---------------- ---------------------");
$display("----------------------------------------------");
$monitor("TIME = %d, reset = %b, sensor = %b, light of highway =
%h, light of farm road = %h",$time,rst_n
,sensor,light_highway,light_farm );
end
endtask
endmodule
Simulation results for the traffic light controller in Verilog:
TIME = 2000, reset = 1, sensor = 0, light of highway = 1, light of farm
road = 4
TIME = 60000, reset = 1, sensor = 1, light of highway = 1, light of farm
road = 4
TIME = 60001, reset = 1, sensor = 1, light of highway = 2, light of farm
road = 4
TIME = 72211, reset = 1, sensor = 1, light of highway = 4, light of farm
road = 1
TIME = 122011, reset = 1, sensor = 1, light of highway = 4, light of
farm road = 2
TIME = 136951, reset = 1, sensor = 1, light of highway = 1, light of
farm road = 4
TIME = 136953, reset = 1, sensor = 1, light of highway = 2, light of
farm road = 4
TIME = 136955, reset = 1, sensor = 1, light of highway = 4, light of
farm road = 1
TIME = 180000, reset = 1, sensor = 0, light of highway = 4, light of
farm road = 1
TIME = 186751, reset = 1, sensor = 0, light of highway = 4, light of
farm road = 2
TIME = 201691, reset = 1, sensor = 0, light of highway = 1, light of
farm road = 4
TIME = 300000, reset = 1, sensor = 1, light of highway = 1, light of
farm road = 4
TIME = 300001, reset = 1, sensor = 1, light of highway = 2, light of
farm road = 4
TIME = 311251, reset = 1, sensor = 1, light of highway = 4, light of
farm road = 1
TIME = 361051, reset = 1, sensor = 1, light of highway = 4, light of
farm road = 2
TIME = 375991, reset = 1, sensor = 1, light of highway = 1, light of
farm road = 4
TIME = 375993, reset = 1, sensor = 1, light of highway = 2, light of
farm road = 4
TIME = 375995, reset = 1, sensor = 1, light of highway = 4, light of
farm road = 1