---> Go to Part part 1 part 2 part 4 part 5
4>Counter
See RTL for better understanding
RTL
//counter test bench
module counter_tb();
reg clk,rst,one_minute,load_new_c;
reg [3:0]new_current_time_ms_hr,new_current_time_ls_hr,new_current_time_ms_min,new_current_time_ls_min;
wire [3:0]current_time_ms_hr,current_time_ls_hr,current_time_ms_min,current_time_ls_min;
counter C(clk,rst,one_minute,load_new_c,
new_current_time_ms_hr,new_current_time_ls_hr,new_current_time_ms_min,new_current_time_ls_min,
current_time_ms_hr,current_time_ls_hr,current_time_ms_min,current_time_ls_min);
initial
begin
clk=0;
forever #5 clk=~clk;
end
task initialize();
begin
{clk,rst,one_minute,load_new_c,
new_current_time_ms_hr,new_current_time_ls_hr,new_current_time_ms_min,new_current_time_ls_min}=0;
end
endtask
task reset();
begin
@(negedge clk)
rst=1;
@(negedge clk)
rst=0;
end
endtask
task data(input [3:0]a,b,c,d);
begin
@(negedge clk)
load_new_c=1;
one_minute=0;
new_current_time_ms_hr=a;
new_current_time_ls_hr=b;
new_current_time_ms_min=c;
new_current_time_ls_min=d;
@(negedge clk)
load_new_c=0;
one_minute=1;
end
endtask
task mini(input e);
begin
one_minute=e;
end
endtask
initial
begin
initialize;
reset;
data(4'd0,4'd1,4'd1,4'd0);
#5;
end
initial
$monitor($time,"Input
clk=%b,rst=%b,one_minute=%b,load_new_c=%b,new_current_time_ms_hr=%b,new_current_time_ls_hr=%b,new_current_time_ms_min=%b,new_current_time_ls_min=%b
Outputcurrent_time_ms_hr=%b,current_time_ls_hr=%b,current_time_ms_min=%b,current_time_ls_min=%b",clk,rst,one_minute,load_new_c,new_current_time_ms_hr,new_current_time_ls_hr,new_current_time_ms_min,new_current_time_ls_min,current_time_ms_hr,current_time_ls_hr,current_time_ms_min,current_time_ls_min);
initial
#20000 $finish;
endmodule
--------------->Continue Part 4part 4
0 Comments