An2867 Guidelines For Oscillator Design On Stm8afals and Stm32 Mcusmpus Stmicroelectronics
An2867 Guidelines For Oscillator Design On Stm8afals and Stm32 Mcusmpus Stmicroelectronics
Application note
Guidelines for oscillator design on STM8AF/AL/S
and STM32 MCUs/MPUs
Introduction
Many designers know oscillators based on Pierce-Gate topology (Pierce oscillators), but not
all of them really understand how they operate, and only a few master their design. In
practice, limited attention is paid to the oscillator design, until it is found that it does not
operate properly (usually when the final product is already in production). A crystal not
working as intended results in project delays, if not overall failure.
The oscillator must get the proper amount of attention during the design phase, well before
moving to manufacturing, to avoid the nightmare scenario of products failing in application.
This document introduces the Pierce oscillator basics, and provides guidelines for its
design. It also shows how to determine the external components, and provides guidelines
for correct PCB design and for selecting crystals and external components.
To speed up the application development, the recommended crystals (HSE and LSE) for the
products listed in Table 1 are detailed in Section 5: Recommended resonators for STM32
MCUs/MPUs and Section 6: Recommended crystals for STM8AF/AL/S MCUs.
Contents
2 Oscillator theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.1 Negative resistance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2 Transconductance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3 Negative-resistance oscillator principles . . . . . . . . . . . . . . . . . . . . . . . . . 10
8 Reference documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
9 FAQs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
10 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
11 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
List of tables
List of figures
A quartz crystal is a piezoelectric device converting electric energy into mechanical energy,
and vice versa. The transformation occurs at the resonant frequency. The quartz crystal can
be modeled as shown in Figure 1.
C0
Q
Lm Rm Cm
MS36117V1
• C0 represents the shunt capacitance resulting from the capacitor formed by the
electrodes
• Lm (motional inductance) represents the vibrating mass of the crystal
• Cm (motional capacitance) represents the elasticity of the crystal
• Rm (motional resistance) represents the circuit losses
The impedance of the crystal (assuming that Rm is negligible) is
2
(1) j w × Lm × Cm – 1
Z = ---- × ------------------------------------------------------------------------------------------
w 2
( C0 + Cm ) – w × Lm × Cm × C0
Impedance
Area of parallel
resonance: Fp
Inductive behavior:
the quartz oscillates
Fs Fa
Capacitive behavior: Frequency
no oscillation
Phase (deg)
+90
Frequency
–90
ai15834c
Fs is the series resonant frequency when Z = 0. Its expression can be deduced from
equation (1) as follows:
(2) F 1
= -----------------------------
s 2π L m C m
Fa is the antiresonant frequency when Z tends to infinity. Using equation (1), it is expressed
as follows:
(3) Cm
F a = F s 1 + ---------
C0
The region delimited by Fs and Fa (shaded area in Figure 2) is the area of parallel
resonance. In this region, the crystal operates in parallel resonance and behaves as an
inductance that adds an additional 180° phase to the loop. Its frequency Fp (or FL: load
frequency) has the following expression:
(4) ⎛ Cm ⎞
F = F ⎜ 1 + -----------------------------
-⎟
p s⎝ 2 ( C + C )⎠
0 L
According to this equation, the oscillation frequency of the crystal can be tuned by varying
the load capacitance CL. This is why, in their datasheets, crystal manufacturers indicate the
exact CL required to make the crystal oscillate at the nominal frequency.
Table 2 gives an example of equivalent crystal circuit component values for an 8 MHz
nominal frequency.
Rm 8Ω
Lm 14.7 mH
Cm 0.027 pF
C0 5.57 pF
Using equations (2), (3), and (4), it is possible to calculate Fs, Fa, and Fp of this crystal:
• Fs = 7988768 Hz
• Fa = 8008102 Hz
If the load capacitance CL is equal to 10 pF, the crystal oscillates at Fp = 7995695 Hz.
To have an oscillation frequency of exactly 8 MHz, CL must be 4.02 pF.
2 Oscillator theory
Oscillators are among the backbone components of modern digital ICs. They can be
classified into different subfamilies, depending upon their topology and operating principles.
For each subfamily there is a mathematical model that can be used to study the oscillator
behavior, and theoretically determine its performance.
This section deals only with harmonic oscillators (relaxation oscillators are out of the scope
of this document), with particular focus (see Section 3) on Pierce oscillators. This is
because all the oscillators requiring external passive components (resonator, load
capacitors, etc.) covered by this document are of the previously mentioned type and
topology.
The harmonic oscillator family can be divided into two main subfamilies:
• negative-resistance oscillators
• positive-feedback oscillators.
These two subfamilies of oscillators are similar for what concerns the output waveform.
They deliver an oscillating waveform at the desired frequency. This waveform is typically
composed of a fundamental sine wave of the desired frequency, plus a sum of overtone
harmonics (at frequencies multiple of the fundamental one), due to the nonlinearity of
components of the oscillation loop.
The two subfamilies differ in their operating principles. A specific mathematical model
describes and analyzes each of them.
Positive-feedback oscillators are usually modeled using the Barkhausen model, where an
oscillator must fulfill the Barkhausen criterion to maintain a stable oscillation at the desired
frequency.
The Barkhausen model is not fully adequate to describe negative-resistance oscillators: the
most suitable approach is to use the negative-resistance model described in [1].
STM32 microcontrollers and microprocessors (based on Arm®(a) cores) feature low-speed
external (LSE) and high-speed external (HSE) oscillators designed according to the
negative-resistance principle, hence this section focuses on the presentation of this model.
a. Arm is a registered trademark of Arm Limited (or its subsidiaries) in the US and/or elsewhere.
The term negative resistance is a misnomer of negative transresistance, defined as the ratio
between a given voltage variation (∆V) and the induced current variation (∆I). Unlike the
resistance, always positive, the transresistance (also known as differential resistance) can
be either positive or negative. Figure 3 shows the current-voltage curve for a dipole with a
negative transresistance region. It is obvious that the V/I ratio is always positive, this is not
the case for the ∆V/∆I ratio.
The portion of the I-V curve in purple shows a negative transresistance:
ΔV V(D) – V(C)
-------- = --------------------------------- < 0
ΔI I(D) – I(C)
2.2 Transconductance
Similarly to the conductance, defined as the inverse of the resistance, the transconductance
is defined as the inverse of the transresistance. Transconductance can also be defined as
the differential conductance, expressed as ∆I / ∆V.
Xtal
STM32
C
MSv36188V1
According to the small signals theory, when the active branch (oscillator part) is correctly
biased, to maintain a stable oscillation around the oscillator biasing voltage the latter must
have its transconductance equal to the passive branch conductance.
However, at startup, the oscillator transconductance must be higher than (multiple of) the
conductance of the passive part of the oscillation loop, to maximize the possibility to build up
the oscillation from the inherent noise of the loop. An excessive oscillator transconductance
compared to the oscillation loop passive branch conductance can saturate the oscillation
loop, and cause a startup failure.
To ensure the successful oscillator start, and to maintain stable oscillation, the ratio between
the negative resistance of the loop and the crystal maximal equivalent series resistance
(ESR) is specified for STM32 and STM8 products. It is recommended to have a ratio higher
than 5 for the HSE oscillators, and higher than 3 for the LSE oscillators.
This section describes the different parameters, and how to determine their values to be
compliant with the Pierce oscillator design.
Microcontroller
RF
In v
OSC_IN OSC_OUT
R Ext
Q
C L1 Cs C L2
ai15836b
area in Figure 6). The noise (for example, the thermal noise of the crystal) is amplified within
the range of serial to parallel frequency (Fa, Fp), thus starting the oscillation.
Vout
VDD
Saturation Saturation
region region
Vin
~VDD/2 V DD
ai15837b
32.768 kHz 10 to 25 MΩ
1 MHz 5 to 10 MΩ
10 MHz 1 to 5 MΩ
20 MHz 470 kΩ to 5 MΩ
C L1 × C L2
C L = -----------------------------
- + Cs
C L1 + C L2
C L1 × C L2
C L – C s = ------------------------------ = 10 pF
C L1 + C L2
where:
• ESR is the equivalent series resistance
• C0 is the crystal shunt capacitance
• CL is the crystal nominal load capacitance.
• F is the crystal nominal oscillation frequency
For example, to design the oscillation loop for the HSE oscillator embedded in an STM32F1
microcontroller with a transconductance value (gm) of 25 mA/V, we choose a quartz crystal
from Fox, with the following characteristics:
• Frequency = 8 MHz
• C0 = 7 pF
• CL = 10 pF
• ESR = 80 Ω
To check if this crystal oscillates, let us calculate gmcrit:
6 2 – 12 – 12 2
g mcrit = 4 × 80 × ( 2 × π × 8 × 10 ) × ( 7 × 10 + 10 × 10 ) = 0.23 mA ⁄ V
The gain margin is sufficient to start the oscillation and the gainmargin > 5 condition is met.
The oscillator is expected to reach stable oscillation after the typical delay specified in the
datasheet.
If an insufficient gain margin is found (gainmargin < 5), the oscillation can start when
designing and testing the final application, but this does not guarantee that the oscillation
starts in operating conditions. It is highly recommended that the selected crystal has a gain
margin higher than or equal to 5 (try to select a crystal with a lower ESR and/or a lower CL).
In a second example of the case where the maximal critical crystal transconductance is
given, the HSE oscillator embedded in STM32G0 microcontrollers has Gm = 1.5 mA/V. gmcrit
for the implemented oscillator must stay below this value. The Fox quartz crystal described
above respects this condition.
The conversion between the oscillator transconductance (gm) and the oscillation loop
maximal critical transconductance (Gm_crit_max) is given by Gm_crit_max = gm / 5.
Note: Before any verification, the crystal chosen must vibrate at a frequency that respects the
oscillator frequency range given in the STM32 datasheet.
2
The drive level is given by the formula: DL = ESR × I Q , where:
• ESR is the equivalent series resistor (specified by the crystal manufacturer):
C 2
ESR = R m × ⎛⎝ 1 + ------0-⎞⎠
C L
• IQ is the current flowing through the crystal in RMS. This current can be displayed on
an oscilloscope as a sine wave. The current value can be read as the peak-to-peak
value (IPP). When using a current probe (as shown in Figure 7), the voltage scale of an
oscilloscope may be converted into 1 mA / 1 mV.
Crystal
To oscilloscope
Current probe
ai15838b
So, as described previously, when tuning the current with the potentiometer, the current
through the crystal (assuming it is sinusoidal) does not exceed IQmax RMS, given by:
DL max I Qmax PP
I Qmax RMS = ----------------- = -----------------------
-
ESR 2 2
Therefore, the current through the crystal (peak-to-peak value read on the oscilloscope)
should not exceed a maximum peak-to-peak (IQmaxPP) equal to:
2 × DL max
I Qmax PP = 2 × ---------------------------
-
ESR
Hence, the need for an external resistor RExt (refer to Section 3.5.3) when IQ exceeds
IQmaxPP. The addition of RExt becomes mandatory, and is added to ESR in the expression
of IQmax.
remains the same, and is equal to ± 5%. If we consider that all the remaining contributors to
the CL are maintained to their nominal values at design stage (to assess the frequency shift
magnitude induced only by load capacitor tolerances), then the load capacitance seen by
the crystal (CL) either decreases by 0.175 pF, or increases by the same value. This induces
an oscillation shift of:
0.175 pF × 45 PPM / pF = ~7.8 PPM (~0.7 s/day for a time-keeping function such as RTC)
The above example shows that lower pullability results in lower impact of small load
capacitance deviation on the frequency shifting. Crystal pullability is an important factor
when defining the final application PPM budget.
6
C m × 10
Pullability ( PPM ⁄ pF ) = -----------------------------------------
2
2 × ( C0 + CL )
where
• Cm is the crystal motional capacitance (in pF)
• C0 is the crystal shunt capacitance (in pF)
• CL is the crystal nominal load capacitance (in pF)
The following sections give a more detailed description on how to calibrate the oscillation
frequency, and how to estimate the final accuracy uncertainty (PPM) budget.
3.8.1 Definition
Resonators (such as crystal resonators) undergo aging effects that manifest themselves
over time in deviations of resonator parameters from the values defined by the
specifications. Among the impacted parameters there is the resonator ESR, whose value
depends upon the environment conditions, such as moisture and temperature. The
oscillator transconductance depends upon the power supply voltage and upon the
temperature.
The safety factor parameter enables to determine the oscillator safe operation under the
operating conditions and during the application life. It measures the ability of the oscillator
not to fail under operating conditions.
The safety factor is defined as the ratio between the oscillator negative resistance and its
ESR:
STM32
Q RADD
CL1 CL2
MSv37268V1
The oscillator negative resistance is the value of the smallest series resistance RADD
preventing the oscillator from starting up successfully.
In practice, this value is set by conducting a series of experiments in which the value of the
series resistance is slightly increased compared to the previous experiment. The sequence
stops when the oscillator is unable to start correctly. The oscillator negative resistance is
equal to the value of the added series resistance.
3 ≤ Sf < 5 Safe
Not safe
Sf < 3 Not safe
1. Safe and very safe oscillations are shown in green, unsafe oscillation in yellow.
Note: AT-cut quartz corresponds to most of the crystals to use with HSE. For LSE, tuning fork
crystals can be used, but they do not show the same oscillation mode possibilities (Figure 9
is not valid for them). In this part, we consider an AT-cut quartz crystal when referring to a
crystal.
This multiple-time cancellation is because a more accurate quartz crystal theoretical model
shows an RLC branch for each one of its overtone modes, as illustrated in Figure 10.
C0
=
Lm Rm Cm
Q
Fundamental mode
For example, it is possible to use the third overtone mode by implementing the oscillator as
shown in Figure 11, to suppress the fundamental frequency (theoretically each overtone
mode can be selected by suppressing the previous ones).
Microcontroller RF
Inv
OSC_IN OSC_OUT
RExt
Q
MS55484V1
The model for a crystal operating in third overtone mode (Figure 11) shows a resistance Rm
approximately three times higher and a capacitance Cm nine times lower than those
associated with the fundamental mode.
For the third overtone mode, these differences mean a higher Q-factor since the quality
factor for an RC series circuit is 1 / ωRC (less energy loss, more stable performances, better
jitter, and lower pullability, see Section 3.7). A lower pullability means a lower frequency shift
when the application is deployed in the field, at the expense of lower tunability of the
oscillation frequency.
High
Crystal load capacitance
(12.5 pF)
Low drift
Low power
Low
(S)
Low Medium High
A resonator with a relatively high load-capacitance (such as 12.5 pF) requires more power
for the oscillator to drive the oscillation loop at the resonator nominal frequency. Designs
targeting low power consumption (for example, RTC application powered by coin-batteries
requiring very long autonomy) are consequently more likely to use resonators with relatively
small load capacitance. On the other side, big load capacitance resonators have a much
smaller pullabilty compared to resonators with small load capacitance. As a result, designs
without severe constraints on power consumption tend to use big load capacitance crystals
to reduce pullability.
One of the key areas where crystal resonators are massively used is the hand-held and
wearable appliance consumer market (such as smartphones, Bluetooth® kits). For this
market segment, the crystal size is of critical importance. However, it is widely known that
small-footprint crystals come with high crystal ESR. The choice may be harder if the target
design has severe constraints in terms of power consumption (the usual scenario). In this
case, choose a crystal with a load capacitance as small as possible to optimize power
consumption even if this compromises pullabilty. In addition, crystals with high ESR may
have a slightly longer startup time. If there are no constraints on crystal size, then it is
recommended to choose a crystal with the smallest possible ESR.
In noisy environments (almost always the case for industrial applications), if there are no
constraints on power consumption, it is recommended to choose crystals with high load
capacitance. These crystals require a high-drive current from the oscillator, but are more
robust against noise and external perturbations. Another advantage is that the design
pullability is minimized.
Depending on the device used, all the resonator families listed below can be compatible
with your design, or only some of them. STM32 devices embed two types of low-speed
oscillator (LSE):
• Constant gain
This type of LSE oscillator features a constant gain, which makes them compatible only
with a few crystal groups mentioned above. For example, LSE oscillators embedded in
STM32F2 and STM32L1 MCUs target designs with severe power consumption
constraints. The selected crystal should consequently have a low load capacitance and
a moderate ESR. LSE oscillators embedded in STM32F1 MCUs target crystal
resonators with moderate ESR and moderate load capacitance.
• Configurable gain
The main advantage of LSE oscillators belonging to this family is the compatibility with
a large number of crystals. Almost no constraint comes by the device embedding this
kind of oscillator. The large list of compatible resonator crystals allows the designer to
focus on design constraints (such as power consumption, footprint) when selecting a
compatible resonator. These oscillators are divided into two categories:
– Dynamically (on-the-fly) modifiable gain LSE oscillators
The gain of this type of LSE oscillators can be changed either before starting the
oscillator or after enabling it.
– Statically modifiable gain LSE oscillators
The gain can be changed only when the LSE oscillator is turned off. If the
oscillator transconductance has to be increased or decreased, the LSE must be
turned off first.
Table 5 gives the list of low-speed oscillators (LSE) embedded in STM32 devices.
Caution: When the gain is modified statically or on-the-fly, the calibration of the oscillation frequency
must be readjusted to estimate the final accuracy uncertainty (PPM) budget.
Caution: In STM32F0 and STM32F3 MCUs, High drive mode (gm = 25 µA/V) must be used only with
12.5 pF crystals, to avoid saturating the oscillation loop and causing a startup failure. When
used with a low CL crystal (for example 6 pF), the oscillation frequency jitters and duty cycle
can be distorted.
Step 2: Determine the capacitance value of the load capacitors CL1 and CL2
To determine the correct capacitance values for CL1 and CL2 load capacitors, apply the
formula specified in Section 3.3. The values obtained are approximations of the exact
capacitances to be used. In a second phase, to fine-tune the values of the load capacitors,
go through a series of experimental iterations, until the right capacitance values are found.
During the experimental phase, use a standard crystal, one whose PPM drift is well known
when it is loaded by the crystal nominal load capacitance (CL). This kind of crystal can be
provided by the manufacturer upon request. After this crystal has been chosen, calculate its
oscillation frequency (Fstandard) when the crystal is loaded by its nominal load capacitance.
This frequency is given by the formula:
6
F = F × ⎛ PPM ⁄ 10 ⎞
s tan dard nominal ⎝ s tan dard ⎠
where:
• Fstandard is the standard crystal oscillation frequency when it is loaded by its nominal
load capacitance
• Fnominal is the oscillation nominal frequency specified in the crystal datasheet
• PPMstandard is the oscillation frequency drift of the standard crystal, as characterized by
the crystal manufacturer
where:
• PPMBudget is the estimated accuracy for the oscillation frequency
• PPMcrystal is the crystal PPM accuracy specified in the datasheet
Deviation (CL) is expressed in pF. It measures the deviation of the load capacitance (CL)
due to tolerances on load capacitor values and the variation of the stray capacitance (CS)
due to PCB manufacturing process deviation.
Pullabilty is expressed in PPM / pF (refer to Section 3.7).
Note: The PPM budget calculated above does not take into account the temperature variation,
which can make the PPM budget bigger.
Frequency
4 - 32 4 - 16 4 - 25 4 - 26 4 - 26 1 - 25 1 - 24 4 - 48 4 - 50 16 - 48 16 - 48 MHz
range
gm (min) 10 25 5 5 5 3.5 3.5 7.5 7.5 12.5 9.57
mA/V
Gm_crit_max 2 5 1 1 1 0.7 0.7 1.5 1.5 2.5 1.95
a. This is not applicable for STM32WB, STM32WB0, STM32WBA and STM32WL series due to the RF
constraints. For information about HSE oscillator compatibility with these devices, refer to Precise HSE
frequency and startup time tuning for STM32 wireless MCUs (AN5042), available on www.st.com.
Different footprints are provided to facilitate crystal selection, even if there are geometric
constraints for the final application.
To measure and verify the safety factor of oscillators in STM32 products, methodologies include analyzing the gain margin ratio, ensuring it is above 5, and comparing the oscillator's transconductance (gm) against the maximum critical transconductance (Gm_crit_max). The methodologies ensure enough starting energy and maintain oscillation under specified conditions by checking transconductance parameters and evaluating their adequacy in compensating loop losses .
Startup time challenges in oscillator circuits include achieving quick and reliable oscillation initiation and avoiding prolonged startup periods which may affect system performance. These can be addressed by optimizing the gain margin to ensure adequate energy is supplied to overcome loop losses quickly, using appropriate external resistor values to reduce overdrive, and maintaining stable environmental conditions to prevent undue effects from temperature and capacitance variations .
When selecting a crystal for STM32 microcontrollers, key considerations include ensuring compatibility with STM32 products, confirming the frequency and load capacitance as per the datasheet, verifying the gain margin ratio is bigger than 5, checking the equivalent series resistance (ESR) and ensuring it is lower or equal to that specified for the crystal, and adjusting the drive level to be within the crystal manufacturer's specifications . Additionally, noise and temperature variations should be considered as they can affect oscillation stability .
ESR impacts the performance by influencing the crystal's ability to maintain stable oscillation; higher ESR can increase losses and reduce the oscillation margin. Managing ESR involves selecting crystals with lower ESR values within manufacturer specifications and optimizing the gain margin during design. This involves careful selection of circuit components and layout to ensure minimal impact from equivalent series resistance on overall stability and performance .
The gain margin ratio is crucial for ensuring that an STM32 oscillator circuit has the necessary energy to compensate for the loop losses and maintain stable oscillation. It is calculated using the formula gainmargin = gm/gmcrit, where gm is the oscillator transconductance specified in the datasheet, and gmcrit is derived from passive components parameters such as ESR, C0, and CL. An acceptable gain margin ratio should be greater than 5 to guarantee steady oscillation under operational conditions .
The drive level affects both performance and reliability by determining the power dissipated in the crystal. If the drive level exceeds the specifications set by the crystal manufacturer, it can cause excess power dissipation, potentially leading to crystal damage or accelerated aging. Conversely, a drive level too low can prevent the oscillator from starting up effectively. Proper selection and calculation ensure the oscillator functions within its limits, maintaining performance and longevity .
The load capacitance in a crystal oscillator circuit determines the accuracy of the oscillator's frequency. It's composed of external capacitors (CL1 and CL2) and stray capacitances (Cs). For accuracy, the oscillator must present a load capacitance equal to the value at which the crystal was calibrated by the manufacturer. This ensures that the frequency is stable and reflects the intended specification .
The fundamental oscillation mode is typically used for low-frequency applications, providing a straightforward implementation with fewer complexities and stability issues. In contrast, the third overtone mode can be used for higher frequencies but introduces additional complexity, such as spurious modes and higher power consumption. It requires more careful design consideration to avoid unwanted harmonics, making it less ideal for simple applications .
Load and stray capacitance parameters affect oscillation stability by altering the effective capacitance seen by the crystal. Variations in these parameters can lead to frequency deviations from the crystal’s intended specification, affecting stability. To maintain stability, the sum of load and stray capacitances must match the value the crystal is trimmed for. Oscillation stability is thus reliant on maintaining consistent capacitance values despite manufacturing tolerances and environmental changes .
The criteria for selecting high-speed versus low-speed resonators involve the frequency requirements of the application, power consumption constraints, and compatibility with specific STM32 microcontroller series. High-speed resonators are typically chosen for applications requiring fast processing and data transfer, while low-speed resonators are used in low-power or real-time clock applications. Additionally, compatibility with series specifications like frequency range and PLL unlocking conditions must be considered .