| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- `timescale 1ns/1ps
- module prod2u_p4_axis_saturated_jog_tb;
- localparam [2:0] AXIS_CLOSED = 3'd1;
- localparam [2:0] AXIS_INTERMEDIATE = 3'd5;
- reg clk = 1'b0;
- reg rst_n = 1'b0;
- reg limit_fast = 1'b0;
- reg limit_active = 1'b0;
- reg jog_start = 1'b0;
- reg jog_dir = 1'b0;
- reg [15:0] jog_steps = 16'd4;
- reg mark_closed = 1'b0;
- reg mark_close_dir = 1'b0;
- wire step_out;
- wire dir_out;
- wire busy;
- wire drive_active;
- wire close_dir_valid;
- wire [2:0] axis_state;
- wire jog_can_accept;
- integer guard;
- always #5 clk = ~clk;
- prod2u_p4_axis_executor #(
- .HAS_LIMIT(1), .STANDARD_STEPS(8), .RECOVERY_STEPS(4),
- .LIMIT_CONFIRM_US(4), .DIR_SETUP_US(1),
- .SPEED0_HALF_US(2), .SPEED1_HALF_US(2),
- .SPEED2_HALF_US(2), .SPEED3_HALF_US(2)
- ) dut (
- .clk(clk), .rst_n(rst_n), .tick_1us(1'b1), .force_stop(1'b0),
- .limit_fast(limit_fast), .limit_active(limit_active),
- .jog_start(jog_start), .jog_dir(jog_dir), .jog_speed_code(2'd3),
- .jog_steps(jog_steps), .standard_start(1'b0), .standard_target_open(1'b0),
- .mark_closed(mark_closed), .mark_close_dir(mark_close_dir),
- .terminal_ready(1'b1),
- .step_out(step_out), .dir_out(dir_out), .busy(busy),
- .drive_active(drive_active), .position_valid(), .current_aperture(),
- .target_aperture(), .close_dir(), .close_dir_valid(close_dir_valid),
- .fault(), .move_kind(), .remaining_steps(), .axis_state(axis_state),
- .jog_can_accept(jog_can_accept), .standard_can_accept()
- );
- task pulse_mark;
- begin
- @(negedge clk);
- mark_closed = 1'b1;
- @(posedge clk);
- #1;
- @(negedge clk);
- mark_closed = 1'b0;
- end
- endtask
- task pulse_jog;
- input direction;
- begin
- @(negedge clk);
- jog_dir = direction;
- jog_start = 1'b1;
- @(posedge clk);
- #1;
- @(negedge clk);
- jog_start = 1'b0;
- end
- endtask
- initial begin
- repeat (4) @(negedge clk);
- rst_n = 1'b1;
- @(negedge clk);
- limit_fast = 1'b0;
- limit_active = 1'b0;
- dut.g_limited_axis.u_limited.close_dir = 1'b0;
- dut.g_limited_axis.u_limited.close_dir_valid = 1'b1;
- dut.g_limited_axis.u_limited.axis_state = AXIS_INTERMEDIATE;
- dut.g_limited_axis.u_limited.distance_valid = 1'b1;
- dut.g_limited_axis.u_limited.distance_steps = 16'hffff;
- dut.g_limited_axis.u_limited.distance_saturated = 1'b1;
- jog_dir = 1'b1;
- #1;
- if (jog_can_accept) begin
- $display("saturated axis exposed away-direction JOG acceptance");
- $fatal;
- end
- pulse_jog(1'b1);
- repeat (4) @(posedge clk);
- if (busy || drive_active || step_out || axis_state !== AXIS_INTERMEDIATE) begin
- $display("rejected saturated away-JOG changed motion state");
- $fatal;
- end
- jog_dir = 1'b0;
- #1;
- if (!jog_can_accept) begin
- $display("saturated axis rejected supervised close-direction JOG");
- $fatal;
- end
- pulse_jog(1'b0);
- guard = 0;
- while (!step_out && guard < 30) begin
- @(posedge clk);
- #1;
- guard = guard + 1;
- end
- if (!step_out || dir_out !== 1'b0) begin
- $display("close-direction recovery JOG did not move toward LS");
- $fatal;
- end
- limit_fast = 1'b1;
- repeat (2) @(posedge clk);
- limit_active = 1'b1;
- guard = 0;
- while (busy && guard < 80) begin
- @(posedge clk);
- #1;
- guard = guard + 1;
- end
- if (busy || drive_active || step_out || axis_state !== AXIS_CLOSED ||
- dut.g_limited_axis.u_limited.distance_saturated) begin
- $display("close-direction saturated JOG did not re-establish CLOSED");
- $fatal;
- end
- $display("PASS: prod2u_p4_axis_saturated_jog_tb");
- $finish;
- end
- endmodule
|