Complete Counter Testbench
`timescale 1ns/1ps
module counter_tb;
// Testbench signals (no ports!)
reg clk;
reg rst_n;
reg enable;
wire [7:0] count;
// Instantiate DUT (Device Under Test)
counter #(.WIDTH(8)) u_dut (
.clk (clk),
.rst_n (rst_n),
.enable (enable),
.count (count)
);
// Clock generation: 100MHz (10ns period)
initial clk = 0;
always #5 clk = ~clk;
// Stimulus
initial begin
// Initialize
rst_n = 0;
enable = 0;
// Apply reset
#20 rst_n = 1;
// Enable counting
#10 enable = 1;
// Let it run
#200;
// Disable and check
enable = 0;
#20;
// End simulation
$display("Test completed. Final count = %d", count);
$finish;
end
// Monitor (optional)
initial begin
$monitor("Time=%0t rst_n=%b en=%b count=%d",
$time, rst_n, enable, count);
end
endmodule