3 usage, Atmega4hvd/8hvd – Rainbow Electronics ATmega8HVD User Manual
Page 28

28
8052B–AVR–09/08
ATmega4HVD/8HVD
8.12.3
Usage
The Slow RC oscillator represents a highly predictable and accurate clock source over the
entire temperature range and provides an excellent reference for calibrating the Fast RC oscil-
lator runtime. Typically, runtime calibration is needed to provide an accurate Fast RC
frequency for asynchronous serial communication in the complete temperature range.
The Slow RC frequency at 70
°
C and the Slow RC temperature coefficient are stored in the sig-
nature row. These characteristics can be used to calculate the actual Slow RC clock period at
a given temperature with high precision. Refer to
”Slow RC Oscillator” on page 24
for details.
By measuring the number of CPU cycles of one or more prescaled Slow RC clock periods, the
actual Fast RC oscillator clock period can be determined. The Fast RC clock period can then
be adjusted by writing to the FOSCCAL register. The new Fast RC clock period after calibra-
tion should be verified by repeating the measurement and repeating the calibration if
necessary. The Fast RC clock period as a function of the Slow RC clock period is given by:
where n is the number of prescaled Slow RC periods that is used in the measurement. Using
more prescaled Slow RC periods decreases the measurement error, but increases the time
consumed for calibration. Note that the Slow RC Oscillator needs very short time to stabilize
after being enabled by the OSI module. Hence, the calibration algorithm may use the time
between the first and second osi_posedge as time reference for calculations.
Another usage of OSI is determining the ULP frequency accurately. The ULP frequency at
70
°
C and the ULP temperature coefficient are stored in the signature row, allowing the ULP
frequency to be calculated directly. However, the ULP frequency is less predictable over tem-
perature than the Slow RC oscillator frequency, therefore a more accurate result can be
obtained by calculating the ratio between the Slow RC and ULP oscillators. This is done by
sampling both the ULP and Slow RC oscillators and comparing the results. When the ratio is
known, the actual ULP frequency can be determined with high accuracy. The ULP RC clock
period as a function of the Slow RC clock period is given by:
where n is the number of prescaled ULP RC and Slow RC periods that is used in the measure-
ment. Using more prescaled ULP RC and Slow RC periods decreases the measurement error,
but increases the time consumed for calibration. Note that the FOSCCAL register must be
kept at a constant value during this operation to ensure accurate results.
These clock period calculations should be performed again when there is a significant change
in die temperature since the previous calculation. The die temperature can be found using the
ADC, refer to section TBD for details.
T
FastRC
T
SlowRC
128
n
⋅
number of CPU cycles in n prescaled Slow RC periods
-------------------------------------------------------------------------------------------------------------------------------------------------
⋅
=
T
ULPRC
T
SlowRC
number of CPU cycles in n prescaled ULP RC periods
number of CPU cycles in n prescaled Slow RC periods
-------------------------------------------------------------------------------------------------------------------------------------------------
⋅
=