prod2u_p4_axis_jog_16bit_tb.v 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. `timescale 1ns/1ps
  2. module prod2u_p4_axis_jog_16bit_tb;
  3. reg clk;
  4. reg rst_n;
  5. reg jog_start;
  6. reg jog_dir;
  7. reg [15:0] jog_steps;
  8. wire step_out;
  9. wire busy;
  10. wire drive_active;
  11. wire [15:0] remaining_steps;
  12. integer guard;
  13. integer rises;
  14. reg previous_step;
  15. prod2u_p4_axis_executor #(
  16. .HAS_LIMIT(1),
  17. .STANDARD_STEPS(4),
  18. .DIR_SETUP_US(1),
  19. .SPEED0_HALF_US(1),
  20. .SPEED1_HALF_US(1),
  21. .SPEED2_HALF_US(1),
  22. .SPEED3_HALF_US(1)
  23. ) dut (
  24. .clk(clk),
  25. .rst_n(rst_n),
  26. .tick_1us(1'b1),
  27. .force_stop(1'b0),
  28. .limit_fast(1'b0),
  29. .limit_active(1'b0),
  30. .jog_start(jog_start),
  31. .jog_dir(jog_dir),
  32. .jog_speed_code(2'd3),
  33. .jog_steps(jog_steps),
  34. .standard_start(1'b0),
  35. .standard_target_open(1'b0),
  36. .mark_closed(1'b0),
  37. .mark_close_dir(1'b0),
  38. .terminal_ready(1'b1),
  39. .step_out(step_out),
  40. .dir_out(),
  41. .busy(busy),
  42. .drive_active(drive_active),
  43. .position_valid(),
  44. .current_aperture(),
  45. .target_aperture(),
  46. .close_dir(),
  47. .close_dir_valid(),
  48. .fault(),
  49. .move_kind(),
  50. .remaining_steps(remaining_steps),
  51. .axis_state(),
  52. .jog_can_accept(),
  53. .standard_can_accept()
  54. );
  55. initial begin
  56. clk = 1'b0;
  57. forever #5 clk = ~clk;
  58. end
  59. task run_exact_jog;
  60. input [15:0] requested;
  61. begin
  62. @(negedge clk);
  63. jog_dir = ~jog_dir;
  64. jog_steps = requested;
  65. jog_start = 1'b1;
  66. @(posedge clk);
  67. #1;
  68. if (!busy || !drive_active || remaining_steps !== requested) begin
  69. $display("16-bit JOG load mismatch requested=%0d busy=%0d drive=%0d remaining=%0d",
  70. requested, busy, drive_active, remaining_steps);
  71. $fatal;
  72. end
  73. @(negedge clk);
  74. jog_start = 1'b0;
  75. guard = 0;
  76. rises = 0;
  77. previous_step = step_out;
  78. while ((busy || dut.terminal_pending) && guard < (requested * 4 + 32)) begin
  79. @(posedge clk);
  80. #1;
  81. if (!previous_step && step_out) rises = rises + 1;
  82. previous_step = step_out;
  83. guard = guard + 1;
  84. end
  85. if (busy || dut.terminal_pending || drive_active || step_out || rises != requested) begin
  86. $display("16-bit JOG count mismatch requested=%0d rises=%0d busy=%0d remaining=%0d",
  87. requested, rises, busy, remaining_steps);
  88. $fatal;
  89. end
  90. end
  91. endtask
  92. initial begin
  93. rst_n = 1'b0;
  94. jog_start = 1'b0;
  95. jog_dir = 1'b0;
  96. jog_steps = 16'd1;
  97. repeat (4) @(negedge clk);
  98. rst_n = 1'b1;
  99. run_exact_jog(16'd1);
  100. run_exact_jog(16'd160);
  101. run_exact_jog(16'd161);
  102. run_exact_jog(16'd8191);
  103. run_exact_jog(16'd8192);
  104. run_exact_jog(16'd65535);
  105. $display("PASS: prod2u_p4_axis_jog_16bit_tb");
  106. $finish;
  107. end
  108. endmodule