door_parallel_dda_scheduler_a2.v 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. `timescale 1ns/1ps
  2. // Scheme A2: three parallel narrow DDA datapaths (one add/compare/sub each).
  3. // On each motion_service_ce, all active axes update in one clock.
  4. // Rise permission is enforced in the axis STEP toggle helper; this datapath
  5. // always wraps when active so high pulses can still drain (!allow_rise).
  6. // busy is always 0 after the single service cycle (1-cycle datapath).
  7. // service_overrun stays 0: next service cannot overlap a multi-cycle busy.
  8. module door_shared_dda_scheduler #(
  9. parameter integer PHASE_WIDTH = 26,
  10. parameter integer RATE_WIDTH = 21,
  11. parameter integer THRESH_WIDTH = 25,
  12. parameter integer CAL_PHASE_THRESHOLD = 5120
  13. ) (
  14. input wire clk,
  15. input wire rst_n,
  16. input wire service_ce,
  17. input wire [2:0] active,
  18. input wire [2:0] allow_toggle,
  19. input wire [2:0] cal_mode,
  20. input wire [RATE_WIDTH-1:0] rate0,
  21. input wire [RATE_WIDTH-1:0] rate1,
  22. input wire [RATE_WIDTH-1:0] rate2,
  23. input wire [THRESH_WIDTH-1:0] phase_threshold,
  24. output reg [2:0] toggle_pulse,
  25. output reg busy,
  26. output wire service_overrun
  27. );
  28. reg [PHASE_WIDTH-1:0] phase0, phase1, phase2;
  29. assign service_overrun = 1'b0;
  30. wire _unused_allow = |allow_toggle;
  31. wire [PHASE_WIDTH-1:0] thr_run =
  32. {{(PHASE_WIDTH-THRESH_WIDTH){1'b0}}, phase_threshold};
  33. wire [PHASE_WIDTH-1:0] thr_cal = CAL_PHASE_THRESHOLD[PHASE_WIDTH-1:0];
  34. always @(posedge clk or negedge rst_n) begin
  35. if (!rst_n) begin
  36. phase0 <= {PHASE_WIDTH{1'b0}};
  37. phase1 <= {PHASE_WIDTH{1'b0}};
  38. phase2 <= {PHASE_WIDTH{1'b0}};
  39. toggle_pulse <= 3'b000;
  40. busy <= 1'b0;
  41. end else begin
  42. toggle_pulse <= 3'b000;
  43. busy <= 1'b0;
  44. if (service_ce) begin
  45. begin : par
  46. reg [PHASE_WIDTH-1:0] t0, t1, t2;
  47. reg [PHASE_WIDTH-1:0] s0, s1, s2;
  48. t0 = cal_mode[0] ? thr_cal : thr_run;
  49. t1 = cal_mode[1] ? thr_cal : thr_run;
  50. t2 = cal_mode[2] ? thr_cal : thr_run;
  51. if (active[0]) begin
  52. s0 = phase0 + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate0};
  53. if (s0 >= t0) begin
  54. toggle_pulse[0] <= 1'b1;
  55. phase0 <= s0 - t0;
  56. end else begin
  57. phase0 <= s0;
  58. end
  59. end else begin
  60. phase0 <= {PHASE_WIDTH{1'b0}};
  61. end
  62. if (active[1]) begin
  63. s1 = phase1 + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate1};
  64. if (s1 >= t1) begin
  65. toggle_pulse[1] <= 1'b1;
  66. phase1 <= s1 - t1;
  67. end else begin
  68. phase1 <= s1;
  69. end
  70. end else begin
  71. phase1 <= {PHASE_WIDTH{1'b0}};
  72. end
  73. if (active[2]) begin
  74. s2 = phase2 + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate2};
  75. if (s2 >= t2) begin
  76. toggle_pulse[2] <= 1'b1;
  77. phase2 <= s2 - t2;
  78. end else begin
  79. phase2 <= s2;
  80. end
  81. end else begin
  82. phase2 <= {PHASE_WIDTH{1'b0}};
  83. end
  84. end
  85. end
  86. end
  87. end
  88. endmodule