prod2u_p4_axis_saturated_jog_tb.v 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. `timescale 1ns/1ps
  2. module prod2u_p4_axis_saturated_jog_tb;
  3. localparam [2:0] AXIS_CLOSED = 3'd1;
  4. localparam [2:0] AXIS_INTERMEDIATE = 3'd5;
  5. reg clk = 1'b0;
  6. reg rst_n = 1'b0;
  7. reg limit_fast = 1'b0;
  8. reg limit_active = 1'b0;
  9. reg jog_start = 1'b0;
  10. reg jog_dir = 1'b0;
  11. reg [15:0] jog_steps = 16'd4;
  12. reg mark_closed = 1'b0;
  13. reg mark_close_dir = 1'b0;
  14. wire step_out;
  15. wire dir_out;
  16. wire busy;
  17. wire drive_active;
  18. wire close_dir_valid;
  19. wire [2:0] axis_state;
  20. wire jog_can_accept;
  21. integer guard;
  22. always #5 clk = ~clk;
  23. prod2u_p4_axis_executor #(
  24. .HAS_LIMIT(1), .STANDARD_STEPS(8), .RECOVERY_STEPS(4),
  25. .LIMIT_CONFIRM_US(4), .DIR_SETUP_US(1),
  26. .SPEED0_HALF_US(2), .SPEED1_HALF_US(2),
  27. .SPEED2_HALF_US(2), .SPEED3_HALF_US(2)
  28. ) dut (
  29. .clk(clk), .rst_n(rst_n), .tick_1us(1'b1), .force_stop(1'b0),
  30. .limit_fast(limit_fast), .limit_active(limit_active),
  31. .jog_start(jog_start), .jog_dir(jog_dir), .jog_speed_code(2'd3),
  32. .jog_steps(jog_steps), .standard_start(1'b0), .standard_target_open(1'b0),
  33. .mark_closed(mark_closed), .mark_close_dir(mark_close_dir),
  34. .terminal_ready(1'b1),
  35. .step_out(step_out), .dir_out(dir_out), .busy(busy),
  36. .drive_active(drive_active), .position_valid(), .current_aperture(),
  37. .target_aperture(), .close_dir(), .close_dir_valid(close_dir_valid),
  38. .fault(), .move_kind(), .remaining_steps(), .axis_state(axis_state),
  39. .jog_can_accept(jog_can_accept), .standard_can_accept()
  40. );
  41. task pulse_mark;
  42. begin
  43. @(negedge clk);
  44. mark_closed = 1'b1;
  45. @(posedge clk);
  46. #1;
  47. @(negedge clk);
  48. mark_closed = 1'b0;
  49. end
  50. endtask
  51. task pulse_jog;
  52. input direction;
  53. begin
  54. @(negedge clk);
  55. jog_dir = direction;
  56. jog_start = 1'b1;
  57. @(posedge clk);
  58. #1;
  59. @(negedge clk);
  60. jog_start = 1'b0;
  61. end
  62. endtask
  63. initial begin
  64. repeat (4) @(negedge clk);
  65. rst_n = 1'b1;
  66. @(negedge clk);
  67. limit_fast = 1'b0;
  68. limit_active = 1'b0;
  69. dut.g_limited_axis.u_limited.close_dir = 1'b0;
  70. dut.g_limited_axis.u_limited.close_dir_valid = 1'b1;
  71. dut.g_limited_axis.u_limited.axis_state = AXIS_INTERMEDIATE;
  72. dut.g_limited_axis.u_limited.distance_valid = 1'b1;
  73. dut.g_limited_axis.u_limited.distance_steps = 16'hffff;
  74. dut.g_limited_axis.u_limited.distance_saturated = 1'b1;
  75. jog_dir = 1'b1;
  76. #1;
  77. if (jog_can_accept) begin
  78. $display("saturated axis exposed away-direction JOG acceptance");
  79. $fatal;
  80. end
  81. pulse_jog(1'b1);
  82. repeat (4) @(posedge clk);
  83. if (busy || drive_active || step_out || axis_state !== AXIS_INTERMEDIATE) begin
  84. $display("rejected saturated away-JOG changed motion state");
  85. $fatal;
  86. end
  87. jog_dir = 1'b0;
  88. #1;
  89. if (!jog_can_accept) begin
  90. $display("saturated axis rejected supervised close-direction JOG");
  91. $fatal;
  92. end
  93. pulse_jog(1'b0);
  94. guard = 0;
  95. while (!step_out && guard < 30) begin
  96. @(posedge clk);
  97. #1;
  98. guard = guard + 1;
  99. end
  100. if (!step_out || dir_out !== 1'b0) begin
  101. $display("close-direction recovery JOG did not move toward LS");
  102. $fatal;
  103. end
  104. limit_fast = 1'b1;
  105. repeat (2) @(posedge clk);
  106. limit_active = 1'b1;
  107. guard = 0;
  108. while (busy && guard < 80) begin
  109. @(posedge clk);
  110. #1;
  111. guard = guard + 1;
  112. end
  113. if (busy || drive_active || step_out || axis_state !== AXIS_CLOSED ||
  114. dut.g_limited_axis.u_limited.distance_saturated) begin
  115. $display("close-direction saturated JOG did not re-establish CLOSED");
  116. $fatal;
  117. end
  118. $display("PASS: prod2u_p4_axis_saturated_jog_tb");
  119. $finish;
  120. end
  121. endmodule