3.4.14 · D4Sequential Circuits

Exercises — Clock domain crossing

3,026 words14 min readBack to topic

Before we begin, one figure fixes the picture of why crossing is dangerous — glance at it whenever a problem says "the signal is unrelated to the clock".

Figure — Clock domain crossing

The burnt-orange input can flip at any moment. The teal clock edge only samples at its tick. When a flip happens inside the shaded setup/hold window around the edge, the flop is told "capture" while the value is still moving — that is the birth of metastability.


Level 1 — Recognition

(Can you name the pieces and read a formula?)

Recall Solution L1.1
  • The time before the edge is the setup time : the data must already be stable this long before the clock ticks.
  • The time after the edge is the hold time : the data must stay stable this long after the tick.

Together they form the "danger window". If the input changes anywhere inside it, the flop's capture is ambiguous → metastability. See these two times as the width of the shaded band in the figure above.

Recall Solution L1.2
Symbol Meaning Larger → MTBF?
settling time we allow before using the value better (it's in the exponent, upstairs)
regeneration time constant of the flop worse (bigger shrinks the exponent )
measured metastability aperture / prefactor worse (downstairs)
sampling clock frequency worse (downstairs — sample more often, more chances to catch a bad edge)
rate of async input changes worse (downstairs — more transitions to catch)

The single most powerful knob is because it sits inside the exponential.

Recall Solution L1.3
  • (a) single strobe → two-flop synchronizer (one bit, safe to sync directly).
  • (b) counter/pointer → Gray code (only one bit changes per step, so a metastable bit still yields a valid off-by-one value).
  • (c) arbitrary 32-bit word → handshake or asynchronous FIFO (many bits change at once; never sync each bit independently).

Level 2 — Application

(Plug numbers into the formulas correctly.)

Recall Solution L2.1

First the clock period: . Why and ? FF1's resolved value only shows up after its clock-to-Q delay, which lengthens the window; but FF2 must have stable data one setup time before its own next edge, which shortens it. Net: .

Recall Solution L2.2

Exponent: Denominator:

=\frac{1.40\times10^{22}}{2\times10^{3}}\approx 7.0\times10^{18}\ \text{s}.$$ That's about $2\times10^{11}$ years — vastly longer than the age of the universe. One extra flop already made this near-perfect.
Recall Solution L2.3

Only changed, and only inside the exponent. The improvement factor is

= e^{(t_{s,new}-t_{s,old})/\tau} = e^{(10.1-5.1)\text{ns}/100\text{ps}} = e^{5\text{ns}/100\text{ps}} = e^{50}.$$ $e^{50}\approx 5.18\times10^{21}$ — a twenty-one-order-of-magnitude jump for one extra flop. **Lesson:** reliability multiplies exponentially with each added stage.

Level 3 — Analysis

(Compare choices; explain why one is right and another is a trap.)

Recall Solution L3.1

In binary , all four bits flip at once. Each bit's synchronizer resolves after an independent, random delay, so on the sampling edge some bits may show the new value and others the old:

  • Suppose bit3 resolves fast (new = 1) but bits 2,1,0 lag (old = 111).
  • Receiver reads — a value the counter never produced (it went 7 → 8).

This is data incoherence. The fix is Gray code: re-encode the count so that exactly one bit changes per step. In 4-bit Gray code, the number 7 is and 8 is — they differ in only the top bit. So the step is the single flip . Now even if that one bit goes metastable, the receiver reads either (old = 7) or (new = 8) — both real counts, off by at most one.

Recall Solution L3.2
  • (A) adds depth → more → exponentially better MTBF. This directly attacks the physics (more time to resolve).
  • (B) width just moves more data per cycle. It does nothing to , , or the probability any single bit is metastable — and worse, syncing multiple bits invites the incoherence of L3.1.

Metastability is a time problem, not a bandwidth problem. Depth (time) helps; width does not.

Recall Solution L3.3

Denominator Set MTBF s:

t_s = 29.7\times100\text{ ps}\approx 2.97\text{ ns}.$$ So once the settling window falls below **≈ 3 ns**, this design risks a failure within a year — a signal that you need a deeper synchronizer or a slower clock.

Level 4 — Synthesis

(Assemble a working subsystem from the pieces.)

Recall Solution L4.1

Use a 4-phase handshake (Handshake protocols):

  1. A places the 16-bit word on the bus and holds it steady. A raises req.
  2. req (1 bit) is passed through a two-flop synchronizer into domain B.
  3. B sees synchronized req, and because the data bus has been stable for ≥ 2 clkB cycles, B safely latches the 16 data bits directly (no per-bit synchronizer needed — they are not changing).
  4. B raises ack; ack (1 bit) is passed through a two-flop synchronizer back to A.
  5. A sees synchronized ack, drops req, is free to change the data. B drops ack.

Crossing with synchronizers: only the two 1-bit control signals req and ack. Crossing without synchronizers: the 16 data wires — they are held constant across the handshake, sampled only when known stable. This sidesteps incoherence entirely.

The figure below draws this exact sequence as a timeline — trace the three annotated steps.

Figure — Clock domain crossing

Read the timeline top to bottom: the burnt-orange data bus stays flat (held steady) across the whole exchange; the teal req rises first and is synchronized into B; the plum ack rises only after B has safely latched the stable data. The data line never moves while either control signal is being sampled — that is the whole safety argument, made visual.

Recall Solution L4.2

Per-word latency .

\approx 1.67\times10^{7}\ \text{words/s}.$$ ≈ **16.7 million words/s**. This is the price of handshaking: safe but latency-bound. When you need far more throughput, move to an [[Asynchronous FIFO design|asynchronous FIFO]], which pipelines many words with Gray-coded pointers instead of one-at-a-time handshakes.

Level 5 — Mastery

(Invent, justify, and defend the tricky choices.)

Recall Solution L5.1

The full/empty flags come from comparing the crossed write pointer against the local read pointer. Correctness needs the crossed pointer to always be a value the counter genuinely held.

Binary pointer — the failure, step by step. Suppose the true write pointer advances , i.e. binary (all four bits flip). The synchronizer bits resolve on independent random delays, so on one sampling edge domain B may capture, say, (bit3 new, rest old) — a phantom pointer the writer never held.

  • Say the read pointer is at . The true occupancy is (empty).
  • But the comparator sees write , read , and computes occupancy — it declares the FIFO 7 entries full when it is actually empty.
  • Downstream logic trusting "7 available" would read 7 stale/garbage entries (an under-run), or in the symmetric case a phantom low value hides real entries and the writer overruns and clobbers unread data. Either way: corrupted data from a pointer value that never existed.

Gray pointer — why it is safe. Re-encode so exactly one bit changes per increment (e.g. becomes Gray , a single top-bit flip). A metastable bit can then only yield the old pointer (=7) or the new one (=8) — both are real counts. The comparator may lag by exactly one, reporting the FIFO slightly more full than it is, which is conservative: it can stall a write briefly but never overruns and never under-runs.

So Gray coding converts a catastrophic incoherence into a harmless, conservative one-step lag. That safety margin is the whole reason async FIFOs use it.

Recall Solution L5.2

Target in seconds: s. Denominator

=2.95\times10^{21}.$$ $$\frac{t_s}{\tau}\ge\ln(2.95\times10^{21})\approx 49.4 \Rightarrow t_s\ge 49.4\times80\text{ ps}\approx 3.95\text{ ns}.$$ Clock period $T_{clk}=1/(250\text{ MHz})=4\text{ ns}$. Since $t_s$ per stage $=4$ ns and we need $\ge 3.95$ ns, **one full extra period suffices → a standard 2-flop synchronizer** ($t_s=4\text{ ns}$) meets the target. No third flop required.

Recall Quick self-test (click to reveal)

The exponent in MTBF is which ratio? ::: (settling time over regeneration constant) Which technique guarantees at most a one-step, conservative error on a crossed counter? ::: Gray code In a handshake, which wires get synchronizers? ::: only the 1-bit control signals req and ack Adding one flop multiplies MTBF by roughly what? ::: Can any synchronizer make metastability impossible? ::: No — only exponentially improbable