// pulse_sync.sv // Toggle-based pulse synchroniser. A one-cycle pulse in clk_src becomes a // one-cycle pulse in clk_dst. // // Rule: pulses in the source domain must be spaced far enough apart that the // destination sees every toggle. Keep at least 3 destination clock periods // between source pulses (two synchroniser flops plus the edge detector). // If the source can send faster than that, use a handshake or a FIFO. `timescale 1ns/1ps module pulse_sync ( input logic clk_src, input logic rst_src, // synchronous reset, source domain input logic pulse_src, // one-cycle pulse in clk_src input logic clk_dst, input logic rst_dst, // synchronous reset, destination domain output logic pulse_dst // one-cycle pulse in clk_dst ); // Source domain: convert each pulse into a level change. logic toggle_src; always_ff @(posedge clk_src) begin if (rst_src) begin toggle_src <= 1'b0; end else if (pulse_src) begin toggle_src <= ~toggle_src; end end // Destination domain: two-flop synchroniser, then one more flop for edge detection. (* ASYNC_REG = "TRUE" *) logic [1:0] sync_ff; logic toggle_dst_d; always_ff @(posedge clk_dst) begin if (rst_dst) begin sync_ff <= 2'b00; toggle_dst_d <= 1'b0; end else begin sync_ff <= {sync_ff[0], toggle_src}; toggle_dst_d <= sync_ff[1]; end end // Any change of the synchronised toggle is one event. assign pulse_dst = sync_ff[1] ^ toggle_dst_d; endmodule