C741 of 57
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

C7 · Lesson 41 · Crossing clock domains

Synchronizers, handshakes and asynchronous FIFOs

Most chips run several clocks: a fast one for the core, slower ones for peripherals, another recovered from an incoming data stream. A signal passing from one clock's domain to another arrives at a moment the receiving flip-flops didn't plan for, and sometimes it violates their setup time. Lesson 27 showed that the flip-flop may then hang between 0 and 1. This lesson is about living with that: how many flip-flops make a synchronizer safe, why a multi-bit value can't be synchronized bit by bit, and how handshakes and FIFOs move data across safely.

Play

  • The curve is a synchronizer's mean time between failures, as a power of ten in seconds, against the time it gives a metastable flip-flop to resolve.
  • Each extra flip-flop adds a whole clock period of resolution time. Watch how far one period moves the curve.
  • Slower flip-flops (larger τ) need much more time for the same safety.

Predict

An 8-bit counter in one clock domain is read in another by passing each bit through its own two-flop synchronizer. The counter steps from 0111 1111 to 1000 0000 just as the receiver samples. What can the receiver see?

Name it

Synchronizers

A flip-flop sampling an asynchronous input becomes metastable now and then; given time tr to resolve, the mean time between failures is

MTBF=etr/τT0fclkfdata.

A two-flop synchronizer gives the first flip-flop a whole clock period, less setup, to resolve before the second samples it. Each extra stage adds another period, multiplying the MTBF by eT/τ, typically by a factor of 1013 or more.

Multi-bit values

Bits synchronized separately can disagree. Three safe ways across:

  • Gray-coded counters: one bit changes per step, so a sample is either the old or the new value (lesson 3).
  • Handshakes: the sender holds the data steady and raises a request; the request (one bit) is synchronized; the receiver reads the stable data and returns an acknowledge, synchronized back. A four-phase handshake (request up, acknowledge up, request down, acknowledge down) passes four synchronizations per word, about 4Tdst+4Tsrc.
  • Asynchronous FIFOs: a dual-port memory written in one domain and read in the other, with Gray-coded read and write pointers synchronized across to compute full and empty.

Sizing a FIFO

If the writer delivers bursts of B words at fw while the reader drains at a slower fr, the FIFO must absorb the difference:

depth≥B(1−frfw),

plus a few words for the pointers' synchronizer delay.

Pulses

A one-clock pulse from a fast domain can fall between a slow domain's edges and be missed. Convert it to a level change (a toggle), synchronize the level, and detect its edges on the other side.

Worked example

A 1 GHz design samples a 100 MHz asynchronous signal with flip-flops having τ = 30 ps, T0 = 50 ps and 50 ps of setup. Compare one flop whose output feeds 0.7 ns of logic, two flops, and three.

Show the solution
  1. One flop. It leaves only 1−0.05−0.7 = 0.25 ns to resolve: MTBF=e0.25/0.0350ps×109×108=0.8ms It fails about a thousand times a second.
  2. Two flops. The first gets a clean 0.95 ns: MTBF=e0.95/0.035×106=1.1×107s or 131 days.
  3. Three flops. They give 1.95 ns: about 1014 years.
  4. Compare. The second stage turns a broken design into a rare failure; the third makes failure practically impossible.

Answer about 0.8 ms with one flop, 131 days with two, and about 1014 years with three.

Worked example

A four-phase handshake passes words from a 100 MHz domain to a 50 MHz domain, with two-flop synchronizers both ways. About how many words per second can it move?

Show the solution
  1. Count the synchronizations. Each word needs four: request rising and falling into the 100 MHz side, and acknowledge rising and falling back into the 50 MHz side.
  2. Time each one. Each takes two clocks: 10 ns each on the 100 MHz side and 20 ns each on the 50 MHz side.
  3. Add them up. 4×10+4×20=120ns per word, roughly 8.3 million words a second.
  4. Compare. Safe and simple, but slow; bulk data uses a FIFO instead.

Answer roughly 8.3 million words a second.

Worked example

A writer at 100 MHz sends bursts of 120 words; a reader drains at 80 MHz. How deep must the FIFO be?

Show the solution
  1. Words drained during the burst. During the 1.2 µs burst the reader removes 1.2μs×80MHz=96 words, so 24 pile up.
  2. Minimum depth. depth≥120(1−80100)=24
  3. Add margin. A few more cover the synchronizer delay before the writer sees the read pointer move: 32 is a natural choice.
  4. Between bursts. The reader must have time to empty it, or it overflows on the next.

Answer at least 24 words; 32 is a natural choice.

Check

A synchronizer clocked with a 2 ns period uses flops with τ = 20 ps; each extra stage adds one period of resolution time.

(a)

By how many powers of ten does one extra stage multiply the MTBF?

(b)

By what factor, exactly?

Check

A writer at 100 MHz sends bursts of 200 words to a reader at 80 MHz.

(a)

What's the least FIFO depth, before margin?

(b)

How long does the reader take to empty that backlog after the burst?

Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.

Check

A four-phase handshake with two-flop synchronizers carries words from a 10 MHz domain to a 100 MHz domain. About how long does each word take?

Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.

Check

A 4-bit write pointer must be passed to another clock domain to compute "FIFO full". What's the safe way?

Check

A synchronizer gives resolution time t, with flops of time constant u and aperture T, at clock c and data rate d.

Step 1

What's its MTBF?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Check

Write fifo_depth(B, fw, fr, sync=2) returning the smallest power-of-two FIFO depth that holds a burst of B words written at fw while being read at fr, plus sync words of margin for the pointer synchronizers.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

Why can't a multi-bit value be passed between clock domains by synchronizing each bit separately?

Practice

Keep practicing

4 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.