prod2u_runtime_step_limit_gate.v 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. `timescale 1ns/1ps
  2. // Production selected-limit hard gate: immediate truncate + hold until engine low.
  3. // Formal and sim must instantiate this module (not a hand-copied shell).
  4. module prod2u_runtime_step_limit_gate #(
  5. parameter integer AXIS_COUNT = 3
  6. ) (
  7. input wire clk,
  8. input wire rst_n,
  9. input wire [AXIS_COUNT-1:0] engine_step,
  10. input wire [AXIS_COUNT-1:0] engine_dir,
  11. input wire [AXIS_COUNT-1:0] close_limit,
  12. input wire [AXIS_COUNT-1:0] open_limit,
  13. output wire [AXIS_COUNT-1:0] selected_limit,
  14. output wire [AXIS_COUNT-1:0] gated_step
  15. );
  16. reg [AXIS_COUNT-1:0] gate_hold;
  17. genvar gi;
  18. generate
  19. for (gi = 0; gi < AXIS_COUNT; gi = gi + 1) begin : gen_gate
  20. assign selected_limit[gi] =
  21. engine_dir[gi] ? close_limit[gi] : open_limit[gi];
  22. assign gated_step[gi] =
  23. engine_step[gi] & ~selected_limit[gi] & ~gate_hold[gi];
  24. end
  25. endgenerate
  26. integer ai;
  27. always @(posedge clk or negedge rst_n) begin
  28. if (!rst_n) begin
  29. gate_hold <= {AXIS_COUNT{1'b0}};
  30. end else begin
  31. for (ai = 0; ai < AXIS_COUNT; ai = ai + 1) begin
  32. if (!engine_step[ai])
  33. gate_hold[ai] <= 1'b0;
  34. else if (selected_limit[ai])
  35. gate_hold[ai] <= 1'b1;
  36. end
  37. end
  38. end
  39. endmodule