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.
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.
| Rising edge | Inputs (hex) | Observed after edge (hex) |
|---|---|---|
| E0 | rst_n=0, src_level=0 | stage1=0, sync_level=0 |
| E1 | rst_n=1, src_level=1 | stage1=1, sync_level=0 |
| E2 | rst_n=1, src_level=1 | stage1=1, sync_level=1 |
| E3 | rst_n=1, src_level=0 | stage1=0, sync_level=1 |
| E4 | rst_n=1, src_level=0 | stage1=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
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)