yosys/tests/asicworld/code_verilog_tutorial_count...

102 lines
2.5 KiB
Coq
Raw Normal View History

2015-08-13 02:35:00 -05:00
///////////////////////////////////////////////////////////////////////////
// MODULE : counter_tb //
// TOP MODULE : -- //
// //
// PURPOSE : 4-bit up counter test bench //
// //
// DESIGNER : Deepak Kumar Tala //
// //
// Revision History //
// //
// DEVELOPMENT HISTORY : //
// Rev0.0 : Jan 03, 2003 //
// Initial Revision //
// //
///////////////////////////////////////////////////////////////////////////
module testbench;
2016-05-20 10:13:11 -05:00
integer file;
reg clk = 0, reset = 0, enable = 0;
2015-08-13 02:35:00 -05:00
wire [3:0] count;
2016-05-20 10:13:11 -05:00
reg dut_error = 0;
2015-08-13 02:35:00 -05:00
counter U0 (
.clk (clk),
.reset (reset),
.enable (enable),
.count (count)
);
event reset_enable;
event terminate_sim;
initial
2016-05-20 10:13:11 -05:00
file = $fopen(`outfile);
2015-08-13 02:35:00 -05:00
always
#5 clk = !clk;
initial
@ (terminate_sim) begin
2016-05-20 10:13:11 -05:00
$fdisplay (file, "Terminating simulation");
2015-08-13 02:35:00 -05:00
if (dut_error == 0) begin
2016-05-20 10:13:11 -05:00
$fdisplay (file, "Simulation Result : PASSED");
2015-08-13 02:35:00 -05:00
end
else begin
2016-05-20 10:13:11 -05:00
$fdisplay (file, "Simulation Result : FAILED");
2015-08-13 02:35:00 -05:00
end
2016-05-20 10:13:11 -05:00
$fdisplay (file, "###################################################");
2015-08-13 02:35:00 -05:00
#1 $finish;
end
event reset_done;
initial
forever begin
@ (reset_enable);
@ (negedge clk)
2016-05-20 10:13:11 -05:00
$fdisplay (file, "Applying reset");
2015-08-13 02:35:00 -05:00
reset = 1;
@ (negedge clk)
reset = 0;
2016-05-20 10:13:11 -05:00
$fdisplay (file, "Came out of Reset");
2015-08-13 02:35:00 -05:00
-> reset_done;
end
initial begin
#10 -> reset_enable;
@ (reset_done);
@ (negedge clk);
enable = 1;
repeat (5)
begin
@ (negedge clk);
end
enable = 0;
#5 -> terminate_sim;
end
reg [3:0] count_compare;
always @ (posedge clk)
if (reset == 1'b1)
count_compare <= 0;
else if ( enable == 1'b1)
count_compare <= count_compare + 1;
always @ (negedge clk)
if (count_compare != count) begin
2016-05-20 10:13:11 -05:00
$fdisplay (file, "DUT ERROR AT TIME%d",$time);
$fdisplay (file, "Expected value %d, Got Value %d", count_compare, count);
2015-08-13 02:35:00 -05:00
dut_error = 1;
#5 -> terminate_sim;
end
endmodule