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.

Five questions this page answers
Question
1Why does a chip have three clock sources and not one?
2Why does a chip start on its RC oscillator?
3The PLL output toggles. May the chip use it?
4What is a clock tree, and why is it made of buffers?
5What 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

New words on this page
WordMeaning
OscillatorA circuit that makes clock edges by itself. It has no clock input.
RC oscillatorAn oscillator inside the chip. A capacitor charges and discharges through a resistor, and that sets the rate. RC stands for resistor and capacitor.
Crystal oscillatorAn oscillator whose rate is set by a quartz crystal on the board. The rate is very exact.
Period of a clockThe 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 clockThe clock that a PLL follows. Here it is the crystal clock.
PLL lockA signal from the PLL, called lock for short. It is 1 when the output has settled at the right rate.
Source muxThe switch that passes one clock source to the rest of the chip.
Clock rootThe output of the source mux: the one clock that the whole tree carries.
Clock bufferA gate that copies its input to its output with more drive strength. It adds a small delay.
Clock treeThe buffers and wires that carry the clock root to every flip-flop.
Clock leafAn end of the clock tree: the clock as a group of flip-flops receives it.
Insertion delayThe time an edge takes from the clock root to one clock leaf.
Clock skewThe difference between the arrival times of one edge at two clock leaves.
The three sources, side by side
SourceIts strengthIts weaknessIts job in ap_soc
RC oscillatorInside the chip. Runs almost from the first moment.The rate is rough and drifts.The clock at start: 25 MHz.
Crystal oscillatorA very exact rate.Needs a part on the board. Slow to start. Not fast.The reference clock: 50 MHz.
PLLA 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

From Three Sources to Four LeavesStep through the picture. It starts with the one source that needs nothing.
  • Clock / reset
  • Pads
  • Control / FSM
  • Bus
  • Processor
  • Peripheral
From Three Sources to Four LeavesStep through the picture. It starts with the one source that needs nothing. component RC oscillator inside the chip; 25MHz, roughly component Crystal oscillator a crystal on theboard; 50 MHz,exactly component PLL makes 100 MHz fromthe 50 MHz component Source mux software picks RC orPLL component Clock root the one clock of thechip component Clock buffers level after level; eachadds delay component Leaf: processorand bus the edge arrives 3 nsafter the root component Leaf: GPIO the edge arrives 4 nsafter the root from the first momentreference clockgood only after lockone of the twoone wire in3 buffers on the way4 buffers on the way
  1. component RC oscillatorinside the chip; 25 MHz, roughly
    • from the first moment → Source mux
  2. component Crystal oscillatora crystal on the board; 50 MHz, exactly
    • reference clock → PLL
  3. component PLLmakes 100 MHz from the 50 MHz
    • good only after lock → Source mux
  4. component Source muxsoftware picks RC or PLL
    • one of the two → Clock root
  5. component Clock rootthe one clock of the chip
    • one wire in → Clock buffers
  6. component Clock bufferslevel after level; each adds delay
    • 3 buffers on the way → Leaf: processor and bus
    • 4 buffers on the way → Leaf: GPIO
  7. component Leaf: processor and busthe edge arrives 3 ns after the root
  8. component Leaf: GPIOthe edge arrives 4 ns after the root
  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

Three rates as periods, by hand
SourceRatePeriodHow
RC oscillator25 MHz40 ns1000 / 25
Crystal oscillator50 MHz20 ns1000 / 50
PLL100 MHz10 nsTwice 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.

The start of the clocks, by hand
TimeWhat happensClock at the root
20 nsFirst edge of the RC oscillator.RC, period 40 ns
110 nsFirst edge of the crystal oscillator. The PLL output starts to toggle.RC
130, 150, 170 nsReference edges two, three and four. Lock is still 0.RC
190 nsReference edge five: 110 plus four periods of 20. Lock rises.RC
After 190 nsSoftware 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.

Two leaves, by hand
LeafBuffers on the wayInsertion delay
Processor and bus33 ns
GPIO, far across the chip44 ns
Clock skew between the two4 - 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

  1. Rule 1: An oscillator needs no clock. Everything else does.

    So every clock on the chip can be traced back to an oscillator.

  2. 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.

  3. Rule 3: A PLL multiplies the rate of its reference clock.

    Here the factor is 2: a reference of 50 MHz gives 100 MHz.

  4. 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.

  5. 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.

  6. 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.

Printed by the lab on Icarus. Times and periods are in nanoseconds.
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 ns

Rule 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 choiceThe alternativeWhat the choice buys, and costs
Start on the RC oscillatorHold the chip in reset until the crystal runsThe chip can run, and report a fault, with a dead crystal. The first code runs on a rough clock.
A PLL for the fast clockA crystal at the full rateA cheap, slow crystal is enough, and software can change the rate. The PLL costs area, power and time to lock.
A tree of small buffersOne huge driver for the whole chipEach buffer drives a load it can manage, and sits near its flip-flops. Every level adds delay.
Equal delay to every leafThe shortest wire to every leafSmall 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 page4 leaves, 8 buffers
A phone chipmillions of flip-flops

This section looks ahead. Our tree has eight buffers. The tree of a phone chip is a design task of its own.

  1. 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.

  2. 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.

  3. 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.

  4. 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
NameMeaning
rc first edgeThe time of the first rising edge of the RC oscillator, in nanoseconds.
crystal first edgeThe time of the first rising edge of the crystal oscillator.
earlyA look at the PLL after three of its edges. locked=0 means that lock is still low.
period nsThe time from one rising edge to the next, for each source.
root periodThe same measure at the clock root, with the source that the mux has passed.
lockThe time at which the PLL raises lock.
leaf core, leaf gpioHow long after the root the same edge arrives at that leaf.
skewThe difference between the two arrival times.
RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: 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 ns
Read 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

Predict the outputIn this run the crystal oscillator gives its first rising edge at 70 ns, and the run ends at lock. What is the last row the lab prints?
`timescale 1ns/1ns
module tb;
  wire clk_rc, clk_ref, clk_pll, locked;      // RC oscillator, crystal oscillator, PLL output, PLL lock
  // The crystal oscillator is switched on at 60 ns. Its first rising edge comes 10 ns later. The PLL reports lock after 5 reference edges.
  clock_source_model #(.REF_START(60), .LOCK_EDGES(5)) sources(.*);

  bit request_pll;                            // the choice of the source mux: 0 = RC, 1 = PLL
  wire clk_root;                              // the output of the source mux: the root of the tree
  clock_path_model path(.clk_rc, .clk_pll, .request_pll, .gate_open(1'b1),
                        .clk_root, .clk_div(), .clk_leaf());

  // The clock tree. Each buffer is modelled as a delay of 1 ns (a lab number).
  wire trunk, branch_a, branch_b;
  wire leaf_core, leaf_bus, leaf_uart, leaf_gpio;
  assign #1 trunk = clk_root;
  assign #1 branch_a = trunk;
  assign #1 branch_b = trunk;
  assign #1 leaf_core = branch_a;
  assign #1 leaf_bus = branch_a;
  assign #1 leaf_uart = branch_b;
  assign #2 leaf_gpio = branch_b;          // GPIO sits far away: 1 more buffer on its branch

  // The period of a clock: the time from one rising edge to the next.
  task automatic root_period_now(output time result);
    time first;
    @(posedge clk_root); first = $time;
    @(posedge clk_root); result = $time - first;
  endtask

  time rc_period, ref_period, pll_period, root_period, launched;
  initial begin
    @(posedge clk_rc);
    $display("rc first edge t=%0d", $time);
    @(posedge clk_ref);
    $display("crystal first edge t=%0d", $time);
    repeat (3) @(posedge clk_pll);
    $display("early t=%0d pll edges=3 locked=%b", $time, locked);
    fork
      begin @(posedge clk_rc);  rc_period = $time;  @(posedge clk_rc);  rc_period = $time - rc_period;   end
      begin @(posedge clk_ref); ref_period = $time; @(posedge clk_ref); ref_period = $time - ref_period; end
      begin @(posedge clk_pll); pll_period = $time; @(posedge clk_pll); pll_period = $time - pll_period; end
      root_period_now(root_period);
    join
    $display("period ns: rc=%0d crystal=%0d pll=%0d", rc_period, ref_period, pll_period);
    $display("root period=%0d ns source=RC", root_period);
    wait (locked);
    $display("lock t=%0d", $time);
    $finish;
  end
endmodule
Read 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
ConceptWhy does a chip have a PLL as well as a crystal oscillator?
ConceptWhy does a chip start on its RC oscillator?
ConceptThe PLL output toggles and lock is 0. What may the chip do with that clock?
ConceptWhy is a clock tree made of many buffers?
ConceptWhat is clock skew?

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.

Practice

Report a problem with this page