Clocks and Crystals: Getting Oscillators Right on Embedded Boards

Almost every embedded board has at least one crystal, and most work first time. The ones that do not are hard to diagnose: a clock that runs slightly fast, a radio that will not hold a link, or a board that occasionally fails to start at low temperature. These problems come from a small set of causes, chiefly load capacitance, oscillator margin and layout. This article covers each, with the arithmetic needed to get them right.

At a glance

32.768 kHz
Equal to 2^15 Hz, so fifteen divide-by-two stages give exactly one pulse per second.
±20 ppm
A common crystal frequency tolerance at 25 °C; tighter grades are available.
1.73 s/day
The timekeeping error from a constant 20 ppm offset: 86,400 seconds times 20 ppm.
2(CL - Cs)
The value of each of two equal load capacitors for a crystal with load capacitance CL.

The problem

A crystal is specified at a particular load capacitance. If the board presents a different load, the crystal still oscillates but away from its nominal frequency. For a real-time clock that means drift; for a radio or USB interface it can mean a link that fails at the edge of its tolerance.

Oscillator margin is the less visible risk. The oscillator must supply enough gain to overcome the crystal’s resistance with plenty to spare, or start-up becomes slow and unreliable, usually worst at temperature extremes.

Treat the crystal and its capacitors as one tuned circuit, and size the capacitors from the arithmetic, not from the last board.

Getting the numbers right

With two equal load capacitors, the crystal sees them in series plus the stray capacitance of the pins and traces: CL = C/2 + Cs. Rearranged, each capacitor is 2(CL - Cs). Stray capacitance is commonly a few picofarads; the microcontroller datasheet often gives its pin capacitance.

For margin, oscillator application notes commonly recommend that the oscillator’s negative resistance be at least about five times the crystal’s maximum ESR. Also check that the crystal’s ESR and drive level are within the limits stated for the microcontroller’s oscillator.

What good looks like

Pick the crystal from the microcontroller vendor’s recommendations, or check its ESR, load capacitance and drive level against the oscillator specification.

Calculate the load capacitors from CL and an estimated stray capacitance, and record the assumption.

Place the crystal close to the pins with short traces, a ground guard and no signals routed underneath, then measure the frequency on the first boards.

Load capacitor values by crystal CL
Crystal CLEach capacitorNearest E12 value
6 pF4 pF3.9 pF
9 pF10 pF10 pF
12.5 pF17 pF18 pF
18 pF28 pF27 pF
20 pF32 pF33 pF
Calculated as C = 2(CL - Cs) with an assumed stray capacitance of 4 pF. Use your own stray estimate.
Clock error per day by frequency offset
s/day
5 ppm0.43
10 ppm0.86
20 ppm1.73
50 ppm4.32
100 ppm8.64
Calculated as 86,400 seconds times the offset. Real crystals also drift with temperature and age.

What it changes

Accurate Timekeeping

Correct loading keeps the frequency near its nominal value.

Reliable Start-Up

Adequate margin starts the oscillator at every temperature.

Interface Compliance

USB, CAN and radio links stay within their clock tolerances.

Lower Noise

A compact, guarded layout keeps the oscillator quiet and immune.

Where to go next

Consider whether a crystal is needed at all. Many microcontrollers can trim an internal oscillator to the host’s frame timing for full-speed USB, and internal oscillators suit many control tasks.

Where tight accuracy over temperature matters, a temperature-compensated oscillator module may be simpler than trimming a crystal circuit.

Problems this prevents

  • Clocks drifting from wrong load capacitors
  • Boards that fail to start in the cold
  • Crystals driven beyond their rated drive level
  • Noisy signals routed under the oscillator

Discuss your project

Email support@aavico.com or use Get in Touch when the website finishes loading.