English
Language : 

AN2326 Datasheet, PDF (3/20 Pages) STMicroelectronics – Calibrating the RC oscillator of the ST7ULTRALITE MCU using the mains
AN2326
1
Calibration software
Calibration software
1.1
Software principle
The software algorithm, described in the following flowchart (see Figure 3.), uses the mains
frequency as a timebase. This timebase allows the microcontroller to test if the RC oscillator
frequency is above or below the targeted frequency and repeatedly transforms it by
dichotomous analysis so that in 10 iterations the RCCR/SICSR registers are set to the
optimum value. In order to simplify the calculation, the calibration is done at 1MHz, the
8MHz internal RC is divided by 8 thanks to the AVTCHR register.
As the timer speed depends on the RC oscillator frequency, it is easy to determine if the
oscillator is too fast or too slow. The counted value can be obtained by the following
equation:
countedvalue = ----------f--c--p---u-----------
32 × fmains
Since the frequency of the counter is the frequency of the oscillator divided by 32 (only the 8
) MSbits are saved on the 13 bits of the counter), if the oscillator is at 1 MHz, the result of the
t(s count between two edges (which have a 10 ms interval), is 138h for the European standard
c (220V/50Hz). For the US standard (110V/60Hz) the right value is 104h. Since the goal of the
u software is to set the RC oscillator frequency to 1 MHz it means obtaining 138h as the result
d of the count. So if the result of the count is greater than 138h, it means that the frequency is
ro too high so the program increases the value of RCCR/SICSR registers in order to decrease
P the RC oscillator frequency. And if the result is less than 138h, the RCCR/SICSR register
te value is decreased in order to increase the RC oscillator frequency.
ole Figure 1. Dichotomous analysis of RCCR value
s increase oscillator decrease oscillator
b frequency
frequency
O RCCR Register
- 0h
80h
FFh
) Start Value
t(s The RCCR register is set to 80h initially by the program, then the dichotomization starts by
c adding or subtracting 40h and after each iteration the result is divided by two, so that after
Obsolete Produ 10 iterations the value of RCCR is set with an accuracy of one bit.
3/20