Clock Domain Crossing
Clock Distribution & Power Management · Hardware Foundations track
13 min read
In this module
The Boundary Problem
Lesson 1 showed that modern processors run multiple clock domains at different frequencies. When data has to hop from one domain to another (core to memory controller, between two cores with independent PLLs, I/O interface into the internal fabric) it crosses a clock domain boundary. That crossing is one of the most treacherous patches of ground in digital design, because the two clocks have no guaranteed phase or frequency relationship at all.
If the receiving clock samples the data right as it's changing, the result is metastability: the receiving flip-flop's output is neither a valid 0 nor a valid 1. The fuzzy state can propagate through downstream logic, producing unpredictable, intermittent failures that are a nightmare to reproduce or debug.
What Is Metastability?
A flip-flop is a bistable device: two stable states (0 and 1) separated by an unstable equilibrium point. Sample the input cleanly, well before or after a transition, and the flip-flop snaps to the correct state. Sample it during the transition, inside the setup and hold time window, and the internal feedback loop starts near the equilibrium point and may take arbitrarily long to resolve.
While metastable, the flip-flop's output voltage hangs near the threshold between 0 and 1. Downstream logic sees an in-between voltage. Some gates read it as 0, others as 1, and the circuit's behaviour fragments across the chip.
Metastable output voltage over time:
Vdd ────────────────────────────────────────── (logic 1) ┌──────────────── / /Vth ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─/─ ─ ─ ─ ─ ─ ─ ─ ─ (threshold) ~~~~~~~~~~~~~~~~GND ────── (logic 0) ^ ^ ^ Input Metastable Resolved sampled region to logic 1The probability of staying metastable falls off exponentially with time. Given enough time, the flip-flop always resolves. The real question is whether it resolves within the clock period you've got.
Every flip-flop has a setup time (minimum time the input must be stable before the clock edge) and a hold time (minimum time it must remain stable after the clock edge). When data crosses between unrelated clock domains, these timing requirements cannot be guaranteed, making metastability inevitable without proper synchronisation.
The Two-Flip-Flop Synchroniser
The standard defence against metastability is the two-flip-flop synchroniser (also called a double-flop synchroniser). The asynchronous input feeds the first flip-flop, whose output feeds the second, both clocked by the receiving domain's clock:
The first flip-flop may go metastable, sure, but it gets an entire clock period to settle before the second one samples it. The probability that it's still wobbly by then is tiny: a well-designed synchroniser lets a failure through once in years or centuries of continuous operation, as the MTBF section below works out.
The price of this safety is latency. The synchroniser adds two clock cycles of delay in the receiving domain. For a single-bit signal like a request or acknowledge flag, that's a fine tax to pay.
Mean Time Between Failures (MTBF)
A synchroniser's reliability is captured by its Mean Time Between Failures (MTBF), the average gap between metastability events that slip through and produce an error.
MTBF depends on:
- Clock frequency of the receiving domain (faster clocks, more sampling opportunities per second)
- Data transition rate (more transitions per second, more chances to land mid-edge)
- Resolution time constant (a property of the flip-flop technology, typically 20-50 ps in modern processes)
- Number of synchroniser stages (every extra stage multiplies MTBF exponentially)
The standard model ties them together:
MTBF = e^(t_r / tau) / (T0 x f_clk x f_data)Here t_r is the time the first flop gets to resolve (roughly one clock period minus the second flop's setup time and the first one's clock-to-output delay), tau is the resolution time constant, and T0 is a technology constant describing how wide the dangerous window around the clock edge is.
Plug in illustrative numbers: f_clk = 1 GHz, f_data = 100 MHz, t_r = 0.9 ns, tau = 25 ps, T0 = 50 ps. The exponent is 0.9 ns / 25 ps = 36, and e^36 is about 4.3 x 10^15. The denominator is 50 ps x 10^9 x 10^8 = 5 x 10^6 per second. MTBF comes out at about 8.6 x 10^8 seconds, roughly 27 years. Real values swing by orders of magnitude with tau, T0 and the clock rate, which is why the exponent matters so much: a third stage adds another 0.9 ns to t_r (one more clock period, less that stage's own delay and setup), the exponent becomes 72, and MTBF jumps to around 4 x 10^24 seconds. A two-stage synchroniser in a modern process typically lands somewhere between years and thousands of years at GHz rates; three stages push it into astronomical territory and earn their keep in safety-critical designs. And remember that a chip has many synchronisers, so the system MTBF is the single-synchroniser figure divided by how many there are.
The explorer below starts with those same numbers. First drag the data edge into the shaded window and creep it towards the dashed balance point: each tenfold step closer adds the same stretch of time, tau x ln 10, before the output picks a side. Then try three stages, or halve tau, and see how far the MTBF moves.
Metastability and the two-flop synchroniser
Move the data edge into the setup and hold window and watch the output stall near the threshold. The closer the edge gets to the balance point, the longer it takes to fall one way or the other.
Inside the window. Q hovers near Vth, then resolves to 0 after about 140 ps.
Across many random crossings, the share still unresolved after time t is e−t/tau: 37% after one tau, 0.67% after five, 0.0045% after ten.
Giving the first flop a clock period
- async data
- FF1
- FF2
- logic
Constants are illustrative: a 20 ps setup and 10 ps hold window, 30 ps clock-to-output, 100 ps lost per stage to clock-to-output and setup. MTBF = et_r/tau / (T0 × f_clk × f_data) follows the standard model in R. Ginosar, “Metastability and Synchronizers: A Tutorial”, IEEE Design & Test of Computers, 2011.
In safety-critical systems (aerospace, automotive, medical), designs may use three-stage synchronisers to push MTBF beyond the lifetime of the universe. You pay one extra cycle of latency for the privilege. Functional-safety standards such as ISO 26262 don't name a synchroniser MTBF, but they do set limits on random hardware failure rates for each Automotive Safety Integrity Level (ASIL), and metastability failures count towards that budget, which pushes automotive designs towards very large synchroniser MTBFs.
Synchronising Multi-Bit Signals
A two-flip-flop synchroniser handles single-bit signals just fine. But what about a multi-bit bus, like a 32-bit data word? You can't slap a synchroniser on each bit independently, because each bit might resolve in a different cycle, corrupting the word.
Picture a 4-bit value transitioning from 0111 to 1000. All four bits change simultaneously. If bit 3 is sampled in the new state while bits 2-0 catch the old state, the receiver sees 1111, a value that was never sent.
Handshake Protocols
For low-bandwidth multi-bit transfers, a handshake protocol turns the crossing into a serial back-and-forth:
- The sender drops data on the bus and asserts a
requestsignal. - The
requestcrosses the domain boundary through a two-flip-flop synchroniser. - The receiver sees the synchronised
request, samples the data bus (which by now has been stable for at least two receiving clock cycles), and asserts anacknowledge. - The
acknowledgerides back through another synchroniser to the sending domain. - The sender sees the
acknowledgeand knows it's safe to change the data for the next transfer.
Safe, but slow. In a four-phase handshake, REQ and ACK each have to rise and then fall again, so every transfer pays for four synchroniser crossings: roughly eight clock cycles before the next word can go. Fine for configuration registers, control signals, and infrequent transfers, useless for streaming data.
Asynchronous FIFOs
For high-bandwidth continuous data streams, the standard solution is an asynchronous FIFO: a dual-port memory with independent write and read clocks.
- The write side is clocked by the source domain. It writes data and advances the write pointer.
- The read side is clocked by the receiving domain. It reads data and advances the read pointer.
- The FIFO is full when the write pointer catches the read pointer from behind. It's empty when the read pointer catches the write pointer.
The hard part is figuring out full and empty status, because that means comparing pointers that live in different clock domains.
Gray Code Counters
The asynchronous FIFO's correctness rests on safely shipping the write pointer over to the read domain (to check empty) and the read pointer over to the write domain (to check full). These pointers are multi-bit values, so the obvious approach of synchronising each bit independently breaks for the reason just covered.
Gray code solves it. In a Gray code counter, exactly one bit changes per increment:
| Decimal | Binary | Gray Code |
|---|---|---|
| 0 | 0000 | 0000 |
| 1 | 0001 | 0001 |
| 2 | 0010 | 0011 |
| 3 | 0011 | 0010 |
| 4 | 0100 | 0110 |
| 5 | 0101 | 0111 |
| 6 | 0110 | 0101 |
| 7 | 0111 | 0100 |
Because only one bit changes per increment, running a Gray code pointer through a two-flip-flop synchroniser can only land on the old value or the new one. There's no garbage intermediate state to worry about. Sample during the single-bit transition and you resolve to the previous count or the current count, both legal.
Here's the 0111 to 1000 case from earlier with a little skew on the bus. Bit 0 lands first and bit 3 last, and the destination clock samples somewhere in between. Slide the sample point through the skew window and watch the binary column produce values like 0100 that were never sent, while the Gray count stays at zero whatever you do.
Sampling a counter across clock domains
A 4-bit counter steps once per source clock, but its bits arrive at slightly different times. The destination flop samples once per cycle and catches each bit as either old or new.
sampled 0100 = 4, never sent
sampled 0100 = 7, a value that was sent
Every sample over one wrap of the counter
| Step | Binary sent | Sampled | Gray sent | Sampled |
|---|---|---|---|---|
| 0→1 | 0000→0001 | 0001 (1) | 0000→0001 | 0001 (1) |
| 1→2 | 0001→0010 | 0010 (2) | 0001→0011 | 0011 (2) |
| 2→3 | 0010→0011 | 0011 (3) | 0011→0010 | 0010 (3) |
| 3→4 | 0011→0100 | 0000 (0) never sent | 0010→0110 | 0010 (3) |
| 4→5 | 0100→0101 | 0101 (5) | 0110→0111 | 0111 (5) |
| 5→6 | 0101→0110 | 0110 (6) | 0111→0101 | 0101 (6) |
| 6→7 | 0110→0111 | 0111 (7) | 0101→0100 | 0100 (7) |
| 7→8 | 0111→1000 | 0100 (4) never sent | 0100→1100 | 0100 (7) |
| 8→9 | 1000→1001 | 1001 (9) | 1100→1101 | 1101 (9) |
| 9→10 | 1001→1010 | 1010 (10) | 1101→1111 | 1111 (10) |
| 10→11 | 1010→1011 | 1011 (11) | 1111→1110 | 1110 (11) |
| 11→12 | 1011→1100 | 1000 (8) never sent | 1110→1010 | 1110 (11) |
| 12→13 | 1100→1101 | 1101 (13) | 1010→1011 | 1011 (13) |
| 13→14 | 1101→1110 | 1110 (14) | 1011→1001 | 1001 (14) |
| 14→15 | 1110→1111 | 1111 (15) | 1001→1000 | 1000 (15) |
| 15→0 | 1111→0000 | 1100 (12) never sent | 1000→0000 | 1000 (15) |
Both clocks run at the same rate here, so the sample lands at the same point in every cycle. In a real crossing the phase drifts and every point gets visited sooner or later. Bits are assumed to resolve cleanly; metastability is a separate problem that the synchroniser handles.
You can watch this happen in software. The sampler below models a synchroniser catching each changing bit as either its old or its new value, at random, then counts how often the receiver ends up with a value that was never sent. The second experiment shows the catch: plain Gray counting only works if the pointer wraps at a power of two, and the bits also have to arrive within one destination clock of each other, which in silicon means constraining the skew on that bus.
The FIFO carries Gray-coded write and read pointers:
- The write pointer (in Gray code) is synchronised into the read domain to compute the empty flag.
- The read pointer (in Gray code) is synchronised into the write domain to compute the full flag.
Gray code pointers ensure that when one clock domain reads another domain's pointer, the result is always a valid count (either the current value or the previous value). This may cause the FIFO to appear slightly more full or more empty than it actually is, but it never causes data corruption. A FIFO that appears full when it is not simply stalls the writer briefly - a safe, conservative error.
Depth and Latency
FIFO depth has to be large enough to absorb the rate difference between source and destination. If the source averages a higher data rate than the destination, the FIFO will overflow eventually no matter how deep it is. For bursty traffic, depth must cover the worst-case burst size.
Synchroniser latency (two to three cycles each way) leaves the full and empty flags slightly stale, reflecting pointer values from two or three cycles ago. So the FIFO may report "full" when one or two entries are actually free, or "empty" when there's one entry sitting there. This conservatism is intentional and safe.
Why CDC Bugs Are So Dangerous
CDC bugs sit at the very top of every hardware engineer's list of horrors, for several reasons:
Non-deterministic: Metastability failures depend on the exact phase relationship between two clocks, which shifts with temperature, voltage, and manufacturing variation. A design that's flawless on one chip may glitch intermittently on another.
Intermittent: A CDC bug might fire once in a billion clock cycles. It sails through every simulation (which runs for millions of cycles at most) and only surfaces after weeks or months of field operation.
Hard to observe: When a metastability event corrupts a pointer or control signal, the symptom shows up far downstream and much later. Tracing it back to the source is brutal.
Simulation can't catch them: Standard RTL simulation pretends clock edges are ideal and doesn't model metastability at all. Even gate-level simulation with timing annotations can miss CDC issues if the problematic phase alignment never happens during the simulation window.
Since simulation can't reliably find CDC bugs, the industry leans on specialised CDC verification tools (Synopsys CDC Compiler, Cadence Conformal CDC, Siemens Questa CDC). They perform structural analysis of the RTL, identifying every signal that crosses a domain boundary and checking that it routes through a proper synchronisation structure. Any unsynchronised crossing gets flagged as a violation. CDC verification is a mandatory sign-off step in modern chip design flows.
Real-World CDC Architectures
Clock-Crossing Bridges
Many SoC (System-on-Chip) architectures park standardised clock-crossing bridge blocks at domain boundaries. The bridge wraps asynchronous FIFOs, synchronisers, and handshake logic into one verified IP block. Once the bridge is proven correct, designers wire clock domains into it and stop worrying about the gory details.
ARM's AXI protocol bakes in provisions for clock domain crossings, and standard bridge IP exists for AXI, AHB, and APB interfaces.
Quasi-Synchronous Crossings
When two clocks come from the same PLL but at different divider ratios (4 GHz and 2 GHz, say), they're quasi-synchronous. Their edges have a known, fixed relationship. Simpler synchronisation schemes work here because the designer knows precisely when the edges align. Even so, PLL jitter can shift edges relative to each other, so quasi-synchronous crossings still demand care.
Globally Asynchronous, Locally Synchronous (GALS)
The GALS paradigm carves the chip into synchronous islands, each with its own clock generator, joined by asynchronous communication channels. Every island runs at whatever frequency suits its workload, no global clock required. GALS sidesteps the headache of distributing one clock across a large die, but it makes every inter-island communication a CDC problem in its own right. Some network-on-chip architectures take this route.
Clock domain crossing isn't glamorous, but it's foundational. Every modern processor, SoC, and FPGA design carries dozens or hundreds of domain crossings. Getting even one wrong can produce a chip that passes every test and fails unpredictably in the field. That's why CDC verification ranks among the highest-priority checks in the design flow.