R8C/36T-A Group
18. Timer RE2
Under development Preliminary document
Specifications in this document are tentative and subject to change.
R01UH0240EJ0010 Rev.0.10
Page 362 of 728
Aug 05, 2011
18.3.4.4
Examples of Setting Clock Error Correction Function
The following shows examples of setting correction by the automatic correction function and correction by
software.
These examples apply under the assumptions:
External sub oscillator frequency fsub = 32,769.55 Hz
External sub oscillator frequency error foffsub = (32,769.55 – 32,768)/32,768 × 106 = 47.3 ppm
(1) Example of setting correction by the automatic correction function
The AADJE bit in the TRECR register = 1 (automatic correction function enabled (correction by software
disabled)).
When the AADJM bit in the TRECSR register = 0 (corrected every minute), the correction amount is
expressed as follows:
Correction amount = (fsub – 32,768) × 60 = 93
63 (maximum setting value of bits ADJ0 to ADJ5)
Thus, automatic correction cannot be performed every minute.
When the AADJM bit in the TRECSR register = 1 (corrected every 10 seconds), the correction amount is
expressed as follows:
Correction amount = (fsub – 32,768) × 10 = 15.5
16
Thus, set the TREADJ register to 01010000b (MINUS correction, correction amount = 16).
Clock errors after correction (unit: ppm)
= ((fsub × 10 – 16)/(32,768 × 10) – 1) × 106
= -1.5 ppm (slower than the standard clock by 1.5 ppm)
(2) Example of setting correction by software
The AADJE bit = 0 (automatic correction function disabled (correction by software enabled)).
The minimum correction amount when writing to the TREADJ register every second is ±1/32,768 =
±30.5 ppm, and the minimum correction amount when writing to the TREADJ register every minute is
±1/32,768/60 = ±0.5 ppm, so corrections every second and every minute are combined to be used.
If the correction amount when writing to the TREADJ register every second (writing every second) is A,
and the correction amount when writing to the TREADJ register every minute (writing every minute) is
B,
A = [fsub – 32,768] = [1.55] = 1 ([ ] indicates taking the integer floor of the value.)
B = A + (((fsub – 32,768) × 60) % 60) = A + (93 % 60) = 34
(% indicates the remainder for a division operation.)
Thus, correction is performed by writing 01000001b (41h) every second and 01100010b (62h) every
minute to the TREADJ register.
Clock errors after correction (unit: ppm)
= (((fsub – A) × 59 + (fsub – B))/(32,768 × 60) – 1) × 106
= 0 ppm