Module 7: Advanced RTL Design Techniques · 7.5 Clock Domain Crossing

The Two-Flop Synchronizer as a Module

Module 5 and Section 7.4 implemented two-flop synchronizers as inline registers. This article formalizes the two-flop synchronizer as a standalone, parameterized library module. It also explains the synthesis attributes required to prevent automated compiler optimizations from degrading timing reliability.

Standard Two-Flop Synchronizer Implementation

`timescale 1ns / 1ps
`default_nettype none

module sync_2ff #(parameter WIDTH = 1) (
    input  wire             dest_clk,
    input  wire             dest_rst_n,
    input  wire [WIDTH-1:0] async_in,
    output wire [WIDTH-1:0] sync_out
);
    // Attribute instructs EDA tools to preserve synchronizer topology
    (* ASYNC_REG = "TRUE" *) reg [WIDTH-1:0] stage1, stage2;

    always @(posedge dest_clk or negedge dest_rst_n) begin
        if (!dest_rst_n) begin
            stage1 <= {WIDTH{1'b0}};
            stage2 <= {WIDTH{1'b0}};
        end else begin
            stage1 <= async_in;    // Stage 1: absorbs physical metastability
            stage2 <= stage1;      // Stage 2: clean output for destination logic
        end
    end

    assign sync_out = stage2;
endmodule

The parameter WIDTH configures bus width. While this module supports multi-bit vectors, passing raw binary vectors across clock boundaries remains unsafe. Use WIDTH > 1 only for Gray-coded vectors or static bus lines.

Critical Synthesis Attributes

The attribute (* ASYNC_REG = "TRUE" *) provides essential instructions to synthesis and physical placement engines:

  1. Prevents Register Retiming: Without this attribute, synthesis optimizers can merge or retime the two flip-flops. Retiming alters the available settling time, reducing physical MTBF.
  2. Constrains Physical Proximity: Place-and-route tools place the two flip-flops directly adjacent in silicon. Minimizing interconnect length maximizes available recovery time $t_r$.
  3. Suppresses Static Timing Warnings: Static Timing Analysis (STA) tools recognize that the input path originates from an asynchronous domain, suppressing false timing violation reports.

Vendor-specific toolchains provide equivalent attribute keywords. Xilinx Vivado uses ASYNC_REG. Intel Quartus uses synchronizer_identification. Always apply synchronizer attributes to prevent synthesis optimizations from invalidating timing assumptions.

Appropriate Operating Scenarios

Apply the two-flop synchronizer under specific conditions:

  • Single-bit control flags, such as interrupt requests, start strobes, or hardware enables.
  • Multi-bit Gray-coded FIFO pointers where exactly one bit transitions per update.
  • Static configuration registers that remain constant throughout operational execution.

Never pass dynamic, multi-bit binary data words through parallel two-flop synchronizers. While each bit resolves to valid binary states, differential interconnect delays cause bits to arrive on different clock edges. Transferring multi-bit data words requires formal handshake synchronizers or asynchronous FIFOs.

Verification Exercise

An external peripheral asserts an asynchronous, active-high interrupt request line (irq_request). Instantiate sync_2ff to synchronize this signal into a processor clock domain (proc_clk).

View Solution
wire irq_sync;

sync_2ff #(.WIDTH(1)) u_irq_sync (
    .dest_clk(proc_clk),
    .dest_rst_n(proc_rst_n),
    .async_in(irq_request),
    .sync_out(irq_sync)
);

Because irq_request is a single-bit signal, multi-bit coherence race conditions do not exist. The synchronized interrupt arrives safely in the proc_clk domain after two clock cycles of latency.

The two-flop synchronizer resolves single-bit metastability when configured with appropriate synthesis attributes. The next article explores four-phase handshake protocols for transferring arbitrary multi-bit data words across clock domains.

← Metastability and MTBF The Request/Acknowledge Handshake →