| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- `timescale 1ns/1ps
- // Scheme A2: three parallel narrow DDA datapaths (one add/compare/sub each).
- // On each motion_service_ce, all active axes update in one clock.
- // Rise permission is enforced in the axis STEP toggle helper; this datapath
- // always wraps when active so high pulses can still drain (!allow_rise).
- // busy is always 0 after the single service cycle (1-cycle datapath).
- // service_overrun stays 0: next service cannot overlap a multi-cycle busy.
- module door_shared_dda_scheduler #(
- parameter integer PHASE_WIDTH = 26,
- parameter integer RATE_WIDTH = 21,
- parameter integer THRESH_WIDTH = 25,
- parameter integer CAL_PHASE_THRESHOLD = 5120
- ) (
- input wire clk,
- input wire rst_n,
- input wire service_ce,
- input wire [2:0] active,
- input wire [2:0] allow_toggle,
- input wire [2:0] cal_mode,
- input wire [RATE_WIDTH-1:0] rate0,
- input wire [RATE_WIDTH-1:0] rate1,
- input wire [RATE_WIDTH-1:0] rate2,
- input wire [THRESH_WIDTH-1:0] phase_threshold,
- output reg [2:0] toggle_pulse,
- output reg busy,
- output wire service_overrun
- );
- reg [PHASE_WIDTH-1:0] phase0, phase1, phase2;
- assign service_overrun = 1'b0;
- wire _unused_allow = |allow_toggle;
- wire [PHASE_WIDTH-1:0] thr_run =
- {{(PHASE_WIDTH-THRESH_WIDTH){1'b0}}, phase_threshold};
- wire [PHASE_WIDTH-1:0] thr_cal = CAL_PHASE_THRESHOLD[PHASE_WIDTH-1:0];
- always @(posedge clk or negedge rst_n) begin
- if (!rst_n) begin
- phase0 <= {PHASE_WIDTH{1'b0}};
- phase1 <= {PHASE_WIDTH{1'b0}};
- phase2 <= {PHASE_WIDTH{1'b0}};
- toggle_pulse <= 3'b000;
- busy <= 1'b0;
- end else begin
- toggle_pulse <= 3'b000;
- busy <= 1'b0;
- if (service_ce) begin
- begin : par
- reg [PHASE_WIDTH-1:0] t0, t1, t2;
- reg [PHASE_WIDTH-1:0] s0, s1, s2;
- t0 = cal_mode[0] ? thr_cal : thr_run;
- t1 = cal_mode[1] ? thr_cal : thr_run;
- t2 = cal_mode[2] ? thr_cal : thr_run;
- if (active[0]) begin
- s0 = phase0 + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate0};
- if (s0 >= t0) begin
- toggle_pulse[0] <= 1'b1;
- phase0 <= s0 - t0;
- end else begin
- phase0 <= s0;
- end
- end else begin
- phase0 <= {PHASE_WIDTH{1'b0}};
- end
- if (active[1]) begin
- s1 = phase1 + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate1};
- if (s1 >= t1) begin
- toggle_pulse[1] <= 1'b1;
- phase1 <= s1 - t1;
- end else begin
- phase1 <= s1;
- end
- end else begin
- phase1 <= {PHASE_WIDTH{1'b0}};
- end
- if (active[2]) begin
- s2 = phase2 + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate2};
- if (s2 >= t2) begin
- toggle_pulse[2] <= 1'b1;
- phase2 <= s2 - t2;
- end else begin
- phase2 <= s2;
- end
- end else begin
- phase2 <= {PHASE_WIDTH{1'b0}};
- end
- end
- end
- end
- end
- endmodule
|