STM8S and STM8A high speed internal oscillator calibration
Introduction
This application note describes how to take advantage of the 16 MHz internal RC oscillator
trimming feature on the STM8S and STM8A microcontroller to improve the frequency
accuracy of the system compensating voltage and temperature frequency drift. The
calibration technique, using the mains frequency as a timebase, is presented with an
example of both hardware and software solutions. The example source code can be
downloaded from the www.st.com.
To benefit fully from the information in this application note, the user should be familiar with
the STM8S and STM8A microcontroller architecture and with the basics of C language.
For further information on the STM8S and STM8A family features, pinout, electrical
characteristics, mechanical data and ordering information, please refer to the STM8S and
STM8A datasheets.
This document and its associated firmware, are written to accompany the STM8S and
STM8A firmware library. Please contact STMicroelectronics for information on the STM8S
and STM8A firmware library.
Figure 6.Example of calibration signal conditioning circuit and 5 V power supply . . . . . . . . . . . . . . 15
4/19Doc ID 14983 Rev 2
AN2822High speed internal oscillator trimming
RC OSCILLATOR
DECODER
CLK_HSITRIM
HSI Clock Output
+
INIT_TR IM
1 High speed internal oscillator trimming
1.1 Introduction
The STM8S and STM8A 8-bit microcontrollers can use a high speed internal (HSI) RC
oscillator as a system clock source. This oscillator has a nominal frequency, f
16 MHz which is factory calibrated at an ambient temperature of T
voltage of V
= 5 V. This accuracy is specified in the datasheet for each device.
CC
= 25 °C and a supply
A
HSI nominal
The HSI frequency is calibrated to give reasonable accuracy for the vast majority of
applications. However, the output frequency of the RC oscillator is affected by temperature
and/or voltage drift, while, total accuracy of the HSI frequency is reduced a percentage
given in the datasheet. To compensate for such influences in the application, the STM8S
and STM8A HSI oscillator output frequency can be trimmed by the user runtime calibration
routine to improve frequency accuracy. This is especially important for communication
peripherals.
Figure 1.STM8S and STM8A HSI trimming principle
, of
Initial calibration data, INIT_TRIM, are stored in the protected part of the internal memory
and loaded onto the internal calibration register after reset.
The frequency of the HSI RC oscillator can be fine-tuned to achieve better accuracy with
wider temperature and supply voltage ranges. The lowest three bits of the CLK_HSITRIMR
register are reserved for this purpose. The number stored in these bits is processed as a
signed number with the two's-complement representation (see Ta bl e 1 ). The trimming
number
(a)
can vary from -4 (100b) to +3 (011b). This number is added to the factory
calibration value.
Note:An increase in this trimming value causes a decrease in HSI frequency.
The frequency change per step is approximately 1%
a. Some selected STM8S and STM8A devices can be set to 4-bit trimming mode by the HSITRIM option byte,
see device datasheet for details.
b. If the 4-bit trimming mode is set by the HSITRIM option byte, the frequency change between two steps in the
trimming value is approx. 0.5%
(b)
.
Doc ID 14983 Rev 25/19
High speed internal oscillator trimmingAN2822
TIM3_CC1
/1, /2, /4 or /8
Counter
Capture
f
MASTER
= f
HSI
Core
CCO
Overload
interrupt
Capture
interrupt
CLK_HSITRIMR
HSI 16 MHz
Prescaler
Calibration
signal
Input
Filter
TI1TI1FIC1PS
Table 1.CLK_HSITRIMR values and two’s-complement binary representation
Decimal valueBinary two’s-complement value
3011
2010
1001
0000
-1111
-2110
-3101
-4100
Note:The default value on the CLK_HSITRIMR register is zero (000b) after reset.
1.2 Calibration principle
To calibrate the HSI output frequency, a reference timebase is necessary. A simple
reference timebase can be used, such as the post-processed signal from the mains power
source (see Section 2). The final accuracy of the HSI frequency is strongly dependent on
the accuracy of the reference timebase. Better accuracy can be achieved with more
accurate timebases such as a signal generator.
Figure 2.HSI calibration set-up
The calibration signal, from the mains power supply, is connected to the TIM3_CC1 input pin
and is used as a timebase which allows the microcontroller to test if the HSI RC oscillator
frequency is above or below the nominal frequency. The HSI frequency is sequentially tuned
by the microcontroller until the optimum value is reached.
6/19Doc ID 14983 Rev 2
Loading...
+ 13 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.