|
|
@@ -100,6 +100,8 @@ module door_axis_controller #(
|
|
|
reg wd_stopped;
|
|
|
reg open_limit_armed;
|
|
|
reg close_limit_armed;
|
|
|
+ // Cached L*unit for O(1) S-curve climb/drop (avoids 15-iter combo unroll).
|
|
|
+ reg [CNT_W-1:0] profile_level_thresh;
|
|
|
|
|
|
assign calibrated = calibrated_r;
|
|
|
assign faulted = (status_state == ST_FAULT);
|
|
|
@@ -124,32 +126,8 @@ module door_axis_controller #(
|
|
|
// DDA only while producing/consuming half-cycles; DIR_SETUP clears phase via !active.
|
|
|
assign axis_dda_run = (phase == PH_RUN) || (phase == PH_DRAIN_HIGH);
|
|
|
|
|
|
- // level = min(15, floor(done/unit), floor((remaining-1)/unit)) via repeated add (no divider).
|
|
|
- function automatic [3:0] f_profile_level;
|
|
|
- input [CNT_W-1:0] done_i;
|
|
|
- input [CNT_W-1:0] remaining_i;
|
|
|
- input [CNT_W-1:0] unit_i;
|
|
|
- integer L;
|
|
|
- reg [CNT_W-1:0] thresh;
|
|
|
- reg [CNT_W-1:0] rem_term_limit;
|
|
|
- reg [3:0] best;
|
|
|
- begin
|
|
|
- best = 4'd0;
|
|
|
- if (unit_i == {CNT_W{1'b0}}) begin
|
|
|
- f_profile_level = 4'd0;
|
|
|
- end else begin
|
|
|
- rem_term_limit = (remaining_i < {{(CNT_W-1){1'b0}}, 1'b1}) ?
|
|
|
- {CNT_W{1'b0}} : (remaining_i - {{(CNT_W-1){1'b0}}, 1'b1});
|
|
|
- thresh = {CNT_W{1'b0}};
|
|
|
- for (L = 1; L <= 15; L = L + 1) begin
|
|
|
- thresh = thresh + unit_i;
|
|
|
- if ((done_i >= thresh) && (rem_term_limit >= thresh))
|
|
|
- best = L[3:0];
|
|
|
- end
|
|
|
- f_profile_level = best;
|
|
|
- end
|
|
|
- end
|
|
|
- endfunction
|
|
|
+ // Incremental level matching min(15, floor(done/u), floor((rem-1)/u)).
|
|
|
+ // One add/compare per rise (no 15-iter combinational scan).
|
|
|
|
|
|
function automatic [CNT_W-1:0] f_ramp_unit;
|
|
|
input [CNT_W-1:0] distance_i;
|
|
|
@@ -282,6 +260,7 @@ module door_axis_controller #(
|
|
|
open_limit_armed <= 1'b1;
|
|
|
close_limit_armed <= 1'b1;
|
|
|
profile_level <= 4'd0;
|
|
|
+ profile_level_thresh <= {CNT_W{1'b0}};
|
|
|
profile_distance <= {CNT_W{1'b0}};
|
|
|
profile_done_steps <= {CNT_W{1'b0}};
|
|
|
profile_ramp_unit <= {{(CNT_W-1){1'b0}}, 1'b1};
|
|
|
@@ -337,14 +316,33 @@ module door_axis_controller #(
|
|
|
begin : sc_rise
|
|
|
reg [CNT_W-1:0] done_n;
|
|
|
reg [CNT_W-1:0] rem_n;
|
|
|
+ reg [CNT_W-1:0] rem_term;
|
|
|
+ reg [CNT_W-1:0] next_thr;
|
|
|
done_n = profile_done_steps + 1'b1;
|
|
|
rem_n = (profile_distance > done_n) ?
|
|
|
(profile_distance - done_n) : {CNT_W{1'b0}};
|
|
|
+ rem_term = (rem_n < {{(CNT_W-1){1'b0}}, 1'b1}) ?
|
|
|
+ {CNT_W{1'b0}} : (rem_n - {{(CNT_W-1){1'b0}}, 1'b1});
|
|
|
profile_done_steps <= done_n;
|
|
|
- profile_level <= f_profile_level(done_n, rem_n, profile_ramp_unit);
|
|
|
+ if (profile_ramp_unit == {CNT_W{1'b0}}) begin
|
|
|
+ profile_level <= 4'd0;
|
|
|
+ profile_level_thresh <= {CNT_W{1'b0}};
|
|
|
+ end else if ((profile_level != 4'd0) &&
|
|
|
+ (rem_term < profile_level_thresh)) begin
|
|
|
+ profile_level <= profile_level - 4'd1;
|
|
|
+ profile_level_thresh <=
|
|
|
+ profile_level_thresh - profile_ramp_unit;
|
|
|
+ end else if (profile_level < 4'd15) begin
|
|
|
+ next_thr = profile_level_thresh + profile_ramp_unit;
|
|
|
+ if ((done_n >= next_thr) && (rem_term >= next_thr)) begin
|
|
|
+ profile_level <= profile_level + 4'd1;
|
|
|
+ profile_level_thresh <= next_thr;
|
|
|
+ end
|
|
|
+ end
|
|
|
end
|
|
|
end else if (moving && endpoint_mode) begin
|
|
|
profile_level <= 4'd0;
|
|
|
+ profile_level_thresh <= {CNT_W{1'b0}};
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
@@ -447,7 +445,9 @@ module door_axis_controller #(
|
|
|
profile_distance <= dist_n;
|
|
|
profile_ramp_unit <= unit_n;
|
|
|
profile_done_steps <= {CNT_W{1'b0}};
|
|
|
- profile_level <= f_profile_level({CNT_W{1'b0}}, dist_n, unit_n);
|
|
|
+ // done==0 ⇒ level 0 (same as prior full scan).
|
|
|
+ profile_level <= 4'd0;
|
|
|
+ profile_level_thresh <= {CNT_W{1'b0}};
|
|
|
end
|
|
|
if (planner_result == effective_current_position) begin
|
|
|
status_state <= ST_IDLE;
|
|
|
@@ -479,6 +479,7 @@ module door_axis_controller #(
|
|
|
phase <= PH_DIR_SETUP;
|
|
|
moving <= 1'b1;
|
|
|
profile_level <= 4'd0;
|
|
|
+ profile_level_thresh <= {CNT_W{1'b0}};
|
|
|
profile_done_steps <= {CNT_W{1'b0}};
|
|
|
profile_distance <= {CNT_W{1'b0}};
|
|
|
profile_ramp_unit <= CAL_RAMP_UNIT[CNT_W-1:0];
|
|
|
@@ -506,6 +507,7 @@ module door_axis_controller #(
|
|
|
moving <= 1'b1;
|
|
|
// Rebuild soft-start for measure-open (no S decelerate claimed).
|
|
|
profile_level <= 4'd0;
|
|
|
+ profile_level_thresh <= {CNT_W{1'b0}};
|
|
|
profile_done_steps <= {CNT_W{1'b0}};
|
|
|
status_state <= ST_CAL_MEASURE_OPEN;
|
|
|
end else if (stop_after_budget && !gated_step && !step) begin
|
|
|
@@ -649,6 +651,7 @@ module door_axis_controller #(
|
|
|
need_planner <= 1'b0;
|
|
|
planner_req <= 1'b0;
|
|
|
profile_level <= 4'd0;
|
|
|
+ profile_level_thresh <= {CNT_W{1'b0}};
|
|
|
profile_done_steps <= {CNT_W{1'b0}};
|
|
|
if (open_limit) begin
|
|
|
current_position <= {CNT_W{1'b0}};
|
|
|
@@ -674,6 +677,7 @@ module door_axis_controller #(
|
|
|
need_planner <= 1'b0;
|
|
|
planner_req <= 1'b0;
|
|
|
profile_level <= 4'd0;
|
|
|
+ profile_level_thresh <= {CNT_W{1'b0}};
|
|
|
profile_done_steps <= {CNT_W{1'b0}};
|
|
|
if (close_limit) begin
|
|
|
current_position <= travel_steps;
|