// sync_2ff.sv // Two-flop synchroniser for a single-bit level signal that crosses into clk. // Use it only for one bit. Multi-bit values need a Gray code, a handshake or a FIFO. // // Vivado: ASYNC_REG keeps both flops close together and marks them as a synchroniser. // Quartus: add this assignment to the .qsf file instead (or use an altera_attribute): // set_instance_assignment -name SYNCHRONIZER_IDENTIFICATION "FORCED IF ASYNCHRONOUS" -to "*sync_meta" `timescale 1ns/1ps module sync_2ff #( parameter logic RESET_VALUE = 1'b0 ) ( input logic clk, // destination clock input logic rst, // synchronous reset, destination domain input logic d_async, // signal from another clock domain output logic q // synchronised copy, two clk cycles later ); (* ASYNC_REG = "TRUE" *) logic sync_meta; // first stage: may go metastable (* ASYNC_REG = "TRUE" *) logic sync_q; // second stage: safe to use always_ff @(posedge clk) begin if (rst) begin sync_meta <= RESET_VALUE; sync_q <= RESET_VALUE; end else begin sync_meta <= d_async; sync_q <= sync_meta; end end assign q = sync_q; endmodule