prod2u_p4_us_tick_tb.v 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. `timescale 1ns/1ps
  2. module prod2u_p4_us_tick_tb;
  3. reg clk;
  4. reg rst_n;
  5. wire tick_1us;
  6. integer cycle;
  7. integer pulse_count;
  8. prod2u_p4_us_tick #(
  9. .CLK_HZ(4000000)
  10. ) dut (
  11. .clk(clk),
  12. .rst_n(rst_n),
  13. .tick_1us(tick_1us)
  14. );
  15. initial begin
  16. clk = 1'b0;
  17. forever #5 clk = ~clk;
  18. end
  19. initial begin
  20. rst_n = 1'b0;
  21. pulse_count = 0;
  22. repeat (3) @(negedge clk);
  23. rst_n = 1'b1;
  24. for (cycle = 1; cycle <= 20; cycle = cycle + 1) begin
  25. @(posedge clk);
  26. #1;
  27. if (tick_1us) begin
  28. pulse_count = pulse_count + 1;
  29. if ((cycle % 4) != 0) begin
  30. $display("1 us tick arrived on wrong divide cycle=%0d", cycle);
  31. $fatal;
  32. end
  33. end
  34. end
  35. if (pulse_count !== 5) begin
  36. $display("1 us tick count mismatch count=%0d", pulse_count);
  37. $fatal;
  38. end
  39. $display("PASS: prod2u_p4_us_tick_tb");
  40. $finish;
  41. end
  42. endmodule