Crystal load capacitor calculator
The formula C = 2(CL − Cstray) gives a value no shop sells and says nothing about what it costs to round it. This page picks the standard capacitors that leave the smallest frequency error, shows that error in ppm at every tolerance corner next to your budget, and checks the gain margin and the drive level the way ST's AN2867 does.
The crystal (datasheet)
Board and oscillator
Defaults: an 8 MHz crystal with the 80 Ω ESR and the 25 mA/V STM32F1 oscillator of AN2867's worked example. The load, C0, C1 and stray figures are illustrative: replace them with your datasheets'.
| Capacitors | Load | Error, nominal | Error, worst | Critical gm, worst | Verdict |
|---|
How this is calculated
A crystal is cut to oscillate at its marked frequency when the circuit around it presents one particular capacitance, the load capacitance CL on its datasheet. In a microcontroller's Pierce oscillator that load is the two capacitors from each pin to ground, in series as the crystal sees them, plus the stray capacitance of the pins and the traces:
CL = CL1·CL2 / (CL1 + CL2) + Cs
With two equal capacitors that solves to CL1 = CL2 = 2(CL − Cs). For a 12 pF crystal and 5 pF of stray that is 14 pF, which is not an E12 value. The page then asks what each catalogue value would do to the frequency. A crystal's equivalent circuit is a series motional branch (C1, L1, R1) with the shunt capacitance C0 across it, and with a load CL in series it resonates at
fL = fs · √(1 + C1 / (C0 + CL))
where fs is the series resonance of the motional branch alone. The error is the ratio of fL at the load you build to fL at the load the crystal was cut for, in parts per million. Two 15 pF capacitors give 12.5 pF and −12.6 ppm; two 12 pF give 11 pF and +27.5 ppm. The page buys the 15 pF pair. It also looks at pairs of two neighbouring values, since unequal capacitors work in a Pierce oscillator too: 12 pF with 15 pF gives 11.67 pF and +8.8 ppm, which the page points out when it beats the matched pair. The formula treats the crystal as lossless. Its resistance moves the result by a share of the error that grows as (2πf·C0·ESR)²: 0.08 % with the defaults, a few per cent for a fast crystal with a high ESR, which is less than the capacitor tolerance moves it, and a measurement includes it anyway.
The slope of that curve is the crystal's pullability, C1/(2(C0 + CL)²) in ppm per pF. Some datasheets give it instead of C1; choose pullability and the page works C1 back out at the specified load. With the defaults it is 26.0 ppm/pF: every picofarad of load you get wrong moves the clock by 26 ppm.
The worst case, and why the stray matters most
The load is never exactly what you design. Each capacitor has its tolerance, and the stray is an estimate: the pin capacitance from the microcontroller datasheet plus whatever the traces add, which you can't know to better than a picofarad or so before the board exists. The page evaluates every corner of those three and reports the lowest and highest load, and the error at each. With the defaults, ±5 % on two 15 pF capacitors moves the load by only ±0.375 pF, because two capacitors in series halve their own spread, while ±1 pF of stray moves it by the full ±1 pF. The load runs from 11.125 to 13.875 pF and the error from +23.9 to −43.8 ppm.
AN2867 adds this to the crystal's own figures: its tolerance at 25 °C and its stability over temperature. The page does the same and compares the worst total with your budget. Here that is −43.8 − 20 − 20 = −83.8 ppm against ±100 ppm. Bluetooth Low Energy allows ±50 ppm in total, so the same crystal and layout would fail it; a crystal with ±10 ppm figures or a better known stray would pass.
Gain margin: will it start?
The oscillator's amplifier has to make up for the power the crystal loses in its resistance. The transconductance it needs just to sustain oscillation, from AN2867, is
gmcrit = 4 · ESR · (2πf)² · (C0 + CL)²
AN2867's example, an 8 MHz crystal with C0 = 7 pF, CL = 10 pF and 80 Ω, needs 0.23 mA/V. The microcontroller datasheet gives either the oscillator's gm, and the gain margin gm/gmcrit should be at least 5, or a Gm_crit_max, which is gm/5 already and gmcrit must stay under.
That formula is an approximation. It assumes two equal capacitors, and it drops one term: the current the crystal's resistance drives through C0 and the stray. The page solves the Pierce circuit exactly instead. The crystal, with C0 and the stray across it, must present an inductive reactance that cancels the two capacitors in series, which is a quadratic in the crystal's reactance, and gmcrit follows from the solution. The page takes it at the corner with the most capacitance, where it is largest. With the defaults that is 0.291 mA/V, a margin of 85.8, and 1.1 % more than AN2867's formula at the same corner. The difference grows with (2πf·C0·ESR)²: for a 40 MHz crystal with 3 pF of C0, 50 Ω and 4 pF of stray it is 3.9 %, and it grows without bound as the ESR approaches the limit below. The page says so once it passes 2 %.
The exact solution also has a limit the formula hides. Above a certain ESR no gm at all can sustain oscillation, because the negative resistance a Pierce circuit can present has a maximum. With the defaults it is 355 Ω at the worst corner, more than four times the 80 Ω crystal. Smaller load capacitors, less C0 and stray, or a lower frequency raise it. The page warns once the crystal's ESR passes a third of it, and fails the design when it passes it.
The margin is what fails with 32.768 kHz crystals. Their ESR is tens of kilohms and the low-power oscillators that drive them have gm measured in µA/V, so a margin of 5 is often all there is. A crystal with a lower CL is easier to start, which is why low-power watch crystals come in 6 or 7 pF versions; the price is a higher pullability, so each picofarad of stray costs more ppm.
Drive level
The crystal dissipates power in its resistance, and too much ages it, shifts its frequency or cracks it. The datasheet gives a maximum in µW. AN2867 measures it from the swing at OSC_IN, since the crystal's current is practically the current through CL1:
DL = ESR · (π · f · Ctot · Vpp)² / 2, Ctot = CL1 + Cs/2 + Cprobe
Without a measurement the page turns the formula round and gives the largest swing at OSC_IN the drive level allows, without the probe: 3.59 V peak-to-peak for the defaults, more than a 3.3 V oscillator can produce. Enter a measured swing, taken with a low-capacitance probe (AN2867 says 1 pF or less), and the page gives the drive level itself. Too much drive is fixed with a resistor between OSC_OUT and the crystal, which forms a low-pass filter with CL2; recheck the gain margin with that resistor added to the ESR.
Finding the stray from a measurement
The stray capacitance is the one number nobody can give you in advance. Once a board exists, measure the frequency: on most microcontrollers through a clock output pin (MCO), never by probing the crystal itself, since the probe adds load. Choose check the ones I have, enter the capacitors fitted and the error you measured, and the page solves the formula above backwards for the load the crystal actually sees, subtracts the capacitors, and gives the stray. The crystal's own tolerance limits how well that works: ±20 ppm at 26 ppm/pF is ±0.77 pF of uncertainty, and the page reports that range and the pair that would centre the frequency.
Which capacitors to fit
C0G (NP0) ceramic. Their capacitance hardly moves with temperature or voltage. X7R is allowed to drift ±15 % over its temperature range, which on two 15 pF capacitors is about ±1.1 pF of load and about ±29 ppm at the default pullability, and it also loses capacitance with applied voltage. Below 10 pF, capacitors are usually sold with a tolerance in picofarads (B, C or D) rather than in percent; the capacitor code calculator reads the marking and the tolerance letter. Keep the traces short and away from noisy lines: every millimetre adds stray, and a long trace near a fast signal couples it into the oscillator. The crystal itself is an LC resonator with a Q in the tens of thousands, the same equations as the LC resonance calculator with an inductance of millihenries and a capacitance of femtofarads.
FAQ
What load capacitors does a 32.768 kHz crystal need?
For a 12.5 pF crystal and 4 pF of stray, 2(12.5 − 4) = 17 pF each. In E12 that is 15 pF or 18 pF: 18 pF gives 13 pF of load against the 12.5 specified, 15 pF gives 11.5 pF, so 18 pF is closer. Check the gain margin too, with the oscillator's gm in µA/V; with a 6 or 7 pF crystal the capacitors are much smaller.
Can I just use two capacitors of twice CL?
That rule ignores the stray capacitance and makes the load too large, so the crystal runs slow. For the default 12 pF crystal it gives 24 pF; the nearest E12 values, 22 pF and 27 pF, put the load at 16 or 18.5 pF with 5 pF of stray, and the clock at −84.0 or −121.9 ppm, before the crystal's own tolerance.
My crystal runs fast. Bigger or smaller capacitors?
Bigger. More load capacitance pulls the frequency down. Enter the measured error under check the ones I have and the page gives the stray it implies and the pair that would centre it.
What is a good gain margin?
AN2867 asks for at least 5. Below that the oscillator may start on the bench and fail cold, or with a crystal at the top of its ESR range. If the margin is short, choose a crystal with a lower ESR or a lower CL.