Clock Sources and the Chip-Level Clock Tree
A chip has thousands of flip-flops and every one of them waits for an edge. Where does the first edge come from, why are there three sources for it, and how does one clock reach every flip-flop?
You Will Be Able To
- Say why a chip has an RC oscillator, a crystal oscillator and a PLL, and what each one is good at.
- Explain why a chip starts on the RC oscillator and moves to the PLL only after lock.
- Describe a clock tree, and work out insertion delay and clock skew from a count of buffers.
- Lesson
- S5.1
- Time
- 25 min
- Runs on
- Your browser
- Check
- 6 questions
You clip a probe to the fast clock and see a tidy square wave. A colleague switches the chip over to it, and the chip hangs. Nothing was wrong with the wave you saw. So what did the probe not tell you?
Before You Start
You need From Board to Chip: it names the clock and reset unit as one of the eight boxes. You need one fact about a flip-flop: it takes its input on the rising edge of its clock.
This page uses the processor, the bus, UART0 and GPIO only as names of blocks that need a clock. What is inside such a block is in The Anatomy of a Peripheral. You can read that page first, or after this one.
| Question | |
|---|---|
| 1 | Why does a chip have three clock sources and not one? |
| 2 | Why does a chip start on its RC oscillator? |
| 3 | The PLL output toggles. May the chip use it? |
| 4 | What is a clock tree, and why is it made of buffers? |
| 5 | What is clock skew? |
The Idea: Three Sources, One Order, One Tree
Every flip-flop waits for a clock edge. Something must make the first edge without a clock of its own. That something is an oscillator: a circuit that swings between 0 and 1 by itself.
No one oscillator is good at everything, so a chip has three sources. An oscillator built from a resistor and a capacitor sits inside the chip and starts almost at once. But its rate is only roughly right, and it drifts with temperature. A crystal on the board sets a very exact rate. But it needs a part outside the chip, and it is slow to start. It is practical only up to some tens of megahertz.
The third source closes the gap. A phase-locked loop, or PLL, takes the exact, slow clock of the crystal. It makes a fast clock that is just as exact. That is why a chip needs one: the processor wants a faster clock than any cheap crystal gives. The loop needs time to settle on its target. It says that it has settled with a signal called PLL lock, or lock for short.
Now the order at start is forced. The code that switches the crystal on and sets up the loop needs a clock to run on. Only one source is alive from the first moment. So the chip starts on the rough clock, and software moves it to the fast one after lock.
The last idea is distance. One clock must reach every flip-flop of the chip, and one driver cannot drive them all. So the clock passes through buffers that fan out, level after level, like a tree. Each buffer adds delay. If two flip-flops get the same edge at different times, they no longer agree on when "now" is.
New Words
| Word | Meaning |
|---|---|
| Oscillator | A circuit that makes clock edges by itself. It has no clock input. |
| RC oscillator | An oscillator inside the chip. A capacitor charges and discharges through a resistor, and that sets the rate. RC stands for resistor and capacitor. |
| Crystal oscillator | An oscillator whose rate is set by a quartz crystal on the board. The rate is very exact. |
| Period of a clock | The time from one rising edge to the next. A clock of 100 megahertz has a period of 10 nanoseconds. |
| Phase-locked loop (PLL) | A circuit that makes a clock from another clock. Its output can be a whole number of times faster. |
| Reference clock | The clock that a PLL follows. Here it is the crystal clock. |
| PLL lock | A signal from the PLL, called lock for short. It is 1 when the output has settled at the right rate. |
| Source mux | The switch that passes one clock source to the rest of the chip. |
| Clock root | The output of the source mux: the one clock that the whole tree carries. |
| Clock buffer | A gate that copies its input to its output with more drive strength. It adds a small delay. |
| Clock tree | The buffers and wires that carry the clock root to every flip-flop. |
| Clock leaf | An end of the clock tree: the clock as a group of flip-flops receives it. |
| Insertion delay | The time an edge takes from the clock root to one clock leaf. |
| Clock skew | The difference between the arrival times of one edge at two clock leaves. |
| Source | Its strength | Its weakness | Its job in ap_soc |
|---|---|---|---|
| RC oscillator | Inside the chip. Runs almost from the first moment. | The rate is rough and drifts. | The clock at start: 25 MHz. |
| Crystal oscillator | A very exact rate. | Needs a part on the board. Slow to start. Not fast. | The reference clock: 50 MHz. |
| PLL | A fast clock that is as exact as its reference. | Needs a reference, and time to reach lock. | The fast clock: 100 MHz. |
MHz is short for megahertz: a million periods in a second. The three rates are choices of our lab chip.
One Picture: Sources, a Choice and a Tree
- Clock / reset
- Pads
- Control / FSM
- Bus
- Processor
- Peripheral
- The source that needs nothing
Power comes up. The RC oscillator sits inside the chip and starts by itself. It is the only clock the chip has in its first moments.
- The accurate source
A crystal on the board sets a very exact rate. Its oscillator must be switched on, and it takes a while before its edges are steady.
- The fast source
The PLL takes the crystal clock as its reference clock. It makes a clock twice as fast, and just as exact. It needs time to settle. When it has settled, it raises a signal called lock.
- The choice
The source mux passes one source to the clock root. It starts on RC. Software moves it to the PLL after lock, and not before.
- The tree
One root cannot drive every flip-flop of the chip. It drives a few buffers. Each of those drives a few more. The last buffers drive the flip-flops: these ends are the leaves.
- The difference at the leaves
Every buffer adds a little delay. A leaf behind four buffers gets each edge later than a leaf behind three. That difference is the clock skew.
Read the diagram as text
- RC oscillator: inside the chip; 25 MHz, roughly
- Crystal oscillator: a crystal on the board; 50 MHz, exactly
- PLL: makes 100 MHz from the 50 MHz
- Source mux: software picks RC or PLL
- Clock root: the one clock of the chip
- Clock buffers: level after level; each adds delay
- Leaf: processor and bus: the edge arrives 3 ns after the root
- Leaf: GPIO: the edge arrives 4 ns after the root
- RC oscillator → Source mux: from the first moment
- Crystal oscillator → PLL: reference clock
- PLL → Source mux: good only after lock
- Source mux → Clock root: one of the two
- Clock root → Clock buffers: one wire in
- Clock buffers → Leaf: processor and bus: 3 buffers on the way
- Clock buffers → Leaf: GPIO: 4 buffers on the way
The clock sources and the clock tree of ap_soc. The rates and the buffer counts are choices of our lab chip.
The Smallest Example, Worked by Hand
Start with the rates. A period in nanoseconds is 1000 divided by the rate in megahertz.
| Source | Rate | Period | How |
|---|---|---|---|
| RC oscillator | 25 MHz | 40 ns | 1000 / 25 |
| Crystal oscillator | 50 MHz | 20 ns | 1000 / 50 |
| PLL | 100 MHz | 10 ns | Twice the reference rate, so half its period |
Now the order at start. In our lab the RC oscillator gives its first rising edge at 20 ns. The crystal oscillator gives its first at 110 ns. Our PLL raises lock on the fifth rising edge of its reference clock.
| Time | What happens | Clock at the root |
|---|---|---|
| 20 ns | First edge of the RC oscillator. | RC, period 40 ns |
| 110 ns | First edge of the crystal oscillator. The PLL output starts to toggle. | RC |
| 130, 150, 170 ns | Reference edges two, three and four. Lock is still 0. | RC |
| 190 ns | Reference edge five: 110 plus four periods of 20. Lock rises. | RC |
| After 190 ns | Software selects the PLL. The mux hands over. | PLL, period 10 ns |
From 110 ns to 190 ns the PLL output toggles and lock is 0. In a real loop the rate is still moving in that time. Those edges look like a clock on a probe, and they are not yet one.
Last, the tree. Say that each buffer delays the clock by 1 ns. Count the buffers from the root to each leaf.
| Leaf | Buffers on the way | Insertion delay |
|---|---|---|
| Processor and bus | 3 | 3 ns |
| GPIO, far across the chip | 4 | 4 ns |
| Clock skew between the two | 4 - 3 = 1 ns |
A skew of 1 ns means this: when the processor leaf sees an edge, the GPIO leaf sees it 1 ns later. Data sent from one to the other has 1 ns more, or 1 ns less, than the period suggests.
The Rules
Rule 1: An oscillator needs no clock. Everything else does.
So every clock on the chip can be traced back to an oscillator.
Rule 2: The chip starts on the source that needs nothing.
That is the RC oscillator. The code that starts the other sources runs on it.
Rule 3: A PLL multiplies the rate of its reference clock.
Here the factor is 2: a reference of 50 MHz gives 100 MHz.
Rule 4: A PLL output counts only after lock.
Before lock it may toggle at a rate that is still moving. Select the PLL after lock, never before.
Rule 5: Insertion delay is the sum of the delays on the way to a leaf.
Count the buffers and wires from the clock root to that leaf.
Rule 6: Clock skew is the difference between two insertion delays.
A tree is built so that this difference stays small.
Sources for These Rules
Rule 3, and a PLL as the way to get a fast clock from a slow crystal: Weste and Harris, CMOS VLSI Design, fourth edition, chapter 13. Section 13.4.3.3, and section 13.5.1 for the loop itself.
Rules 5 and 6, the buffers of a clock network and the need to make arrival times equal: Weste and Harris, CMOS VLSI Design, fourth edition, chapter 13. Sections 13.4.2 and 13.4.4.
The rate of an oscillator inside the chip depends on how the chip was made. A crystal is used when the rate must be stable: Kang and Leblebici, CMOS Digital Integrated Circuits, third edition, chapter 13, section 13.5.
Rule 2 is common practice in microcontrollers. It is not a rule of any standard, and none of our reference books states it.
Rule 4 is how our lab is built. The lock signal and its timing belong to each PLL design: read the data sheet of yours.
Now Run It
The lab at the end of this page has the three sources, the source mux and a tree of eight buffers. There is no processor in it. A few lines of test code stand in for the software that selects the PLL.
rc first edge t=20
crystal first edge t=110
early t=135 pll edges=3 locked=0
period ns: rc=40 crystal=20 pll=10
root period=40 ns source=RC
lock t=190
root period=10 ns source=PLL
leaf core +3 ns
leaf gpio +4 ns
skew=1 nsRule 2 at work: the RC oscillator gives an edge at 20 ns, long before the crystal does at 110 ns. Rule 3 at work: the periods are 40, 20 and 10.
Rule 4 at work: the row "early" counts three PLL edges at 135 ns, and locked is 0. Lock comes at 190 ns. The root has a period of 40 before the switch and 10 after it.
Rules 5 and 6 at work: the edge reaches the processor leaf 3 ns after the root. It reaches the GPIO leaf 4 ns after the root. The last row is the difference.
This lab leaves a great deal out. Its sources are ideal: they have no drift, and the PLL holds its final rate from its first edge. A real crystal needs milliseconds to start, not 100 ns. Each buffer is a plain delay of 1 ns. Between our root and the leaves the real chip also has a divider and a gate: they are the next page.
Why It Is Built This Way
| Design choice | The alternative | What the choice buys, and costs |
|---|---|---|
| Start on the RC oscillator | Hold the chip in reset until the crystal runs | The chip can run, and report a fault, with a dead crystal. The first code runs on a rough clock. |
| A PLL for the fast clock | A crystal at the full rate | A cheap, slow crystal is enough, and software can change the rate. The PLL costs area, power and time to lock. |
| A tree of small buffers | One huge driver for the whole chip | Each buffer drives a load it can manage, and sits near its flip-flops. Every level adds delay. |
| Equal delay to every leaf | The shortest wire to every leaf | Small skew. Near leaves get more delay than they would need alone. |
The last row is the surprise of clock design. A good tree does not bring the clock to each leaf as fast as it can. It brings the clock to every leaf at the same time.
The Trap: A Wave That Toggles, and a Name That Lies
Back to the tidy square wave. The probe sat on the PLL output, and the output toggled. But a probe shows edges, not lock. The chip was switched over while the loop was still settling, on edges that rule 4 forbids.
The cure is one line of boot code: wait for lock, then select. Real boot code goes further and asks that lock stay high for several samples. The practice problem on this page is such a guard.
The second trap is a name. Someone calls the root "the 100 MHz clock". At start it runs at 25. Code that waits "a million periods" then waits four times as long. Name a clock by where it is, and list its rates by mode.
The third trap is the place of the probe. An edge at the root proves nothing about a leaf. Measure a clock where its flip-flops are.
At Scale
This section looks ahead. Our tree has eight buffers. The tree of a phone chip is a design task of its own.
The tree is built by a tool
Nobody places a million buffers by hand. A tool places them and balances the delays. Skew, Latency and Insertion Delay and Building the Tree show it.
Skew enters every timing check
A path between two flip-flops gains or loses the skew between their leaves. Setup and Hold With Skew works the sums.
Between root and leaf
A real chip puts dividers and gates into the tree. Each block then gets the rate it needs and no more. That is the next page.
Many PLLs
A large chip has several PLLs: for the processors, the memory interface and each fast link. Each has its own lock, and its own order at start.
Try It
Run the lab. The first six rows are the start of the three sources. Then comes the root after the switch, and three rows of the tree.
Change REF_START from 100 to 200. Predict which rows move before you run it.
Give leaf_gpio one more buffer: change its delay from 2 to 3. Predict the last row.
Names Printed by the Lab
| Name | Meaning |
|---|---|
| rc first edge | The time of the first rising edge of the RC oscillator, in nanoseconds. |
| crystal first edge | The time of the first rising edge of the crystal oscillator. |
| early | A look at the PLL after three of its edges. locked=0 means that lock is still low. |
| period ns | The time from one rising edge to the next, for each source. |
| root period | The same measure at the clock root, with the source that the mux has passed. |
| lock | The time at which the PLL raises lock. |
| leaf core, leaf gpio | How long after the root the same edge arrives at that leaf. |
| skew | The difference between the two arrival times. |
rc first edge t=20 crystal first edge t=110 early t=135 pll edges=3 locked=0 period ns: rc=40 crystal=20 pll=10 root period=40 ns source=RC lock t=190 root period=10 ns source=PLL leaf core +3 ns leaf gpio +4 ns skew=1 nsRead included file: clock_source_model.sv
// Simulation-only nominal sources. REF_PERIOD is in ns; no jitter or analog loop.
// REF_START: how long the crystal oscillator takes to start, in ns (0: it runs from the first moment).
`timescale 1ns/1ns
module clock_source_model #(parameter REF_PERIOD = 20, LOCK_EDGES = 5, REF_START = 0)
(output bit clk_ref, clk_rc, clk_pll, locked);
bit ref_running;
initial #(REF_START) ref_running <= 1;
always #(REF_PERIOD/2) if (ref_running) clk_ref = ~clk_ref;
always #20 clk_rc = ~clk_rc;
initial begin
@(posedge clk_ref);
forever #(REF_PERIOD/4) clk_pll = ~clk_pll;
end
initial begin
repeat (LOCK_EDGES) @(posedge clk_ref);
locked <= 1;
end
endmodule
Read included file: clock_path_model.sv
// Transaction-level handoff for the lab. Both sources must keep running.
// Start on RC. The requester holds its choice until the switch finishes.
module clock_path_model(input wire clk_rc, clk_pll, request_pll, gate_open,
output wire clk_root, clk_leaf, output bit clk_div);
bit pass_rc = 1, pass_pll = 0;
always begin
wait (request_pll);
repeat (2) @(negedge clk_rc);
pass_rc <= 0;
@(negedge pass_rc); // the new source counts only edges after the old grant is off
repeat (2) @(negedge clk_pll);
pass_pll <= 1;
wait (!request_pll);
repeat (2) @(negedge clk_pll);
pass_pll <= 0;
@(negedge pass_pll);
repeat (2) @(negedge clk_rc);
pass_rc <= 1;
end
assign clk_root = (pass_rc & clk_rc) | (pass_pll & clk_pll);
always @(posedge clk_root) clk_div <= ~clk_div;
bit held_open;
always_latch if (!clk_div) held_open <= gate_open;
assign clk_leaf = clk_div & held_open;
endmodule
Check Yourself
Common Mistakes
Wrong Switch to the PLL when its output toggles.
The output toggles before the loop has settled.
Fix Wait for lock, then select the PLL.
Wrong Name the root by its fastest rate.
At start the root carries the RC clock.
Fix Name a clock by its place, and list its rates by mode.
Wrong Probe the root to prove that a block has a clock.
The edge still has to travel the tree to that block.
Fix Measure the clock at the leaf.
Remember
- An RC oscillator is there at once, but rough. A crystal oscillator is exact, but slow. A PLL makes an exact clock fast.
- A chip starts on the RC oscillator, and moves to the PLL only after lock.
- A clock tree carries one root to every leaf through buffers. Each buffer adds delay.
- Insertion delay is root to leaf. Clock skew is the difference between two leaves.