`timescale 1ns/1ps module shared_500us_tick_tb; reg clk = 1'b0; reg rst_n = 1'b0; wire tick; integer tick_count; integer cycle_count; always #1 clk = ~clk; shared_500us_tick #(.CLOCK_HZ(10), .TICK_US(1000000)) dut ( .clk(clk), .rst_n(rst_n), .tick(tick) ); always @(negedge clk) begin if (rst_n && tick) tick_count = tick_count + 1; end initial begin tick_count = 0; repeat (2) @(posedge clk); if (dut.counter !== 0 || tick !== 1'b0) $fatal(1, "reset did not clear divider"); @(posedge clk); #0.1; rst_n = 1'b1; for (cycle_count = 0; cycle_count < 10; cycle_count = cycle_count + 1) begin @(posedge clk); @(negedge clk); #0.1; if (cycle_count < 9) begin if (dut.counter !== cycle_count + 1 || tick !== 1'b0) $fatal(1, "divider boundary mismatch cycle=%0d counter=%0d tick=%b", cycle_count, dut.counter, tick); end else if (dut.counter !== 0 || tick !== 1'b1) begin $fatal(1, "tick did not occur on divider terminal count counter=%0d tick=%b", dut.counter, tick); end end if (tick_count !== 1) $fatal(1, "tick count mismatch after one period: %0d", tick_count); for (cycle_count = 0; cycle_count < 10; cycle_count = cycle_count + 1) begin @(posedge clk); @(negedge clk); #0.1; end if (tick_count !== 2) $fatal(1, "tick count mismatch after two periods: %0d", tick_count); $display("shared_500us_tick_tb PASS"); $finish; end endmodule