The STM32F10xxx microcontrollers offer the possibility of running from an internal RC
oscillator (HSI: high-speed internal oscillator of 8 MHz, typically). At 25 °C, the HSI has an
accuracy of ±1% typically. In the range of –40 to 105 °C, the accuracy value of the RC
frequency increases to the maximum value of ±3%. Temperature therefore has an impact on
RC accuracy.
To compensate for the influence of temperature in the application, the output frequency of
the STM32F10xxx HSI oscillator can be further trimmed by the user runtime calibration
routine to improve the HSI frequency accuracy. This may prove crucial for communication
peripherals.
This application note gives two methods of calibrating the internal RC oscillator: finding the
frequency with the minimum error or finding the maximum allowed frequency error. Both are
implemented by providing an accurate reference source such as an RTC/64 signal or a
mains source signal.
Both methods are based on the same technique: computing of the RC frequency vs. the
reference frequency, computing of the HSI frequency error and setting of the HSITRIM bits
in the RCC_CR register.
Figure 7.RC calibration flowchart: calibration with the maximum allowed frequency error. . . . . . . . 15
4/22
AN2868STM32F10xxx’s internal clock: HSI clock
1 STM32F10xxx’s internal clock: HSI clock
The HSI clock signal is generated from an internal 8 MHz RC oscillator and can be used
directly as a system clock or divided by 2 to be used as a PLL input. The HSI RC oscillator
has the advantage of providing a clock source at low cost (no external components). It also
has a faster startup time than the HSE crystal oscillator. However, even with calibration the
frequency is less accurate than an external crystal oscillator or ceramic resonator. The HSI
signal can also be used as a backup source (auxiliary clock) if the HSE crystal oscillator
fails.
1.1 Calibration
RC oscillator frequencies may vary from one chip to another due to manufacturing process
variations. For this reason, each device is factory-calibrated by ST for 1% accuracy at T
25 °C.
After reset, the factory calibration value is loaded into the HSICAL[7:0] bits in the clock
control register RCC_CR.
User calibration is performed by setting the HSITRIM[4:0] bits in the RCC_CR register.
These
bits can be programmed to take into account voltage and temperature variations that
affect the frequency of the internal HSI RC oscillator. The default value is 16, which, when
added to the HSICAL value, should trim the HSI to 8 MHz ±1%. The trimming step (F
is around 40 kHz between two consecutive HSICAL steps.
=
A
hsitrim
)
5/22
RC calibrationAN2868
TimerPeriodCountN 1–()65535×Capture1+=
Frequency
RC
TimerPeriodCountFrequency
Ref
×=
Error Hz() FrequencyRC8000000–=
2 RC calibration
2.1 Principle of calibration
The principle of calibration consists in first measuring the HSI frequency, then computing the
frequency error, and finally setting the HSITRIM bits in the RCC_CR register.
The HSI frequency is not measured directly, but it is estimated from the number of HSI clock
pulses counted using a timer, and compared to an ideal value: 8 000 000 Hz. To do so, a
very accurate reference frequency must be available such as the RTC/64 signal provided by
the external 32 kHz crystal or the 50 Hz/60 Hz of the mains (refer to Section 2.2.2). In the
case of an RTC clock source, the reference frequency is equal to 512 Hz (32768 Hz/64).
Figure 1 shows how the reference signal period is measured in number of timer counts.
Figure 1.Quantification of the reference signal period (RTC signal)
On each rising edge, two interrupts occur: capture compare 1 interrupt and update event
interrupt. The latter is used to count the number of counter overflows over a reference signal
period. Since both interrupts occur at the same time at the beginning of every new period,
an extra overflow occurs. This is the reason why we have to subtract 1 from the number of
counter overflows: N – 1.
Thus the number of counted HSI clock pulses is given as follows:
, where:
–N is the number of timer overflows during one period of the reference frequency
–Capture1 is the value read from the timer CCR1 register.
Since the timer is clocked by the internal RC, the microcontroller can compute the real
frequency generated by the HSI versus the reference frequency.
6/22
The error (in Hz) is computed as the absolute value of the difference between the RC
frequency (Frequency
) and 8 000 000 Hz.
RC
Hence the RC frequency error is expressed as:
.
After calculating the error, the algorithm determines the calibration value that has to be
written to the HSITRIM bits in the RCC_CR register (refer to Section 3 for more details).
AN2868RC calibration
2.2 Hardware implementation
2.2.1 Case where RTC/64 is used as the reference frequency: 512 Hz
The STM32F10xxx can output the RTC signal divided by 64 onto GPIO PC13 (TAMPERRTC pin). The TAMPER-RTC signal can be used as the reference frequency for RC
calibration. For that purpose, this pin must be configured as alternate function push-pull and
be connected to a timer channel input.
Note:In the rest of this application note, the channel used will be timer 3 channel 1 (TIM3_CH1).
Figure 2 shows the hardware connections needed for RC calibration using RTC/64 as an
accurate frequency source for calibration.
Figure 2.Hardware connection using RTC/64 as a source for calibration
Reference signal
C1
32 .768 kHz
C2
32768 Hz/64
1 /512 Hz
OSC32_IN
OSC32_OUT
STM32F10xxx
TAMPER-RTC/PC13
TIM3_CH1 (PA6)
ai15842
2.2.2 Case where the mains frequency is used as the reference frequency:
50 Hz/60 Hz
This section describes the hardware requirements of the method that uses the AC mains
frequency as a reference. Figure 3 illustrates the circuit implemented to provide the DC
power supply (approximately 3.3 V) to the microcontroller:
The only component required to protect the timer input is a resistor. So if no power supply is
needed, then only a resistor is needed on the TIM3_CH1 input, to protect the timer input
from overcurrents.
This circuit includes a few passive components to convert the 220 V/50 Hz mains of the EU,
or the 110 V/60 Hz mains of the US, to a 3.3 V DC power supply. For applications that have
higher current consumptions, a power converter could be used (refer to the application note
AN1357: VIPower: low cost power supplies using VIPer12A in non isolated applications).
Caution:The reference signal conditioning and power supply circuits cannot be used if there are big
current variations.
In case of noisy mains, it is recommended to use an input power line filter (refer to the
application note AN2326: Calibrating the RC oscillator of the ST7ULTRALITE MCU using
the mains).
7/22
Loading...
+ 15 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.