How Crystal Oscillators Work

The crystal is your microcontroller's heartbeat — and the cause of many dead-on-arrival boards. Learn how the Pierce oscillator works, how to calculate load capacitors, what ppm accuracy means, crystal vs resonator tradeoffs, layout rules, and how to debug boot failures.

Written by Projectech9 min readPublished
For B.E./B.Tech Electronics and E&TC students using microcontrollers (Arduino, ESP32, STM32, AVR) in academic and final-year projects Topics: Microcontrollers, Oscillators, PCB Design
Illustration of a quartz crystal component beside a microcontroller, showing the Pierce oscillator circuit with two load capacitors and clock waveform.
Illustration generated for this guide.
In this guide

Your microcontroller board is assembled, the code is flashed, and... nothing. No blinking LED, no serial output, no sign of life. You check the power, re-flash the firmware, swap the MCU — still dead. Then someone points at the little silver can next to the chip and asks: "Did you get the load capacitors right?" The crystal oscillator — the heartbeat of nearly every microcontroller — is one of the most quietly critical components on the board, and one of the least understood.

This guide explains how crystal oscillators actually work: the physics inside the quartz, the oscillator circuit hiding inside your MCU, why load capacitors matter so much, what "ppm" means for your project, and how to debug the classic "MCU won't boot" failure.

The piezoelectric heart: why quartz?

Quartz is piezoelectric: squeeze it and it produces a voltage; apply a voltage and it physically deforms. Cut a quartz wafer to precise dimensions and it behaves like an extremely high-Q electromechanical resonator — it "rings" at one very stable frequency, the way a tuning fork rings at one pitch.

"High-Q" means the resonator stores energy efficiently and loses very little per cycle. A typical quartz crystal has a Q factor of 10,000 to over 1,000,000, compared to maybe 100 for an LC tank circuit made of an inductor and capacitor. That enormous Q is why crystals are so stable: the oscillation frequency barely moves with temperature, voltage, or aging. It's also why a 16 MHz crystal keeps your UART baud rate accurate while a cheap RC oscillator would drift off and garble your serial data.

Inside the metal can (or the tiny ceramic package of an SMD crystal) is just the quartz blank with electrodes — no active electronics. The amplification that keeps it oscillating lives inside your microcontroller.

The Pierce oscillator: what's inside your MCU

Nearly every microcontroller uses a Pierce oscillator topology for its external crystal. The MCU provides:

  • An inverting amplifier between the XTAL_IN (input) and XTAL_OUT (output) pins
  • Internal biasing to put the amplifier in its linear region at startup

You provide the rest, externally:

  • The crystal itself, connected between the two pins
  • Two load capacitors, one from each crystal pin to ground

At power-up, thermal noise contains a tiny component at the crystal's resonant frequency. The crystal's high Q amplifies exactly that component, the inverter provides 180° of phase shift, the crystal-plus-capacitors network provides the other 180°, and the Barkhausen criteria are met: loop gain ≥ 1 with 360° total phase shift. Oscillation builds up over hundreds to thousands of cycles until the amplifier saturates and the amplitude stabilizes. That buildup takes time — typically a few milliseconds — which is why MCUs have startup delays and "clock ready" flags before switching to the external crystal.

Note: The capacitors aren't optional accessories. Together with the crystal they set the load the crystal sees, which pulls the oscillation frequency to its specified value. Wrong capacitors = wrong frequency, or no oscillation at all.

Load capacitance: the number that matters most

Every crystal is manufactured to oscillate at its marked frequency when it sees a specific load capacitance (CL) — commonly 18pF, 20pF, or 12pF for MCU crystals. Your job is to present exactly that load.

The load capacitance seen by the crystal is:

CL = (C1 × C2) / (C1 + C2) + Cstray

where C1 and C2 are your two external capacitors and Cstray is the parasitic capacitance of the PCB traces and MCU pins (typically 2–5pF total, often estimated at ~3pF).

With C1 = C2 = C, this simplifies to CL = C/2 + Cstray. So for a crystal specified at CL = 18pF with ~4pF of stray capacitance, you need C/2 = 14pF, i.e. C1 = C2 = 27pF (nearest standard value 27pF).

Common pairings you'll see on real boards:

Crystal CL spec Stray estimate C1 = C2 (calculated) Standard value used
18pF 4pF 28pF 27pF
20pF 4pF 32pF 33pF
12pF 3pF 18pF 18pF
8pF 3pF 10pF 10pF

What happens if you get it wrong? Too much capacitance pulls the frequency low and can prevent startup (the oscillator can't muster enough gain). Too little pulls the frequency high and makes the oscillator marginal — it may start at room temperature and fail when cold. A crystal running at the wrong load can easily be off by tens of ppm, which is enough to break UART communication at high baud rates.

Warning: "Close enough" capacitors are the #1 cause of dead-on-arrival student boards. Always check the crystal's datasheet CL value — don't copy capacitor values from a different crystal's reference design.

Frequency tolerance, stability, and ppm

Crystal specs are quoted in ppm (parts per million). 1 ppm = 0.0001%. To convert ppm to something tangible:

Error per day = ppm × 86.4 milliseconds

So a ±20ppm crystal (typical for a decent SMD crystal) drifts at most ±1.7 seconds per day. A ±50ppm crystal (cheap can type) can drift ±4.3 seconds per day. For UART at 115200 baud, even ±50ppm is fine (UART tolerates ~2–3% error, i.e. 20,000–30,000ppm). For a real-time clock that must keep time for weeks, ppm is everything — which is why RTC crystals are usually 32.768kHz tuning-fork types specified at ±20ppm, and why serious designs use a temperature-compensated oscillator or sync to network time.

Key datasheet terms:

Term Meaning
Frequency tolerance Initial accuracy at 25°C, e.g. ±10ppm
Frequency stability Drift over the temperature range, e.g. ±30ppm from −40 to +85°C
Aging Long-term drift, e.g. ±3ppm/year
ESR (equivalent series resistance) The crystal's internal loss; lower is easier to start. Must be below the MCU oscillator's maximum drive spec
Drive level Power dissipated in the crystal (µW); exceeding it ages the crystal faster

The ESR check matters: a 32.768kHz tuning-fork crystal can have an ESR of 50–70kΩ, and some MCU oscillator circuits can't drive high-ESR crystals reliably. If your RTC crystal won't start, ESR mismatch is a prime suspect — check the MCU datasheet's maximum crystal ESR spec.

Crystal vs resonator vs internal oscillator

Clock source Typical accuracy Cost When to use it
Quartz crystal + load caps ±10 to ±50ppm Low UART, USB, CAN, RF, anything timing-critical
Ceramic resonator ±0.1 to ±0.5% (1,000–5,000ppm) Very low Non-critical timing; has built-in caps, 3-pin package
Internal RC oscillator ±1 to ±5% (worse over temperature) Free (on-chip) Blinking LEDs, simple logic; never for UART at high baud
MEMS oscillator ±10 to ±50ppm Medium Drop-in stability, shock-resistant; needs no load caps
TCXO / OCXO ±0.1 to ±2ppm High Precision timekeeping, not student projects

Practical guidance: if your project uses UART above 9600 baud, USB, CAN bus, or any radio (including the ESP32's WiFi), use a real quartz crystal. The ESP32 and STM32 boards you buy already include one — problems arise when you design your own PCB and substitute a resonator or wrong load caps to save space or money. A ceramic resonator's ±0.5% error will corrupt 115200-baud serial; a crystal's ±20ppm won't.

Layout: keep the heartbeat quiet and stable

The crystal circuit is the most layout-sensitive part of a microcontroller board:

  1. Place the crystal as close as possible to the MCU's XTAL pins. Every millimetre of trace adds stray capacitance and picks up noise.
  2. Keep the two traces short, symmetric, and equal length. Asymmetry unbalances the load and can shift frequency.
  3. Put the load capacitors right next to the crystal, with short traces to a solid ground.
  4. Keep all other signals away. Don't route digital traces under or near the crystal — coupling into the oscillator circuit causes jitter or startup failure. Keep a keep-out zone around it.
  5. Don't cut the ground plane under the crystal. A solid ground beneath provides shielding and a stable reference. (Some RF designs use cutouts for other reasons — not your student MCU board.)
  6. Add a series resistor (Rs) footprint between the MCU output and the crystal, even if you populate it with 0Ω initially. If the oscillator over-drives the crystal (too much amplitude), increasing Rs tames the drive level. Check the crystal's drive-level spec if you suspect this.

Debugging: when the MCU won't boot

Symptom: the MCU seems dead — no clock output, debugger can't connect, or it runs intermittently. Before blaming the firmware:

  • Verify power first. The oscillator won't start on a sagging rail. Scope the supply during startup.
  • Check the load capacitors. Are they the right value for this crystal's CL spec? Are they actually populated? (An unpopulated cap footprint is a classic assembly error.)
  • Probe carefully. A ×10 scope probe adds ~10–15pF to the node — enough to kill a marginal oscillator or shift its frequency. If the circuit only fails when probed, the oscillator was marginal. Use the MCU's clock-output pin (MCO on STM32, CLKOUT on AVR) to observe the clock without loading the crystal.
  • Try the internal oscillator. If the MCU boots on its internal RC clock but not the crystal, you've isolated the problem to the crystal circuit.
  • Check ESR compatibility. Especially for 32.768kHz crystals — verify the crystal's ESR is below the MCU's maximum.
  • Look for contamination. Flux residue between the XTAL pins creates leakage paths that can stop a 32kHz oscillator. Clean the board around the crystal.
  • Verify the crystal isn't damaged. Crystals are fragile; a dropped board can crack the quartz blank. Swap in a known-good crystal as a test.

Choosing a crystal: a worked example

Say you're designing an STM32 board with an 8MHz crystal for the main clock:

  1. Pick a crystal: 8MHz, CL = 20pF, ESR ≤ 80Ω (check against the STM32 datasheet's HSE specs — STM32s typically require ESR under ~100Ω for 8MHz).
  2. Compute load caps: with ~4pF stray, C1 = C2 = 2 × (20 − 4) = 32pF → use 33pF standard value.
  3. Check drive level: if the datasheet lists 100µW max and your measured amplitude suggests more, add series resistance.
  4. Layout: crystal within ~10mm of the HSE pins, caps adjacent, no traces under the crystal, solid ground beneath.
  5. Validate: boot on the crystal, output the clock on MCO, and measure the frequency with a counter or scope. It should be within the crystal's tolerance of 8.000000MHz.

Common mistakes

  • Copying load-capacitor values from a reference design that used a different crystal with a different CL spec.
  • Using a ceramic resonator where UART/USB timing matters.
  • Long, asymmetric crystal traces routed across the board.
  • Forgetting that a scope probe's capacitance can stop a marginal oscillator — then "fixing" the wrong thing.
  • Assuming the crystal is fine because it's a passive component — cracked blanks and cold solder joints happen.
  • Ignoring the 32.768kHz crystal's ESR requirement on the RTC oscillator.

Where to go from here

More project guides

More in Electronics / E&TC