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?
Almost anything: all eight bits change, and each synchronizer independently catches its bit before or after the change. The receiver might see 0000 0000, 1111 1111 or any mix. Synchronizers make each bit a clean 0 or 1, but they can't make several bits agree. If the counter counted in Gray code, only one bit would change per step, and the receiver would see either the old value or the new one.
Name it
Synchronizers
A flip-flop sampling an asynchronous input becomes metastable now and then; given time to resolve, the mean time between failures is
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 , typically by a factor of 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 .
- 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 while the reader drains at a slower , the FIFO must absorb the difference:
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, = 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
- One flop. It leaves only = 0.25 ns to resolve: It fails about a thousand times a second.
- Two flops. The first gets a clean 0.95 ns: or 131 days.
- Three flops. They give 1.95 ns: about years.
- 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 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
- 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.
- Time each one. Each takes two clocks: 10 ns each on the 100 MHz side and 20 ns each on the 50 MHz side.
- Add them up. per word, roughly 8.3 million words a second.
- 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
- Words drained during the burst. During the 1.2 µs burst the reader removes words, so 24 pile up.
- Minimum depth.
- Add margin. A few more cover the synchronizer delay before the writer sees the read pointer move: 32 is a natural choice.
- 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°.
Step 2
What's it with one more stage (one more clock period of resolution)?
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?
A synchronizer only guarantees that its output settles to a clean 0 or 1; when the input changes near the sampling edge, it may resolve to either the old or the new value. With several bits changing at once, each synchronizer makes that choice independently, so some bits may show the old value and others the new, producing a combination that was never sent. The fix is to make sure only one bit can change at a time, as Gray code does, or to hold the data steady and synchronize just a single control signal that says when it's valid, as a handshake does.
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.