Two-Flop Synchronizer
A signal from another clock domain can change right at your clock edge and leave the first flip-flop metastable. A second flip-flop gives it a full cycle to settle before any logic looks at it. Every CDC path starts with this circuit.
The module accepts an asynchronous input vector and passes it through two cascaded registers clocked by the destination domain clock. The first register captures the asynchronous input, and the second register captures the output of the first. This provides a stable synchronized output exactly two clock cycles after the input stabilizes.
Clocking is driven by clk on the positive edge. The module uses an asynchronous, active-low reset rst_n. On reset, all internal registers and the output evaluate to 0. No combinational logic is permitted between the asynchronous input and the first stage, nor between the first and second stages.
Cycle 1: rst_n=0 → stage1=0, sync_out=0
Cycle 2: rst_n=1, async_in=1 → stage1=0, sync_out=0 (input transitions)
Cycle 3: async_in=1 → stage1=1, sync_out=0 (stage1 captures input)
Cycle 4: async_in=1 → stage1=1, sync_out=1 (sync_out captures stage1)
Cycle 5: async_in=1 → stage1=1, sync_out=1 (steady state)
Cycle 6: async_in=0 → stage1=1, sync_out=1 (input transitions)
Cycle 7: async_in=0 → stage1=0, sync_out=1 (stage1 captures input)
Cycle 8: async_in=0 → stage1=0, sync_out=0 (sync_out captures stage1)
| Signal | Direction | Width | Description |
|---|---|---|---|
clk |
input | 1 | Positive-edge triggered destination clock |
rst_n |
input | 1 | Asynchronous active-low reset; all outputs and internal states go to 0 when asserted |
async_in |
input | WIDTH |
Asynchronous input data vector |
sync_out |
output | WIDTH |
Synchronized output data vector |
Constraints
- Parameter
WIDTHmust define the bit width of the input and output ports. - Reset must be asynchronous and active-low.
- All output and internal register bits must evaluate to 0 on reset.
- No combinational logic is allowed; the module must exclusively infer cascaded flip-flops.
- The output
sync_outmust reflect the capturedasync_inexactly two clock cycles later.
Topics
Solve this problem
Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.
Free to solve. A Codiode account keeps your progress.
The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.