A crystal oscillator is an electronic oscillator that uses the mechanical resonance of a piezoelectric crystal (typically quartz) to generate a highly stable, precise clock frequency. The crystal's physical geometry determines its resonant frequency, making it far more accurate and temperature-stable than RC or LC oscillators.
In practice
Crystal oscillators appear in embedded systems wherever accurate timing is required: as the primary clock source for an MCU, as the dedicated time-base for a real-time clock (RTC) peripheral, or as the reference for a USB or Ethernet PHY. A 32.768 kHz crystal is the standard choice for RTC applications because that frequency is exactly 2^15 Hz, allowing a simple 15-bit counter to produce a 1-second tick with minimal hardware. Higher-frequency crystals (4 MHz to 25 MHz and above) are used as the main system oscillator, often feeding an on-chip PLL to reach the MCU's full operating frequency.
In practice, the crystal is an external passive component. Most MCUs provide the inverting amplifier (oscillator circuit) internally, so the crystal, two load capacitors, and optional series resistor are placed on the PCB; however, some MCUs expect a clock input from a packaged oscillator and provide no on-chip amplifier, and others offer configurable oscillator modes. Getting the load capacitance right is one of the most common sources of frequency error: the two external capacitors must match the crystal's specified load capacitance (CL), and stray PCB capacitance must be included in that calculation. Poor layout, long traces, or nearby switching signals are frequent culprits when a crystal oscillates at the wrong frequency or fails to start.
For RTC use cases, a 32.768 kHz crystal is extremely sensitive to parasitic capacitance and PCB leakage currents because the oscillator drive level is intentionally kept very low to minimize power consumption. Placing the crystal close to the MCU pins, using a ground guard ring, and avoiding other signals on adjacent layers are standard practices. The blog posts "A Working Real Time Clock (RTC) Implementation" and "Real-time clocks: Does anybody really know what time it is?" cover the practical pitfalls of RTC crystal circuits in detail.
An alternative to a discrete crystal is a pre-packaged crystal oscillator module (TCXO, VCXO, or OCXO), which contains the crystal and oscillator circuit in a single component and provides a buffered clock output. These modules cost more but eliminate layout sensitivity and provide tighter frequency tolerance over temperature, which matters for USB, CAN, or communications peripherals that have strict clock accuracy requirements.
Discussed on EmbeddedRelated
Frequently asked
What is the difference between a crystal and a crystal oscillator module?
A crystal (or quartz crystal) is a passive two-terminal resonator. It requires an external oscillator circuit, usually built into the
MCU, plus load capacitors to oscillate. A crystal oscillator module is a complete, self-contained device (commonly offered in 3- or 4-pin packages with pins for
Vcc, GND, output, and sometimes an enable signal) that includes the crystal, the oscillator circuit, and output buffering. The module needs only power and ground and directly produces a logic-level clock signal, but it costs significantly more and draws more current.
Why is 32.768 kHz the standard frequency for RTC crystals?
32.768 kHz equals 2^15 Hz. A 15-stage binary counter driven by this frequency overflows exactly once per second, producing a 1 Hz tick with no complex division logic. This makes it trivial to implement accurate seconds counting in hardware, which is why virtually every
RTC peripheral and dedicated RTC IC is designed around this frequency.
What are load capacitors, and how do I choose their values?
Load capacitors (C1 and C2) are the two capacitors placed from each crystal pin to ground. They form a capacitive voltage divider that presents the correct load to the crystal so it resonates at its specified frequency. The relationship is: C_L(spec) = (C1 * C2) / (C1 + C2) + Cstray. When C1 equals C2 (call each value C), the formula simplifies to C_L(spec) = C/2 + Cstray, so you choose C = 2 * (C_L(spec) - Cstray). The crystal's datasheet specifies its required C_L(spec). Using wrong values shifts the oscillation frequency and can prevent startup. Stray PCB capacitance is typically estimated at 2 to 5 pF but should be measured or simulated for precision designs.
Can I use the MCU's internal RC oscillator instead of a crystal?
Yes, for many applications. Internal RC oscillators are convenient and save cost and board space, but they are typically accurate only to 1% to 3% over temperature and voltage unless trimmed. This is insufficient for
UART communication at higher
baud rates,
USB (which requires 0.25% or better at full-speed 12 Mbps; the required tolerance varies by USB speed and device role),
CAN, or any timekeeping application. Use a crystal when frequency accuracy or long-term stability matters.
What causes a crystal to fail to start oscillating?
Common causes include incorrect load capacitance values, excessive series resistance in the oscillator loop (check the
MCU's maximum allowable ESR against the crystal's ESR), a crystal with a resonant frequency outside the oscillator circuit's tuning range, excessively long or poorly routed PCB traces adding parasitic capacitance, and insufficient oscillator drive strength. Some MCUs allow configuring the oscillator gain; setting it too low for a given crystal is a frequent startup failure mode.
Differentiators vs similar concepts
Crystal oscillators are often confused with ceramic resonators, which are also piezoelectric but use a ceramic material instead of quartz. Ceramic resonators are cheaper and many include built-in load capacitors (though some parts still recommend or require external components, so always check the datasheet), but they are significantly less accurate (0.5% vs. 10 to 50 ppm for a quartz crystal) and have worse temperature stability. Crystal oscillators are also distinct from crystal oscillator modules (TCXOs, VCXOs, OCXOs): a bare crystal is a passive resonator requiring an external drive circuit, while oscillator modules are active, self-contained components that output a buffered clock signal directly.