D10 · Lesson 8 · Timing and clock domains
Why almost all digital design is synchronous, the setup and hold checks every register-to-register path must pass, slack and the maximum clock rate, metastability when a signal arrives from another clock domain, the two-flip-flop synchronizer and its mean time between failures, and safe ways to pass whole buses across
A synchronous design makes one promise: every flip-flop changes only at a clock edge, and every signal has a full clock period to settle before the next edge samples it. Keep that promise and a design with millions of gates behaves predictably, which is why static timing analysis can check it path by path. Break it, by letting a signal arrive from a different clock or from a button, and a flip-flop can be caught mid-change and hover between 0 and 1 for an unpredictable time. That state, metastability, can't be prevented, only made vanishingly rare.
- An asynchronous input A, changing with no relation to the clock, passes through two flip-flops: S1 samples it, S2 samples S1.
- In real hardware S1 may go metastable when A changes right at a clock edge; S2 gives it a whole clock period to resolve before anything uses it. The logic simulator here shows the ideal behavior: the two-cycle delay through the synchronizer.
- Everything downstream reads only S2, which is synchronous to the clock.
Predict
A synchronizer flip-flop has a resolution time constant τ = 50 ps. Compared with allowing 0.5 ns to resolve, how much does allowing 3 ns improve the mean time between failures?
The chance that a metastable flip-flop is still undecided after a time falls as , so the MTBF grows as : 2.5 ns more is 50 more time constants, a factor of = 5 × 10²¹. With a 250 MHz clock and data changing a million times a second, 0.5 ns gives a failure every 0.09 s; 3 ns, about once in 10¹³ years.
Name it
Setup and hold
For every path from one flip-flop to the next:
- setup: the data must arrive a setup time before the next edge: , giving the maximum clock rate. Slack is the period minus the required time; negative slack fails.
- hold: the data must not change until a hold time after the edge: , independent of the clock rate, and fixed by adding delay to short paths.
Clock skew, the difference in when the edge reaches the two flip-flops, eats into one check or the other. Static timing analysis checks every path against both.
Metastability
A flip-flop whose input changes inside its setup-and-hold window may hang between 0 and 1 before resolving. The mean time between failures of a synchronizer allowing a time to resolve is
with device constants τ and (around 50 ps and 1 ns in modern processes).
Crossing clock domains
- A single bit crosses through a two-flip-flop synchronizer, which gives the first flip-flop a whole period to resolve.
- A multi-bit value can't be synchronized bit by bit, since its bits could be caught in different cycles. Use a Gray-coded counter (only one bit changes at a time), a handshake that holds the data steady while a synchronized flag crosses, or an asynchronous FIFO (S3).
Worked example
A path has 0.3 ns clock-to-output, 3.2 ns of logic and 0.2 ns setup. What's its maximum clock, and its slack at 250 MHz?
Show the solution
- Path delay.
- Maximum clock.
- Slack at 250 MHz. The period is 4.0 ns:
Answer a maximum clock of 270 MHz, and 0.3 ns of slack at 250 MHz.
Worked example
A flip-flop with 0.1 ns clock-to-output feeds another through a 0.05 ns wire. The receiving flip-flop needs 0.2 ns of hold. Does it pass?
Show the solution
- When the data changes. after the edge.
- Compare with the hold window. The data changes before the 0.2 ns hold window closes: a hold violation of 0.05 ns.
- The fix. Add delay to the path, since slowing the clock doesn't help hold.
Answer it fails, with a hold violation of 0.05 ns.
Worked example
A single flip-flop synchronizes a 1 MHz signal into a 100 MHz domain with only 0.5 ns to settle. With τ = 50 ps and = 0.1 ns, what is its MTBF?
Show the solution
- Settling time in time constants.
- MTBF. It fails every couple of seconds.
- A second flip-flop. It adds a whole 10 ns period of settling, multiplying the MTBF by effectively never.
Answer an MTBF of 2.2 s, a failure every couple of seconds; a second flip-flop multiplies it by .
Check
A path has 0.1 ns clock-to-output, 1.5 ns of logic and 0.2 ns of setup time. What's the fastest clock it allows?
Write units the way you normally would: 1.5 MHz, 1500 kHz and 0.0015 GHz are the same answer.
Check
A 200 MHz design has a path with 0.2 ns clock-to-output, 3.5 ns of logic and 0.15 ns setup. What's its setup slack?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
Check
A synchronizer with τ = 50 ps and = 1 ns allows 2 ns to resolve, on a 100 MHz clock with data changing 10 million times a second. What's its MTBF?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
Check
A flip-flop with 0.1 ns clock-to-output feeds another through 0.03 ns of logic, and the second needs 0.25 ns of hold. What's the hold slack?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
Check
A path has 0.2 ns clock-to-output, 2 ns of logic and 0.3 ns of setup, clocked at 200 MHz.
(a)
What is its maximum clock?
Write units the way you normally would: 1.5 MHz, 1500 kHz and 0.0015 GHz are the same answer.
(b)
What is its slack at 200 MHz?
Check
A synchronizer has τ = 50 ps and = 0.1 ns, with 0.5 ns to settle, on a 100 MHz clock sampling data that changes 10 million times a second.
(a)
What is its MTBF?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
(b)
By how many powers of ten does a second flip-flop, adding 10 ns of settling, raise it?
Explain why
Why can't a multi-bit counter value be passed between clock domains through a synchronizer on each bit?
When a binary counter increments, several bits can change at once, for example from 0111 to 1000. A receiving clock edge that arrives while those bits are changing may catch some of them old and some new, and each bit's synchronizer resolves independently, so the receiver can see a value such as 1111 or 0000 that the counter never held. Synchronizing each bit guarantees each bit is clean, but not that they're consistent with each other. Gray-coding the counter, so only one bit changes per step, means any capture is either the old value or the new one, and a handshake or FIFO can hold whole words steady while a single synchronized flag crosses.
Practice
Keep practicing
8 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.