Explaining two-flip-flop synchronizer and MTBF
A two-flip-flop synchronizer uses two D flip-flops in series clocked by the destination clock to reduce metastability from asynchronous inputs. The first flip-flop may become metastable if the input violates setup/hold times, but the second flip-flop provides time for the signal to resolve, greatly reducing metastability risk. The MTBF formula quantifies the average time between failures as MTBF ≈ (1/(fclk * fdata)) * exp((Tres - Th)/τ), where Tres is the resolution time, Th is hold time, τ is a device-specific constant, and fclk and fdata are clock and data frequencies. A single flip-flop is insufficient because it can pass unresolved metastability directly into the receiving logic, while the second stage filters and stabilizes the signal.
When you have a signal that is not synchronous to the clock domain you want to sample it in, there is a non‑zero probability that it will transition within the setup/hold aperture of the sampling flip–flop. In that case the internal nodes of the latch can hang in an analog “between 0 and 1” state for some time before resolving. That metastable behaviour is what causes sporadic failures in clock–domain crossings.
A simple and widely‑used way to reduce the risk is to sample the asynchronous input through two flip‑flops clocked by the destination clock:
+--------+ +--------+
async_in ──►| D Q |───►| D Q |───► sync_out
| FF1 | | FF2 |
clk ───► | clk ─► |
+--------+ +--------+
Both flip‑flops are clocked by the destination domain. The first stage isolates the asynchronous input; the second stage only ever sees the first stage’s output and therefore only toggles on clock edges, never in the middle of a cycle.
The likelihood of a metastable event propagating all the way to sync_out is quantified by the mean time between failures (MTBF). A common form of the MTBF expression is
MTBF ≈ 1 / (fclk · fdata) · e^(Tresolve / τ)
where (f_\text{clk}) is the destination clock frequency, (f_\text{data}) is the rate at which the asynchronous input can change, (T_\text{resolve}) is the time allowed for a metastable node to settle, and τ is a device‑dependent time constant that characterises how quickly the internal nodes move away from the metastable point. The exponential term reflects the fact that the probability of still being metastable decays rapidly with time.
With only a single flip‑flop, any metastability created by a bad timing of the asynchronous transition can appear directly on its Q output and feed the rest of your logic. Downstream gates can interpret a marginal voltage as either a 0 or a 1, or even oscillate, leading to unpredictable behaviour.
By inserting a second, identical flip‑flop, you give the first stage a full clock period (T_\text{clk}) to resolve before its state is sampled again. In other words, (T_\text{resolve}) is approximately one clock cycle. That extra resolving time pushes the MTBF up by orders of magnitude. In the very rare case that the first flip‑flop is still metastable at the next active edge, the second stage can itself go metastable, but the probability of both events aligning is extremely low. In the overwhelming majority of cases the second stage sees a clean logic‑0 or logic‑1 level and produces a synchronous, glitch‑free version of the original signal.