| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- `timescale 1ns/1ps
- module prod2u_p4_axis_jog_16bit_tb;
- reg clk;
- reg rst_n;
- reg jog_start;
- reg jog_dir;
- reg [15:0] jog_steps;
- wire step_out;
- wire busy;
- wire drive_active;
- wire [15:0] remaining_steps;
- integer guard;
- integer rises;
- reg previous_step;
- prod2u_p4_axis_executor #(
- .HAS_LIMIT(1),
- .STANDARD_STEPS(4),
- .DIR_SETUP_US(1),
- .SPEED0_HALF_US(1),
- .SPEED1_HALF_US(1),
- .SPEED2_HALF_US(1),
- .SPEED3_HALF_US(1)
- ) dut (
- .clk(clk),
- .rst_n(rst_n),
- .tick_1us(1'b1),
- .force_stop(1'b0),
- .limit_fast(1'b0),
- .limit_active(1'b0),
- .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(1'b0),
- .mark_close_dir(1'b0),
- .terminal_ready(1'b1),
- .step_out(step_out),
- .dir_out(),
- .busy(busy),
- .drive_active(drive_active),
- .position_valid(),
- .current_aperture(),
- .target_aperture(),
- .close_dir(),
- .close_dir_valid(),
- .fault(),
- .move_kind(),
- .remaining_steps(remaining_steps),
- .axis_state(),
- .jog_can_accept(),
- .standard_can_accept()
- );
- initial begin
- clk = 1'b0;
- forever #5 clk = ~clk;
- end
- task run_exact_jog;
- input [15:0] requested;
- begin
- @(negedge clk);
- jog_dir = ~jog_dir;
- jog_steps = requested;
- jog_start = 1'b1;
- @(posedge clk);
- #1;
- if (!busy || !drive_active || remaining_steps !== requested) begin
- $display("16-bit JOG load mismatch requested=%0d busy=%0d drive=%0d remaining=%0d",
- requested, busy, drive_active, remaining_steps);
- $fatal;
- end
- @(negedge clk);
- jog_start = 1'b0;
- guard = 0;
- rises = 0;
- previous_step = step_out;
- while ((busy || dut.terminal_pending) && guard < (requested * 4 + 32)) begin
- @(posedge clk);
- #1;
- if (!previous_step && step_out) rises = rises + 1;
- previous_step = step_out;
- guard = guard + 1;
- end
- if (busy || dut.terminal_pending || drive_active || step_out || rises != requested) begin
- $display("16-bit JOG count mismatch requested=%0d rises=%0d busy=%0d remaining=%0d",
- requested, rises, busy, remaining_steps);
- $fatal;
- end
- end
- endtask
- initial begin
- rst_n = 1'b0;
- jog_start = 1'b0;
- jog_dir = 1'b0;
- jog_steps = 16'd1;
- repeat (4) @(negedge clk);
- rst_n = 1'b1;
- run_exact_jog(16'd1);
- run_exact_jog(16'd160);
- run_exact_jog(16'd161);
- run_exact_jog(16'd8191);
- run_exact_jog(16'd8192);
- run_exact_jog(16'd65535);
- $display("PASS: prod2u_p4_axis_jog_16bit_tb");
- $finish;
- end
- endmodule
|