Skip to content
Tutorials Center
My learning

Topics

Lesson 33 of 57 ยท Latches and Flip-Flops

Timing, Clock Skew and Metastability

Calculate maximum clock frequency from propagation delays, see how clock skew affects setup and hold, and learn how synchronizers tame metastability.

On paper a flip-flop copies D to Q at the clock edge, instantly. In silicon, nothing is instant. Signals take time to travel through gates and wires, clocks arrive at different flip-flops at slightly different moments, and the outside world never agrees to change its signals only when your clock wants it to. Whether a circuit works at 100 MHz or 1 GHz, and whether it works at all, is decided by timing.

This lesson turns the setup and hold rules into arithmetic. You will calculate the maximum clock frequency of a path, see how clock skew helps one check and hurts the other, and learn what happens when an asynchronous input lands in the forbidden window: metastability, and the two-flip-flop synchronizer that makes it rare enough to ignore.

Delays you need to know

Every number below is a property of a real part, taken from a datasheet or a timing report:

  • Propagation delay (t_pd): time from an input change to the output change of a gate or a block of logic. The maximum value matters for speed; the minimum (the contamination delay, t_cd) matters for hold.
  • Clock-to-Q delay (t_cq): time from the active clock edge until the flip-flop output is valid.
  • Setup time (t_su): how long D must be stable before the next edge.
  • Hold time (t_h): how long D must stay stable after the edge.

Picture the most common situation in synchronous design: flip-flop A drives some combinational logic, which feeds flip-flop B. Both share a clock.

flowchart LR
    A["Flip-flop A<br/>launches data"] -->|"logic delay"| L["Combinational<br/>logic"]
    L --> B["Flip-flop B<br/>captures data"]
    CLK["CLK"] --> A
    CLK --> B

Data leaves A at one edge and must arrive at B before the next edge.

The two timing checks

Setup check Slowest path must arrive before the next edge, minus setup.
Hold check Fastest path must not arrive before the hold window ends.

Setup depends on the clock period. Hold does not.

1 / 2

The setup check and maximum frequency

Data launched by A at edge 0 has to reach B before the next edge arrives one clock period T later, and early enough to meet B's setup time:

T โ‰ฅ t_cq + t_logic(max) + t_su + t_skew

The right-hand side is the minimum clock period T_min, and the maximum clock frequency is f_max = 1 / T_min. The path with the largest total, the critical path, sets the speed of the whole circuit. Speeding up any other path does not help; shortening the critical path does.

The skew term (more on it below) is zero when both flip-flops see the clock at the same time. The calculator below finds the critical path among several paths and reports T_min, f_max and the slack at a target frequency. Slack is how much time is left over: positive slack passes, negative slack fails.

Python Maximum clock frequency calculator

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The multiplier stage is the critical path: its total is 0.45 + 2.40 + 0.25 = 3.10 ns, which limits the whole circuit to about 322.6 MHz. At a 350 MHz target (a 2.86 ns period) only that path fails. To go faster, the designer shortens it, for example by splitting the multiplier into two stages with a register in between. That technique is called pipelining.

Splitting a path with a register trades clock frequency for latency. The result takes an extra cycle to appear, but a new input can enter every cycle at a much higher clock rate.

The hold check

Hold violations are the other side of the coin. Immediately after the clock edge, B's input must stay the same for t_h. But A's output starts changing after the same edge, t_cq later, and then races through the fastest possible logic. If that fastest path is too quick, the new value arrives at B before B has finished capturing the old one:

t_cq(min) + t_cd(logic, min) โ‰ฅ t_h + t_skew

Notice that the clock period does not appear. A hold violation cannot be fixed by slowing the clock. It is fixed by adding delay to the short path (insert buffers) or by reducing skew. This is why hold problems are dangerous: a chip with a hold bug fails at every frequency.

Clock skew

In a real chip the clock wire has different lengths to different flip-flops, so the clock edge arrives at B a little earlier or later than at A. That difference is clock skew. Define it as skew = (capture clock arrival) - (launch clock arrival).

  • Positive skew (B's clock is later): data has extra time, so the setup check gets easier (T + skew on the left), but the hold check gets harder, because B holds its capture window open longer.
  • Negative skew (B's clock is earlier): the setup check gets harder and the hold check easier.
Python Skew sweep: setup slack against hold slack

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The table shows a safe window: the path works when the skew is between about -0.20 ns and +0.35 ns. Skew beyond either edge violates one check. The last three lines show that stretching the clock period leaves the hold slack unchanged at -0.15 ns, which is exactly why hold bugs cannot be cured by running slower.

Metastability

A flip-flop is a bistable circuit: it has two stable states, like a ball resting in either of two valleys. Between them lies a hill. If D changes inside the setup and hold window, the internal latch may be pushed close to the top of the hill. It then sits there for a random amount of time before it falls into one of the valleys. This in-between condition is metastability. During it, Q can sit at an invalid mid-level voltage, wobble, or arrive late.

You cannot design metastability away for an input that is truly asynchronous (a button, a signal from another clock domain), because such an input will, sooner or later, change at just the wrong moment. What you can do is make the probability of an unresolved state reaching the rest of the circuit so low that it will not happen within the lifetime of the product.

The probability that a metastable event has not resolved after time t_r falls off exponentially. The standard formula for the mean time between failures is:

MTBF = e^(t_r / ฯ„) / (T_0 ยท f_clk ยท f_data)

ฯ„ is a time constant of the flip-flop (tens of picoseconds in modern processes), T_0 is the width of its vulnerable window, f_clk the sampling clock and f_data the rate at which the asynchronous input changes. The important part is e^(t_r / ฯ„): every bit of extra resolution time multiplies the MTBF by an enormous factor.

The two-flip-flop synchronizer

The standard cure is to feed the asynchronous input into two flip-flops in series on the destination clock. The first may go metastable. The second samples its output one whole clock period later, giving the first a full cycle to resolve. Only the second flip-flop's output is used by the rest of the design.

The calculator below compares one stage against two, using a fast 500 MHz clock to make the numbers dramatic.

Python MTBF of one-stage and two-stage synchronizers

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

With these deliberately harsh numbers (a 500 MHz clock sampling an input that changes 50 million times a second), one stage fails within a fraction of a second, two stages last about 11 hours, and three stages last centuries. Each extra stage multiplies the MTBF by roughly 10^5 here. Slowing the clock to 400 MHz gives a two-stage synchronizer about 34 years, and 300 MHz gives hundreds of millions of years, because resolution time sits in the exponent.

The same effect can be seen in a Monte Carlo toy model. Here each metastable event gets a random resolution time (exponential, with mean ฯ„_res). A single-flop design fails whenever the event is still unresolved when the next flip-flop samples it; the two-stage design allows one more full period.

Python Toy simulation of a synchronizer

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Only edges landing inside the narrow window can cause trouble, and of those, a good fraction is still unresolved after one stage but very few after two. That ratio is the whole idea of the synchronizer.

A synchronizer protects a single bit. If a multi-bit value (a counter, a data bus) crosses clock domains, the individual bits may be captured on different cycles and you read garbage. Use Gray-coded counters, handshakes or FIFOs for multi-bit crossings.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. A path has t_cq = 0.5 ns, logic delay 3.0 ns and t_su = 0.5 ns, with no skew. What is the maximum clock frequency?

    T_min = 0.5 + 3.0 + 0.5 = 4.0 ns, so f_max = 1 / 4 ns = 250 MHz.
  2. 2. How can a hold-time violation be fixed?

    The hold check does not depend on the clock period. You lengthen the fastest path (for example with buffers) or reduce skew.
  3. 3. Positive clock skew (the capture flip-flop gets the clock later) does what?

    A later capture edge gives the data more time to arrive, but it also leaves the capture window open longer, so new data may overrun it.
  4. 4. Why does a two-flip-flop synchronizer work?

    The chance of staying unresolved falls exponentially with time, so one full extra period makes a failure extremely unlikely.
  5. 5. Which signal is a good candidate for a two-flip-flop synchronizer?

    A synchronizer is for a single asynchronous bit. Buses need handshakes, Gray coding or a FIFO.

Summary

  • Minimum clock period for a path: T_min = t_cq + t_logic(max) + t_su (+ skew). The critical path sets f_max = 1 / T_min, and slack is the time to spare.
  • The hold check, t_cq(min) + t_cd(min) โ‰ฅ t_h + skew, does not involve the clock period, so only extra delay or lower skew fixes it.
  • Positive skew helps setup and hurts hold; negative skew does the opposite.
  • Metastability happens when an input changes inside the setup/hold window; the output resolves after a random time that is exponentially unlikely to be long.
  • A two-flip-flop synchronizer raises the MTBF by many orders of magnitude, but only for single bits.

Next: Registers and Shift Registers.