STM32F10xxx internal RC oscillator (HSI) calibration.pdf

(186 KB) Pobierz
STM32F10xxx internal RC oscillator (HSI) calibration
AN2868
Application note
STM32F10xxx
internal RC oscillator (HSI) calibration
Introduction
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.
February 2009
Rev 1
1/22
273858731.002.png
Contents
AN2868
Contents
1
STM32F10xxx’s internal clock: HSI clock . . . . . . . . . . . . . . . . . . . . . . . . 5
1.1
Calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2
RC calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.1
Principle of calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2
Hardware implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2.1
Case where RTC/64 is used as the reference frequency: 512 Hz . . . . . . 7
2.2.2
Case where the mains frequency is used as the reference frequency:
50 Hz/60 Hz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3
Description of the RC calibration library . . . . . . . . . . . . . . . . . . . . . . . . 9
3.1 HSI_FreqMeasure() function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2 HSI_CalibrateMinError() function . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.3 HSI_CalibrateFixedError() function . . . . . . . . . . . . . . . . . . . . . . . 13
3.4
Calibration demo description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.5
Recommendations on the use of the HSI calibration library . . . . . . . . . . 17
4
Calibration process performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.1
Accuracy of frequency measurements . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.2
Duration of the calibration process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
6
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2/22
273858731.003.png
AN2868
List of tables
List of tables
Table 1.
Component values when using the mains frequency as the reference . . . . . . . . . . . . . . . . 8
Table 2.
RC frequency accuracy vs. reference frequency accuracy . . . . . . . . . . . . . . . . . . . . . . . . 18
Table 3.
Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3/22
273858731.004.png
List of figures
AN2868
List of figures
Figure 1.
Quantification of the reference signal period (RTC signal) . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Figure 2.
Hardware connection using RTC/64 as a source for calibration. . . . . . . . . . . . . . . . . . . . . . 7
Figure 3.
Hardware connection in the AC mains calibration method . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Figure 4.
RC frequency measurement flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 5.
RC calibration flowchart: finding the minimum frequency error . . . . . . . . . . . . . . . . . . . . . 12
Figure 6.
“Spring loop” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Figure 7.
RC calibration flowchart: calibration with the maximum allowed frequency error . . . . . . . . 15
4/22
273858731.005.png
AN2868
STM32F10xxx’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 A =
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 hsitrim )
is around 40 kHz between two consecutive HSICAL steps.
5/22
273858731.001.png
Zgłoś jeśli naruszono regulamin