Hi,
As my colleague had mentioned, the AN4949 provides the RTC compensation theory.
Below is the RTC compensation test code for your reference:
/**************************************************************************/
//srtc compensation function test
void srtc_comp()
{
volatile uint32 TSR_VAL, TPR_VAL;
int i=2;
int current;
printf("Start checking srtc time compensation function...\r\n");
printf("Enable osc\n");
RTC_CR |= RTC_CR_OSCE_MASK;
printf("Compensation Interval of 1 seconds with Compensation value of 32641 cycles\r\n");
current = 1;
//RTC_TCR = 0x00000080; //should be short ~3.5 seconds in 1020 counts
//RTC_TCR = 0x000000BF; //should be short ~1.7 seconds in 1000 counts
RTC_TCR = 0x00000000; //should be dead on after 1000 counts
//RTC_TCR = 0x0000003f; // should be fast ~1.7 seconds after 1020 counts
//RTC_TCR = 0x0000007f; //should be fast ~3.5s after 1000 counts
RTC_TSR = 0x00000001;
RTC_SR |= RTC_SR_TCE_MASK;
//Check for 15 seconds that the TPR register never increments to 32642
while(1)
{
//TPR_VAL = RTC_TPR;
//TSR_VAL = RTC_TSR;
if(/*(RTC_TPR >= 32767) &&*/ (current != RTC_TSR))
{
printf("%i\n", i);
i+=1;
current = RTC_TSR;
}
}
}
Wish it helps.
Have a great day,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------