GD32F403xx User Manual
117
CTC_CTL0 register is 1.
If the AUTOTRIM bit in CTC_CTL0 register set, the TRIMVALUE in CTC_CTL0 register
is not changed.
◼
CKLIM
≤
Counter < 3 x CKLIM when REF sync pulse is detected.
The CKOKIF in CTC_STAT register set, and an interrupt generated if CKOKIE bit in
CTC_CTL0 register is 1.
If the AUTOTRIM bit in CTC_CTL0 register set, the TRIMVALUE in CTC_CTL0 register
add 1 when down-counting or sub 1 when up-counting.
◼
3 x CKLIM
≤
Counter < 128 x CKLIM when REF sync pulse is detected.
The CKWARNIF in CTC_STAT register set, and an interrupt generated if CKWARNIE
bit in CTC_CTL0 register is 1.
If the AUTOTRIM bit in CTC_CTL0 register set, the TRIMVALUE in CTC_CTL0 register
add 2 when down-counting or sub 2 when up-counting.
◼
Counter
≥
128 x CKLIM when down-counting when a REF sync pulse is detected.
The CKERR in CTC_STAT register set, and an interrupt generated if ERRIE bit in
CTC_CTL0 register is 1.
The TRIMVALUE in CTC_CTL0 register is not changed
◼
Counter = 128 x CKLIM when up-counting.
The REFMISS in CTC_STAT register set, and an interrupt generated if ERRIE bit in
CTC_CTL0 register is 1.
The TRIMVALUE in CTC_CTL0 register is not changed.
If adjusting the TRIMVALUE in CTC_CTL0 register over the value of 63, the overflow will be
occurred, while adjusting the TRIMVALUE under the value of 0, the underflow will be occurred.
The TRIMVALUE is in the range 0 to 63 (the TRIMVALUE is 63 if overflow, the TRIMVALUE
is 0 if underf low). Then, the TRIMERR in CTC_STAT register will be set, and an interrupt
generated if ERRIE bit in CTC_CTL0 register is 1.
6.3.4.
Software program guide
The RLVALUE and CKLIM bits in CTC_CTL1 register is critical to evaluate the clock
f requency and automatically hardware trim. The value is calculated by the correct clock
f requency (IRC48M:48 MHz) and the f requency of REF sync pulse. The ideal case is REF
sync pulse occur when the CTC counter is zero, so the RLVALUE is:
RLVALUE = (𝐹
𝑐𝑙𝑜𝑐𝑘
÷ 𝐹
𝑅𝐸𝐹
) − 1
(6-1)
The CKLIM is set by user according to the clock accuracy. It is recommended to set to the
half of the step size, so the CKLIM is: