Ground Embedded KO Subscribe

Notes / Practical Components

Crystals and oscillators: the source of the MCU clock

The internal RC oscillator has an error of 1 to 2%, which is not enough for UART, USB or CAN. Calculating crystal load capacitors and placing the parts.

GROUND EMBEDDED · NOTEPractical Components 04Crystals and oscillatorsVCC 3.3V10kΩButtonMCUGPIOHIGH when released

Why an external crystal

The MCU's internal RC oscillator (HSI) varies by more than 1% with temperature and voltage. UART needs an error within 2 to 3%, CAN within 0.5%, and USB within 0.25%. So boards where communication matters use an external crystal (HSE).

Crystal and oscillator

  • Crystal (passive): works together with the MCU's internal oscillator circuit. Needs two load capacitors
  • Oscillator (active): outputs a clock by itself once powered. More expensive, but easier to design in
RoadmapSee where this note sits in Practical Components→

Load capacitor calculation

MCU OSC_INC1 → GNDCrystalC2 → GNDMCU OSC_OUT
One load capacitor on each side of the crystal. The value is calculated from the crystal's CL.

Match the load capacitance CL in the crystal's datasheet (for example 12 pF).

C1 = C2 = 2 × (CL - Cstray)

Taking the stray capacitance Cstray of traces and pins as 3 to 5 pF, 2 × (12 - 4) gives about 16 pF. With the wrong value the frequency is off by tens of ppm, or oscillation starts late.

Placement

  • Crystal right next to the MCU pins, traces as short as possible
  • Surround it with ground on the layer below and around it, and do not route other signals nearby
  • Keep the capacitors' ground connections short too

Failure to oscillate at low temperature happens from time to time, so check prototypes with freeze spray or a chamber.

FREE PDFGet the 3 free ebooksIf you want to keep reading this topic as one book: BLDC motor control, serial communication and sensors at book length. PDFs are in Korean.Get them free →