| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- `timescale 1ns/1ps
- module prod2u_p4_us_tick_tb;
- reg clk;
- reg rst_n;
- wire tick_1us;
- integer cycle;
- integer pulse_count;
- prod2u_p4_us_tick #(
- .CLK_HZ(4000000)
- ) dut (
- .clk(clk),
- .rst_n(rst_n),
- .tick_1us(tick_1us)
- );
- initial begin
- clk = 1'b0;
- forever #5 clk = ~clk;
- end
- initial begin
- rst_n = 1'b0;
- pulse_count = 0;
- repeat (3) @(negedge clk);
- rst_n = 1'b1;
- for (cycle = 1; cycle <= 20; cycle = cycle + 1) begin
- @(posedge clk);
- #1;
- if (tick_1us) begin
- pulse_count = pulse_count + 1;
- if ((cycle % 4) != 0) begin
- $display("1 us tick arrived on wrong divide cycle=%0d", cycle);
- $fatal;
- end
- end
- end
- if (pulse_count !== 5) begin
- $display("1 us tick count mismatch count=%0d", pulse_count);
- $fatal;
- end
- $display("PASS: prod2u_p4_us_tick_tb");
- $finish;
- end
- endmodule
|