|
|
@@ -29,7 +29,8 @@ module door_planner_grant_once_tb;
|
|
|
|
|
|
door_motion_controller #(
|
|
|
.MAX_CAL_STEPS(32), .MIN_TRAVEL(2),
|
|
|
- .ENDPOINT_GUARD_EXTRA(8), .DIR_SETUP_TICKS(1), .PERCENT_MAX(100)
|
|
|
+ .ENDPOINT_GUARD_EXTRA(8), .DIR_SETUP_TICKS(1), .PERCENT_MAX(100),
|
|
|
+ .MOTION_SERVICE_CLKS(4), .PHASE_FACTOR(64), .CAL_RAMP_UNIT(2)
|
|
|
) dut (
|
|
|
.clk(clk), .rst_n(rst_n),
|
|
|
.tick_500us(tick_500us),
|
|
|
@@ -62,39 +63,79 @@ module door_planner_grant_once_tb;
|
|
|
end
|
|
|
endtask
|
|
|
|
|
|
- task force_rise;
|
|
|
- input [2:0] mask;
|
|
|
+ task force_rise_ax;
|
|
|
+ input integer ax;
|
|
|
+ reg [2:0] m;
|
|
|
begin
|
|
|
+ m = 3'b001 << ax;
|
|
|
@(negedge clk);
|
|
|
- gated_step = mask; gated_step_rise = mask;
|
|
|
+ gated_step = gated_step | m; gated_step_rise = m;
|
|
|
@(negedge clk);
|
|
|
- gated_step_rise = 3'b000; gated_step = 3'b000;
|
|
|
+ gated_step_rise = 3'b000; gated_step = gated_step & ~m;
|
|
|
+ end
|
|
|
+ endtask
|
|
|
+
|
|
|
+ task wait_step_ax;
|
|
|
+ input integer ax;
|
|
|
+ input want;
|
|
|
+ integer t;
|
|
|
+ begin
|
|
|
+ for (t = 0; t < 20000; t = t + 1) begin
|
|
|
+ if (step[ax] === want) disable wait_step_ax;
|
|
|
+ @(negedge clk);
|
|
|
+ end
|
|
|
+ $fatal(1, "timeout step[%0d]==%0d", ax, want);
|
|
|
+ end
|
|
|
+ endtask
|
|
|
+
|
|
|
+ task cal_axis;
|
|
|
+ input integer ax;
|
|
|
+ input integer travel;
|
|
|
+ integer r;
|
|
|
+ begin
|
|
|
+ close_limit[ax] = 1'b1;
|
|
|
+ open_limit[ax] = 1'b0;
|
|
|
+ repeat (6) pulse_tick();
|
|
|
+ for (r = 0; r < travel; r = r + 1) begin
|
|
|
+ wait_step_ax(ax, 1);
|
|
|
+ force_rise_ax(ax);
|
|
|
+ wait_step_ax(ax, 0);
|
|
|
+ end
|
|
|
+ @(negedge clk);
|
|
|
+ open_limit[ax] = 1'b1;
|
|
|
+ close_limit[ax] = 1'b0;
|
|
|
+ begin : w
|
|
|
+ integer t;
|
|
|
+ for (t = 0; t < 8000; t = t + 1) begin
|
|
|
+ if (calibrated_mask[ax]) disable w;
|
|
|
+ @(negedge clk);
|
|
|
+ end
|
|
|
+ end
|
|
|
+ if (!calibrated_mask[ax]) $fatal(1, "cal fail ax=%0d", ax);
|
|
|
end
|
|
|
endtask
|
|
|
|
|
|
integer i;
|
|
|
|
|
|
initial begin
|
|
|
- #500000 $fatal(1, "door_planner_grant_once_tb timeout");
|
|
|
+ #5_000_000 $fatal(1, "door_planner_grant_once_tb timeout");
|
|
|
end
|
|
|
|
|
|
initial begin
|
|
|
starts_x = 0; starts_y = 0; starts_z = 0;
|
|
|
+ open_limit = 3'b000;
|
|
|
+ close_limit = 3'b000;
|
|
|
repeat (2) @(posedge clk);
|
|
|
rst_n = 1'b1;
|
|
|
@(negedge clk);
|
|
|
limit_sync_valid = 1'b1;
|
|
|
- repeat (4) pulse_tick();
|
|
|
- for (i = 0; i < 3; i = i + 1) begin
|
|
|
- force_rise(3'b111);
|
|
|
- pulse_tick();
|
|
|
+ cal_axis(0, 4);
|
|
|
+ cal_axis(1, 4);
|
|
|
+ cal_axis(2, 4);
|
|
|
+ begin : ws
|
|
|
+ integer t;
|
|
|
+ for (t = 0; t < 8000 && !startup_complete; t = t + 1) @(negedge clk);
|
|
|
end
|
|
|
- @(negedge clk);
|
|
|
- open_limit = 3'b111; close_limit = 3'b000;
|
|
|
- gated_step = 3'b111; gated_step_rise = 3'b111;
|
|
|
- @(negedge clk);
|
|
|
- gated_step = 3'b000; gated_step_rise = 3'b000;
|
|
|
- repeat (8) @(negedge clk);
|
|
|
if (!startup_complete) $fatal(1, "no startup");
|
|
|
|
|
|
open_limit = 3'b000;
|