Two-flop CDC synchronizer

Sample a sustained one-bit level with two flip-flops on the destination clock and trace the synchronization latency. Compare the needs of short pulses and multi-bit words, and state what the digital waveform shows and what physical evidence is needed to assess metastability risk.

A second clock domain needs to know whether a sensor is enabled. This is one bit that stays at its new level. The source transition has no fixed timing relationship to the receiver’s rising edge.

Both stages use the destination clock. Stage two samples the previous stage-one value.
Both stages use the destination clock. Stage two samples the previous stage-one value.

The RTL

Both registers use the destination clock. The first samples the source; the second samples the previous first-stage Q. If a transition near the sampling edge leaves the first stage metastable, the interval between stages gives it time to settle. Downstream logic uses only stage two.

module level_sync(
    input logic clk_dst,
    input logic rst_n,
    input logic src_level,
    output logic stage1,
    output logic sync_level
);
always_ff @(posedge clk_dst) begin
        if (!rst_n) begin
            stage1 <= 1'b0;
            sync_level <= 1'b0;
        end else begin
            stage1 <= src_level;
            sync_level <= stage1;
        end
    end
endmodule

Trace the outputs

Sample reset at 5 ns. The source rises at 10 ns and stays high. At the 15 ns destination edge stage one becomes 1 while stage two stays 0. The synchronized output rises at 25 ns. A different source phase changes the wait for the first sampling edge.

Recorded simulation. Dashed lines mark rising edges; bus values are hexadecimal. Open the figure to enlarge it.
Recorded simulation. Dashed lines mark rising edges; bus values are hexadecimal. Open the figure to enlarge it.
Rising edgeInputs (hex)Observed after edge (hex)
E0rst_n=0, src_level=0stage1=0, sync_level=0
E1rst_n=1, src_level=1stage1=1, sync_level=0
E2rst_n=1, src_level=1stage1=1, sync_level=1
E3rst_n=1, src_level=0stage1=0, sync_level=1
E4rst_n=1, src_level=0stage1=0, sync_level=0

Design choices

A short pulse entirely between sampling edges may go unseen. Synchronizing each bit of a bus independently can mix words. Events and payloads need a suitable transfer protocol. Metastability risk requires cell parameters, clock and toggle rates, and physical timing evidence.

Yosys synth_ice40 mapped this module to the following cell counts: SB_DFFSR: 2, SB_LUT4: 1. The download records the tool versions and the commands to reproduce this mapping.

Interactive lab

Reset both stages on a destination edge. Release reset and raise src_level. Advance edges one at a time. Then try raising and lowering the source between two edges.

stage1
sync_level
Show the last eight observations

    Teaching film

    Read the transcript

    Run the RTL yourself

    Extract the lab and follow the commands in its README. Compare the simulated outputs and waveform with your predictions from the interactive lab.

    Download Two-flop CDC synchronizer RTL (.zip)

    Check your understanding

    1. Which clock drives both stages?
    2. Both stages were low. Stage one first captures 1 at 15 ns. What is sync_level just after that edge?
    3. Is a pulse entirely between two sampling edges always observed?
    4. Do separate two-stage synchronizers guarantee a coherent bus word?
    5. Does a functional waveform quantify metastability risk?