FPGARelated.com

Oscillator

Category: Io-and-clocking

An oscillator is a circuit or device that produces a periodic signal, typically a square, sine, or clock waveform, without any external input signal driving it. In embedded systems, oscillators are the primary source of the clock signal that drives the CPU, peripherals, and timers.

In practice

Oscillators appear in virtually every embedded design as the system's timing reference. The most common types seen in MCU designs are RC oscillators (integrated inside the chip), ceramic resonators, crystal oscillators (XO), and temperature-compensated crystal oscillators (TCXO) or oven-controlled crystal oscillators (OCXO) for tighter accuracy. Most MCUs include at least one internal RC oscillator that works without any external components, which is convenient for low-cost or space-constrained designs, though internal RC oscillators typically carry 1-5% frequency tolerance and are sensitive to temperature and voltage variation. Many MCUs also expose dedicated oscillator input pins (XTAL_IN/XTAL_OUT or OSC_IN/OSC_OUT) for connecting an external crystal or resonator to improve accuracy.

Crystal oscillators are frequently used when precise timing is required, such as for USB (which requires better than 0.25% tolerance on full-speed links), UART baud rate generation, or real-time clocks. A 32.768 kHz crystal is a near-universal choice for RTC peripherals because it is a power of two in hertz, allowing integer prescaler chains to derive a 1 Hz tick. Higher-frequency crystals, commonly 8 MHz, 12 MHz, or 25 MHz, are used as the reference input to an on-chip PLL that multiplies up to the main CPU clock frequency, such as 72 MHz on the STM32F103 or 168 MHz on the STM32F4.

A common pitfall is incorrect load capacitance. Every crystal has a specified load capacitance (typically 6-20 pF), and the PCB capacitors on each oscillator pin must be matched to this spec, accounting for parasitic capacitance from the PCB traces. Mismatched load capacitance causes the oscillator to run off-frequency or fail to start. Another issue is over-driving the crystal: MCU oscillator drive strength must be appropriate for the crystal's rated drive level (in microwatts), as excess drive causes frequency pulling, aging acceleration, or crystal damage.

For applications requiring synchronization to an external reference, such as GPS 1PPS signals or a network clock, a DPLL (digital phase-locked loop) can be used to discipline a local oscillator to track the reference, a technique covered in the blog post "Use DPLL to Lock Digital Oscillator to 1PPS Signal." In FPGA designs, the clock source and its routing topology are critical architectural decisions, as explored in "Designing a FPGA Micro Pt2 - Clock and Counter build and test."

Frequently asked

What is the difference between an oscillator and a crystal?
A crystal (quartz resonator) is a passive component that resonates at a precise frequency but requires an amplifier circuit to sustain oscillation. An oscillator is a complete self-contained circuit that combines the resonator (or an RC network) with the amplifier to produce a clock output. Most MCUs integrate the amplifier internally and only need an external crystal connected to their oscillator pins. A packaged crystal oscillator module (XO, TCXO, OCXO) integrates both into a single 4-pin component with a direct clock output.
When should I use the internal RC oscillator instead of an external crystal?
Use the internal RC oscillator when cost, PCB space, or BOM complexity are the main concerns and the application tolerates 1-5% frequency variation. Suitable examples include general-purpose GPIO toggling, slow SPI/I2C communication where the peripheral sets the clock, or ADC sampling where absolute sample rate is not critical. Avoid relying solely on the internal RC oscillator for USB, UART at high baud rates, CAN, Ethernet, or any protocol with tight tolerance requirements.
What load capacitors do I need for my crystal?
The crystal datasheet specifies a load capacitance CL (commonly 6 pF, 8 pF, 12 pF, or 18 pF). Each capacitor placed on the XTAL_IN and XTAL_OUT pins should typically be 2 x (CL minus the estimated stray capacitance from PCB traces, usually 2-5 pF). For example, with CL = 12 pF and 3 pF stray, each capacitor is approximately 2 x (12 - 3) = 18 pF. Exact values should be validated by measuring actual oscillator frequency on the target PCB, since stray capacitance varies with layout.
Why does my MCU have both a high-speed and a low-speed oscillator?
Many MCUs with an RTC or low-power sleep modes provide separate high-speed and low-speed clock sources. On STM32 devices, for example, the high-speed sources (HSE, an external crystal input, and HSI, an internal RC oscillator) drive the CPU and high-speed peripherals and consume significant power. The low-speed external source (LSE, typically a 32.768 kHz crystal) or the low-speed internal RC oscillator (LSI, whose frequency varies by device and is typically not 32.768 kHz) keeps the RTC running during deep sleep when the main clock tree is stopped. Separating them allows the system to wake from sleep based on a timer tick without powering the full clock tree.
What causes an oscillator to fail to start?
Common causes include incorrect load capacitors (too large reduces gain margin, too small pulls frequency), excessive PCB trace length or stray capacitance on the oscillator pins, an oscillator drive strength setting that is too low or too high for the crystal's rated characteristics, a damaged crystal (often from ESD or over-drive), and ground or power supply noise coupling into the oscillator loop. Placing the crystal and its capacitors as close as possible to the MCU oscillator pins and providing a solid local ground return reduces most layout-related failure modes.

Differentiators vs similar concepts

Oscillator vs. clock source: in datasheets and reference manuals, 'clock source' is a broader term that includes the oscillator output, PLL output, and divided clocks; the oscillator specifically refers to the signal-generating stage before any multiplication or division. Oscillator vs. resonator: a ceramic or crystal resonator is the passive frequency-selective element; it requires an external or on-chip amplifier to form a complete oscillator. Oscillator vs. PLL: a PLL is not itself an oscillator but uses a voltage-controlled oscillator (VCO) internally and multiplies or synthesizes a new frequency from a reference oscillator input.