---
title: Clocks and resets
heading: Clock generation and distribution, jitter, glitch-free clock gating and reset synchronizers
eyebrow: S3 · Lesson 46 · Clocks and resets
xp: 50
---

::: hook
Two signals reach nearly every flip-flop on a chip: the clock and the reset. The clock has to arrive everywhere at almost the same moment with almost the same period, through a tree of buffers spanning the whole die, and gating it off to save power must never chop a pulse short. The reset has to put every flip-flop in a known state and then let go of all of them on the same clock edge, even though the reset button knows nothing about the clock. Both are easy to get subtly wrong, and both failures show up as chips that work on most boards, most days.
:::

::: play
- Two ways to gate a clock. G1 is CLK & EN, a plain AND gate. G2 uses ENL, the enable captured while the clock is low (here by a flip-flop on the inverted clock, standing in for the latch of an integrated clock-gating cell).
- EN changes in the middle of high phases at 6, 22, 38 and 45. Each time, G1 produces a shortened pulse, a glitch that can clock some flip-flops and not others.
- G2 only ever passes whole clock pulses, because its enable can't change while the clock is high.
:::
:::

```sim logic
module icg(input CLK, input EN, output G1, output G2);
assign CLKN = ~CLK;
always @(posedge CLKN) ENL <= EN;
assign G1 = CLK & EN;
assign G2 = CLK & ENL;
endmodule
clock CLK 8
stim EN 0@0 1@6 0@22 1@38 0@45
wave: CLK, EN, G1, ENL, G2
time: 56
```

::: predict
## A reset button drives every flip-flop's asynchronous reset directly. What can go wrong when the button is released?

- [ ] Nothing: asynchronous reset doesn't depend on the clock
- [x] Flip-flops may leave reset on different clock edges, so a state machine starts in an illegal state
- [ ] The flip-flops stay in reset until power is cycled
- [ ] The clock stops

::: reveal
Releasing reset is a change of an asynchronous signal relative to the clock, exactly the clock-domain-crossing problem. If the release lands near a clock edge, inside the flip-flops' recovery and removal window, some flip-flops leave reset on this edge and others on the next, and a one-hot state machine can end up with two hot bits. The cure is a reset synchronizer: assert reset asynchronously, so it works even with no clock, but release it through two flip-flops on the clock.
:::
:::

::: nameit
## Generating the clock

A PLL multiplies a stable reference: $f_\text{out} = f_\text{ref}\frac{N}{MP}$ (feedback divider N, reference divider M, output divider P). Its output **jitter** is the random variation of edge timing. For a link or timing budget at a given bit-error ratio, peak-to-peak random jitter is $2Q\sigma$, with Q = 7.03 for $10^{-12}$. Setup analysis subtracts jitter (and skew) from the period as clock uncertainty.

## Distributing it

A **clock tree** of buffers, each driving f loads, reaches N sinks in $\lceil \log_fN \rceil$ levels using about $\frac{N - 1}{f - 1}$ buffers. Trees are balanced so every path has the same delay (H-trees, meshes in high-performance chips). Skew and insertion delay vary with process, voltage and temperature, so useful margin goes into the timing budget.

A path launched on the rising edge and captured on the falling edge gets only the high phase, $DT$ for duty cycle D, so duty-cycle distortion matters to such half-cycle paths and to DDR interfaces.

## Gating it

Clock gating (lesson 20) must not create glitches. An **integrated clock-gating cell** latches the enable while the clock is low and ANDs the latched enable with the clock, so the gated clock only ever has whole pulses. Synthesis inserts these cells where a register bank has a common enable.

## Resets

- **Synchronous reset:** reset is just another input to the D logic; no timing hazards, but it needs a running clock and adds logic on the D path.
- **Asynchronous reset:** acts at once, even without a clock, but its *release* must meet **recovery** (before the edge) and **removal** (after the edge) times, like setup and hold.
- **Reset synchronizer:** async assert, sync deassert. Two flip-flops with their D chained from 1 and their async resets tied to the raw reset: reset reaches the design immediately and leaves it two clock edges after release, cleanly. Each clock domain gets its own.
:::

::: example
## A design has 100,000 flip-flops and the clock tree uses buffers that each drive 8 loads. How many levels and buffers? And what does a PLL with a 25 MHz reference, N = 96, M = 1, P = 2 give?

::: solution
1. **Levels.**
   $$\begin{aligned} L &= \lceil \log_8 100{,}000 \rceil \\ &= \lceil 5.54 \rceil \\ &= 6 \end{aligned}$$
2. **Buffers per level.** From the flip-flops up: 12,500, 1,563, 196, 25, 4 and 1, for 14,289 in all.
3. **Check with the formula.**
   $$\frac{N - 1}{f - 1} = 14{,}286$$
   close to the count.
4. **The PLL.**
   $$\frac{25 \times 96}{2} = 1200\ \text{MHz}$$

**Answer:** 6 levels and 14,289 buffers; the PLL gives 1,200 MHz.
:::
:::

::: example
## The 1.2 GHz clock has 1.5 ps rms random jitter. What peak-to-peak jitter should the timing budget allow at $10^{-12}$, and how much of the period is left?

::: solution
1. **Peak-to-peak jitter.** At $10^{-12}$ the budget allows $\pm 7.03\sigma$:
   $$2 \times 7.03 \times 1.5 = 21.1\ \text{ps}$$
2. **What's left.** The period is 833 ps, so
   $$833 - 21.1 = 812\ \text{ps}$$
   remain for clock-to-Q, logic, setup and skew.
3. **Half-cycle paths.** At a 48% duty cycle a half-cycle path gets only
   $$0.48 \times 833 = 400\ \text{ps}$$

**Answer:** allow 21.1 ps peak to peak, which leaves 812 ps of the 833 ps period.
:::
:::

::: example
## A 64-bit register bank is idle 80% of the time. Each flip-flop's clock pin is 2 fF, and an integrated clock-gating cell would add 5 fF that toggles every cycle. At 1 GHz and 0.8 V, what does gating save?

::: solution
1. **Ungated.**
   $$\begin{aligned} P &= 64 \times 2\ \text{fF} \times 0.64 \times 10^9 \\ &= 81.9\ \text{µW} \end{aligned}$$
2. **Gated.** The flip-flops see the clock 20% of the time (16.4 µW), and the gating cell's input always toggles (3.2 µW):
   $$16.4 + 3.2 = 19.6\ \text{µW}$$
3. **Saving.**
   $$1 - \frac{19.6}{81.9} = 76\%$$
4. **Minimum width.** Gating a single flip-flop wouldn't pay, which is why tools gate only banks above a minimum width.

**Answer:** gating cuts the clock power from 81.9 µW to 19.6 µW, a 76% saving.
:::
:::

::: check
given: f = 10 | 25 | 100; N = 40 | 96 | 160; M = 1 | 2; P = 2 | 4
answer: f*N/(M*P)
unit: MHz
tolerance: 0.5%

## A PLL has a {f} MHz reference, feedback divider N = {N}, reference divider M = {M} and output divider P = {P}. What's the output frequency?

::: right
Right. $f_\text{ref}N/(MP)$ = {answer} MHz.
:::

::: misses
- [f*N] Divide by the reference and output dividers.
- [any] Not yet. N multiplies; M and P divide.
:::
:::

::: check
given: N = 5000 | 60000 | 2000000; f = 4 | 8 | 16
answer: ceil(log(N)/log(f) - 0.0001)
tolerance: 0

## A clock tree uses buffers that each drive {f} loads. How many levels does it need to reach {N} flip-flops?

::: right
Right. $\lceil \log_fN \rceil$ = {answer}.
:::

::: misses
- [ceil(log(N)/log(2) - 0.0001)] Each level multiplies the reach by f.
- [any] Not yet. Each level fans out f times.
:::
:::

::: check
given: N = 5000 | 60000 | 2000000; f = 4 | 8 | 16
answer: (N - 1)/(f - 1)
tolerance: 1%

## About how many buffers does a tree of fanout-{f} buffers need to drive {N} flip-flops?

::: right
Right. $(N - 1)/(f - 1)$ ≈ {answer}.
:::

::: misses
- [N/f] That's only the last level.
- [any] Not yet. Add N/f + N/f² + ….
:::
:::

::: check
given: s = 0.5 | 1.5 | 4; Q = 7.03 | 7.65
answer: 2*Q*s
unit: ps
tolerance: 0.5%

## A clock has {s} ps rms random jitter. What peak-to-peak jitter does Q = {Q} correspond to?

::: right
Right. $2Q\sigma$ = {answer} ps.
:::

::: misses
- [Q*s] The jitter spreads both ways: twice Q sigma.
- [any] Not yet. Q sigmas on each side.
:::
:::

::: check
given: f = 400 | 800 | 1500; D = 0.45 | 0.48 | 0.52; c = 40 | 60; s = 20 | 30
answer: D*1e6/f - c - s
unit: ps
tolerance: 0.5%

## A path launches on the rising edge and captures on the falling edge of a {f} MHz clock with a {D} duty cycle. With clock-to-Q {c} ps and setup {s} ps, how much time is left for logic?

::: right
Right. $DT - t_{cq} - t_\text{su}$ = {answer} ps.
:::

::: misses
- [1e6/f/2 - c - s] Use the actual high time, D × T.
- [any] Not yet. The path gets only the high phase.
:::
:::

::: check
given: n = 2 | 3; f = 50 | 200 | 1000
answer: n*1000/f
unit: ns
tolerance: 0.5%

## A reset synchronizer has {n} flip-flops on a {f} MHz clock. At most how long after the raw reset is released does the design leave reset, counting whole cycles?

::: right
Right. {n} clock edges: {answer} ns.
:::

::: misses
- [any] Not yet. One clock edge per synchronizer stage.
:::
:::

::: check
kind: parts
given: N = 1000 | 50000 | 200000; f = 4 | 8 | 16; r = 25 | 100; n = 32 | 64; m = 1 | 2; p = 1 | 2

## A clock tree must reach {N} flip-flops with buffers that each drive {f} loads; its PLL takes a {r} MHz reference with N = {n}, M = {m}, P = {p}.

::: part
answer: ceil(log(N)/log(f) - 1e-9)
tolerance: 0

### How many levels does the tree need?

::: misses
- [any] $\lceil\log_fN\rceil$.
:::
:::

::: part
answer: (N - 1)/(f - 1)
tolerance: 1%

### About how many buffers?

::: misses
- [N/f] Count every level, not just the last.
- [any] $(N - 1)/(f - 1)$.
:::
:::

::: part
answer: r*n/(m*p)
unit: MHz
tolerance: 0.5%

### What frequency does the PLL give?

::: misses
- [any] $f_\text{ref}N/(MP)$.
:::
:::
:::

::: check
kind: derivation
vars: D = 0.4..0.6, T = 1e-10..1e-8, t = 1e-11..4e-9, e = 0..0.05

## A path launches on a rising edge and captures on the falling edge of a clock with period T and duty cycle D; its delay is t.

::: step
answer: D*T

### How much time does it get?
:::

::: step
answer: D*T - t

### What is its slack?
:::

::: step
answer: (D - e)*T - t

### And if duty-cycle distortion shortens the high phase by e of the period?
:::

::: right
Right. Half-cycle paths feel duty-cycle errors directly, which is why DDR interfaces specify them tightly.
:::
:::

::: explain
## Why do reset synchronizers assert reset asynchronously but release it synchronously?

::: model
Asserting reset has to work in every situation, including power-up, when the clock may not be running yet or the PLL hasn't locked. Driving the flip-flops' asynchronous reset inputs straight from the reset signal puts them in their known state immediately, with no clock needed, and it doesn't matter exactly when that happens. Releasing reset is different: the moment every flip-flop starts running has to be the same clock edge for all of them, and an asynchronous release could land inside the recovery and removal window and be seen on different edges by different flip-flops. Passing the release through two flip-flops clocked by the domain's clock resolves any metastability and lines the release up with a clock edge, so the whole domain leaves reset together.
:::
:::

::: practice

::: check
given: f = 12 | 50; N = 64 | 200; M = 1 | 4; P = 2 | 8
answer: f*N/(M*P)
unit: MHz
tolerance: 0.5%

## PLL: {f} MHz reference, N = {N}, M = {M}, P = {P}?

::: misses
- [any] $f N/(MP)$.
:::
:::

::: check
given: N = 3000 | 500000; f = 6 | 12
answer: ceil(log(N)/log(f) - 0.0001)
tolerance: 0

## Clock tree levels: {N} sinks, fanout {f}?

::: misses
- [any] $\lceil \log_fN \rceil$.
:::
:::

::: check
given: s = 0.8 | 3; Q = 7.03 | 6.36
answer: 2*Q*s
unit: ps
tolerance: 0.5%

## Peak-to-peak jitter: {s} ps rms, Q = {Q}?

::: misses
- [any] $2Q\sigma$.
:::
:::
:::
