STM STM8 STM8L151C4 Learning Centre MCU Application Notes STMicroelectronics - Application - Notes - 1
STM STM8 STM8L151C4 Learning Centre MCU Application Notes STMicroelectronics - Application - Notes - 1
STM STM8 STM8L151C4 Learning Centre MCU Application Notes STMicroelectronics - Application - Notes - 1
Application note
STM8L15x
internal RC oscillator calibration
Introduction
The STM8L15x microcontrollers offer the possibility of using internal RC oscillators HSI
(High-speed internal factory trimmed oscillator of 16 MHz, typically) or LSI (Low-speed
internal low-consumption oscillator of 38 kHz, typically) as clock sources.
The operating temperature has an impact on RC accuracy. At 25 C the HSI has an
accuracy of 1% typically but in the temperature range of -40 to 105 C, the accuracy of the
HSI frequency decreases to -4.5% / +3%.
To compensate for the influence of temperature on internal RC oscillator accuracy, the
STM8L15x microcontrollers provide the capability of calibrating the HSI clock and of
measuring the LSI clock.
This application note gives two methods of calibrating the HSI internal RC oscillator. The
first method is based on finding the frequency with the minimum error and the second one
consists in finding the maximum allowed frequency error. Both are implemented by
providing an accurate reference source.
The measurement of the LSI clock is performed by connecting the LSI oscillator to a timer
input capture. Depending on the measured value, peripheral registers are updated to meet
user requirements.
This application note applies to STM8L15x High-Density and Medium-Density Devices.
September 2010
1/21
www.st.com
Contents
AN3101
Contents
1
Calibration principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2
Hardware implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3
2.2.1
2.2.2
2.3.2
2.3.3
2.3.4
2.4
2.5
3.2
3.3
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2/21
AN3101
List of figures
List of figures
Figure 1.
Figure 2.
Figure 3.
Figure 4.
Figure 5.
Figure 6.
Figure 7.
Figure 8.
Figure 9.
Figure 10.
Figure 11.
3/21
AN3101
The internal RC oscillators (HSI and LSI) have the advantage of providing a low-cost clock
source (no external components required). It also has a faster startup time than the external
oscillator. However, even with calibration, the internal RC oscillator frequency is less
accurate than the frequency of an external crystal oscillator or ceramic resonator.
Note:
4/21
The internal oscillator can also be used as backup source (auxiliary clock) if the external
oscillator fails.
AN3101
2.1
Calibration principle
The calibration principle consists in
and finally setting the HSITRIMR register with the optimum value.
The HSI frequency is not measured directly but it is estimated from the number of counted
HSI clock pulses using a timer compared with the typical value (16 MHz). To do so, a very
accurate reference frequency must be available such as the LSE frequency provided by the
external 32.768 kHz crystal or the 50 Hz/60 Hz of the mains (refer to Section 2.2.2: Case
where another source is used as the reference frequency).
The following figure shows how the reference signal period is measured in number of timer
counts.
Figure 1.