---
title: Timing of sequential circuits
heading: Setup, hold, clock skew, metastability and pipelining
eyebrow: C7 · Lesson 27 · Timing of sequential circuits
xp: 40
---

::: hook
A synchronous circuit works only if every signal leaving one flip-flop reaches the next in time for the following clock edge, and not so quickly that it disturbs the value being captured on the current one. Those two conditions, setup and hold, decide a chip's top clock speed and whether it works at all. Signals that arrive from outside, unsynchronized to the clock, add a third problem: a flip-flop caught mid-change can hang between 0 and 1. And when the logic between registers is too slow, the cure is to cut it into stages: pipelining.
:::

::: play
- One register feeds two paths to two more registers: N1 inverts it after 3 ticks, N2 after 12. The clock period is 8 ticks.
- R1 always captures the new value of N1. N2 hasn't settled when the next edge arrives, so R2 captures a stale value: the slow path violates setup.
- A slow path can be fixed by a slower clock, a faster circuit, or by adding a register in the middle of it.
:::
:::

```sim logic
clock CLK 8
input D
stim D 0@0 1@5 0@21 1@37
always @(posedge CLK) Q1 <= D;
assign N1 = ~Q1
assign N2 = ~Q1
delay N1 3
delay N2 12
always @(posedge CLK) begin
  R1 <= N1;
  R2 <= N2;
end
wave: CLK, Q1, N1, R1, N2, R2
time: 64
```

::: predict
## A flip-flop's clock-to-Q delay is 50 ps, the logic after it takes 600 ps, and the next flip-flop needs 40 ps of setup. What is the highest clock frequency?

- [ ] 1.67 GHz
- [x] About 1.45 GHz
- [ ] 2 GHz
- [ ] 20 GHz

::: reveal
About 1.45 GHz: the period must cover 50 + 600 + 40 = 690 ps. The logic dominates, but the flip-flops' own overhead is part of every cycle, which matters more as logic per stage shrinks.
:::
:::

::: nameit
## Setup

From one clock edge, data leaves a flip-flop after at most $t_{pcq}$ (clock-to-Q), passes logic of at most $t_{pd}$, and must arrive $t_\text{setup}$ before the next edge:

$$T_c \ge t_{pcq} + t_{pd} + t_\text{setup} \qquad f_\text{max} = 1/T_c$$

The slowest such path is the **critical path**. A setup violation can always be fixed by slowing the clock.

## Hold

The new data must not reach the next flip-flop so soon that it corrupts what that flip-flop is capturing on the same edge. With the shortest delays, $t_{ccq}$ (contamination clock-to-Q) and $t_{cd}$ (contamination logic delay):

$$t_{ccq} + t_{cd} \ge t_\text{hold}$$

This doesn't involve the clock period, so slowing the clock can't fix it: the fix is adding delay (buffers) to the short path.

## Clock skew

If the receiving flip-flop's clock arrives late by up to $t_\text{skew}$, the setup constraint gets easier only if skew is known; in the worst case both tighten: $T_c \ge t_{pcq} + t_{pd} + t_\text{setup} + t_\text{skew}$ and $t_{ccq} + t_{cd} \ge t_\text{hold} + t_\text{skew}$.

## Metastability and synchronizers

An input that changes asynchronously can violate setup, leaving a flip-flop between 0 and 1 for an unbounded (but exponentially unlikely) time. The probability that it's still unresolved after time t is about $\frac{T_0}{T_c}e^{-t/\tau}$, with τ and $T_0$ properties of the flip-flop. A **synchronizer**, two flip-flops in series, gives the first nearly a whole period to resolve, so for N asynchronous changes per second

$$\text{MTBF} = \frac{T_c}{NT_0}e^{(T_c - t_\text{setup})/\tau}$$

## Pipelining

Splitting logic of total delay $t_\text{logic}$ into k stages with registers between them gives $T_c = t_\text{logic}/k + t_\text{overhead}$ (the $t_{pcq} + t_\text{setup}$ of each register): **throughput** rises almost k-fold, but each result's **latency** grows to $kT_c$.
:::

::: example
## A synchronizer runs at 100 MHz with $t_\text{setup}$ = 0.1 ns; its flip-flops have τ = 0.2 ns and $T_0$ = 0.15 ns, and the input changes 10⁶ times a second. Find its MTBF.

::: solution
1. **The prefactor.**
   $$\begin{aligned} \frac{T_c}{NT_0} &= \frac{10\ \text{ns}}{10^6 \times 0.15\ \text{ns}} \\ &= 6.7 \times 10^{-5}\ \text{s} \end{aligned}$$
2. **The exponential.** The flip-flop has the period less the setup time, 9.9 ns, to resolve:
   $$e^{9.9/0.2} = e^{49.5}$$
3. **MTBF.**
   $$\begin{aligned} \text{MTBF} &= 6.7 \times 10^{-5}\ \text{s} \times e^{49.5} \\ &\approx 2 \times 10^{17}\ \text{s} \end{aligned}$$
   billions of years.
4. **With half a period.** With only half a period to resolve it would be about $3 \times 10^6$ s, a failure every month: the exponential makes every extra picosecond count.

**Answer:** about $2 \times 10^{17}$ s, billions of years.
:::
:::

::: example
## Logic taking 9 ns sits between registers with 1 ns of overhead. Compare 1, 3 and 9 pipeline stages.

::: solution
1. **One stage.**
   $$9 + 1 = 10\ \text{ns}$$
   100 MHz, with a latency of 10 ns.
2. **Three stages.**
   $$3 + 1 = 4\ \text{ns}$$
   250 MHz, with a latency of 12 ns.
3. **Nine stages.**
   $$1 + 1 = 2\ \text{ns}$$
   500 MHz, with a latency of 18 ns.
4. **Compare.** Throughput rises with depth, but the overhead stops it reaching 900 MHz, and latency grows.

**Answer:** 100 MHz, 250 MHz and 500 MHz, with latencies of 10 ns, 12 ns and 18 ns.
:::
:::

::: example
## Registers with $t_{pcq}$ = 0.1 ns, $t_{ccq}$ = 0.05 ns, setup 0.05 ns and hold 0.03 ns surround logic with $t_{pd}$ = 0.8 ns and $t_{cd}$ = 0.1 ns. The capture clock arrives 0.2 ns late. Check setup and hold.

::: solution
1. **Check setup.** Skew that delays the capture clock gives the data extra time:
   $$\begin{aligned} T_c &\ge 0.1 + 0.8 + 0.05 - 0.2 \\ &= 0.75\ \text{ns} \end{aligned}$$
   a gain.
2. **Check hold.** Hold gets worse by the same amount, since the new data must not arrive before the late edge's hold window closes:
   $$\begin{aligned} t_{ccq} + t_{cd} &= 0.15\ \text{ns} \\ t_\text{hold} + t_\text{skew} &= 0.23\ \text{ns} \end{aligned}$$
   a violation by 0.08 ns.
3. **The fix.** No clock frequency fixes it; delay buffers in the short path do.
4. **The trade.** Skew helps one constraint exactly as much as it hurts the other.

**Answer:** setup passes for any $T_c \ge 0.75$ ns, but hold fails by 0.08 ns.
:::
:::

::: check
given: tpcq = 30 | 80; tpd = 200 | 900; ts = 20 | 60
answer: 1e3/(tpcq + tpd + ts)
unit: GHz
tolerance: 0.5%

## A path has $t_{pcq}$ = {tpcq} ps, logic of {tpd} ps and $t_\text{setup}$ = {ts} ps. What is the highest clock frequency?

::: right
Right. $1/(t_{pcq} + t_{pd} + t_\text{setup})$ = {answer}.
:::

::: misses
- [1e3/tpd] Include the flip-flops' clock-to-Q and setup times.
- [any] Not yet. The period must cover all three.
:::
:::

::: check
given: tpcq = 30 | 80; tpd = 200 | 900; ts = 20 | 60; sk = 10 | 50
answer: tpcq + tpd + ts + sk
unit: ps
tolerance: 0.5%

## With up to {sk} ps of clock skew, what is the shortest period for that path ($t_{pcq}$ = {tpcq}, $t_{pd}$ = {tpd}, $t_\text{setup}$ = {ts} ps)?

::: right
Right. {answer}.
:::

::: misses
- [tpcq + tpd + ts] Add the skew in the worst case.
- [any] Not yet. Skew adds to the setup requirement.
:::
:::

::: check
given: tccq = 20 | 40; tcd = 0 | 15 | 60; th = 30 | 50; sk = 0 | 20
answer: tccq + tcd - th - sk
unit: ps
tolerance: 0.5%

## A short path has $t_{ccq}$ = {tccq} ps and $t_{cd}$ = {tcd} ps; the next flip-flop needs $t_\text{hold}$ = {th} ps, with up to {sk} ps of skew. What is the hold margin (negative means a violation)?

::: right
Right. $t_{ccq} + t_{cd} - t_\text{hold} - t_\text{skew}$ = {answer}.
:::

::: misses
- [any] Not yet. The shortest path must still be longer than hold plus skew.
:::
:::

::: check
given: f = 50 | 200; ts = 0.05 | 0.2; tau = 0.1 | 0.3; T0 = 0.1 | 1; N = 0.1 | 10
answer: log(1/f*1e3/(N*1e6*T0)*exp((1/f*1e3 - ts)/tau))
unit: s
tolerance: 0.5%

## A synchronizer clocked at {f} MHz ($t_\text{setup}$ = {ts} ns, τ = {tau} ns, $T_0$ = {T0} ns) samples an input changing {N} million times a second. What is $\log_{10}$ of its MTBF in seconds?

::: right
Right. MTBF = $\frac{T_c}{NT_0}e^{(T_c - t_\text{setup})/\tau}$, so $\log_{10}$ is {answer}.
:::

::: misses
- [any] Not yet. Compute $(T_c - t_\text{setup})/\tau$ first; the exponential dominates.
:::
:::

::: check
given: t = 6 | 12 | 20; k = 2 | 4; o = 0.5 | 1
answer: 1e3/(t/k + o)
unit: MHz
tolerance: 0.5%

## Logic of {t} ns is split into {k} equal pipeline stages, with {o} ns of register overhead each. What clock frequency results?

::: right
Right. $1/(t_\text{logic}/k + t_\text{overhead})$ = {answer}.
:::

::: misses
- [1e3/(t/k)] Each stage also pays the register overhead.
- [any] Not yet. Period = logic per stage + overhead.
:::
:::

::: check
given: t = 6 | 12 | 20; k = 2 | 4; o = 0.5 | 1
answer: k*(t/k + o)
unit: ns
tolerance: 0.5%

## What is the latency through that pipeline ({t} ns of logic, {k} stages, {o} ns overhead)?

::: right
Right. $k(t_\text{logic}/k + t_\text{overhead})$ = {answer}.
:::

::: misses
- [t] Each stage adds its register overhead.
- [any] Not yet. k periods.
:::
:::

::: check
kind: choice

## Static timing analysis reports a hold violation. Which fix works?

- [ ] Lower the clock frequency
- [ ] Raise the clock frequency
- [x] Add delay buffers to the short path
- [ ] Remove the flip-flop's setup time

::: misses
- [1] Hold doesn't depend on the period: the race is within a single edge.
- [2] Hold doesn't depend on the period at all.
- [4] Setup time is a property of the flip-flop, and it's the other constraint.
:::
:::

::: check
kind: parts
given: P = 0.05 | 0.15; Q = 0.03 | 0.06; Dp = 0.5 | 1.5; Dc = 0.05 | 0.2; Su = 0.04 | 0.08; Ho = 0.02 | 0.05; Sk = 0.05 | 0.15

## Registers ($t_{pcq}$ = {P}, $t_{ccq}$ = {Q}, setup {Su}, hold {Ho} ns) surround logic with $t_{pd}$ = {Dp} ns and $t_{cd}$ = {Dc} ns; the capture clock arrives {Sk} ns late.

::: part
answer: P + Dp + Su - Sk
unit: ns
tolerance: 0.5%

### What's the minimum clock period?

::: misses
- [P + Dp + Su + Sk] A late capture clock gives the data more time.
- [any] $t_{pcq} + t_{pd} + t_\text{setup} - t_\text{skew}$.
:::
:::

::: part
answer: Q + Dc - Ho - Sk
unit: ns
tolerance: 1%

### What's the hold slack (negative means a violation)?

::: misses
- [Q + Dc - Ho + Sk] A late capture clock makes hold harder.
- [any] $t_{ccq} + t_{cd} - t_\text{hold} - t_\text{skew}$.
:::
:::
:::

::: check
kind: derivation
vars: T = 0.000000001..0.0001, N = 1..100000000, t = 0.00000000001..0.000000001, u = 0.00000000001..0.000000001, w = 0.00000000001..0.000000001

## A two-flop synchronizer is clocked with period T; its flip-flops have τ = t and $T_0$ = u, setup w, and the input changes N times a second.

::: step
answer: T/(N*u)*exp((T - w)/t)

### What's its mean time between failures?
:::

::: step
answer: (T - w)/t

### By what exponent does the resolution time beat τ?
:::

::: right
Right. The exponential makes each extra nanosecond of resolution time worth orders of magnitude.
:::
:::

::: explain
## Why can't a hold violation be fixed by slowing the clock?

::: model
A setup violation is a race against the next clock edge: data takes too long to arrive, so giving it a longer period fixes it. A hold violation is a race within a single edge: the same edge launches new data from one flip-flop and captures old data in the next, and if the new data arrives too quickly it overwrites the old value before the capture is complete. Both events happen at the same clock edge, whatever the period, so the period never enters the condition. Only lengthening the short path, or reducing skew, can fix it.
:::
:::

::: practice

::: check
given: Tc = 0.5 | 2 | 10
answer: 1/Tc
unit: GHz
tolerance: 0.5%

## What frequency is a clock period of {Tc} ns?

::: misses
- [any] $1/T_c$.
:::
:::

::: check
given: x = 10 | 20 | 40
answer: x*log(exp(1))
tolerance: 0.5%

## A synchronizer's resolution time grows by {x} time constants τ. By what factor (as a power of ten) does its MTBF grow?

::: misses
- [any] $e^x = 10^{x\log_{10}e}$.
:::
:::

::: check
given: tpcq = 50 | 100; ts = 30 | 60
answer: tpcq + ts
unit: ps
tolerance: 0.5%

## What is the per-stage register overhead for $t_{pcq}$ = {tpcq} ps and $t_\text{setup}$ = {ts} ps?

::: misses
- [any] $t_{pcq} + t_\text{setup}$.
:::
:::
:::
