Load capacitors, ppm accuracy and reliable oscillator start-up
C0, C1, ESR and CL values from the crystal datasheet; the oscillator transconductance from the microcontroller datasheet or its application note. Capacitors chosen from commercial C0G ceramic values.
A quartz crystal vibrates mechanically at a very stable frequency and, through the piezoelectric effect, behaves as a resonant circuit with an extremely high quality factor. Microcontrollers have an internal inverter between the OSC_IN and OSC_OUT pins; with the crystal and two capacitors to ground they form a Pierce oscillator. The inverter provides the gain and the crystal–capacitor network provides the phase shift needed to sustain oscillation.
The manufacturer calibrates the crystal to oscillate at its nominal frequency when it sees a specific capacitance, the load capacitance CL (typically 8 to 20 pF; for 32.768 kHz watch crystals, 6 to 12.5 pF). The crystal sees the two capacitors in series plus the stray capacitance of the pins and traces:
A common mistake is fitting two capacitors equal to CL: the crystal sees half of that plus the stray capacitance, and oscillates slightly above its nominal frequency. If the stray capacitance is unknown, 3 to 5 pF is a reasonable estimate for a normal board.
For the oscillator to always start, the inverter must have enough gain compared with the crystal losses. The critical transconductance the crystal needs is calculated and compared with that of the oscillator; the ratio is the gain margin, which should be at least 5:
Some manufacturers directly give a maximum gm,crit the oscillator accepts; in that case just check that the chosen crystal's value is below it. If the margin is small: choose a crystal with lower ESR or lower CL, or raise the oscillator drive level if the microcontroller allows it.
Crystal accuracy is given in parts per million: factory tolerance at 25 °C, temperature stability and ageing, each from ±10 to ±50 ppm. A day has 86,400 s, so each ppm is 86.4 ms per day. For serial communication a few tenths of a percent are enough, which any crystal meets; the internal RC oscillator of many microcontrollers, at ±1 to ±2 %, sometimes does not. For a clock that drifts no more than a minute a month, about ±20 ppm in total is needed; to do better, an RTC with a temperature-compensated crystal (TCXO) such as the DS3231 is used.
Related: 555 timer, Schmitt trigger and hysteresis, counters (frequency dividers) and RLC circuit.