This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2340R5: How to use 48M Timer to calibrate internal 32.768K RTC

Part Number: CC2340R5

Tool/software:

CC2340R5: The accuracy of the 32kHz RC Oscillator (LFOSC) - Bluetooth forum - Bluetooth®︎ - TI E2E support forums

Continuing the topic of the linked article, I used an external oscillator 48M Timer to read the value of RTC TIME8U. Whether the calibration time is 1 second or 5 minutes, it is very close to the ideal value. This is very strange to me. According to the test report given by TI FAE, the ppm error of the internal 32.768K is as shown below



According to these data, the average ppm error of 32.768K will fall around -100ppm. However, I use 48M Timer for calibration. No matter how many times I test, the error value per second is at most 2 counts. Because it is the value of TIME8U, it is about 16us after conversion per second, which is inconsistent with the data. The calibration method is as follows:


/* ----Calibration RTC Timer Initial ---- */
hTimer_RTC = NULL;
LGPTimerLPF3_Params LGPparams_RTC;
LGPTimerLPF3_Params_init(&LGPparams_RTC);
LGPparams_RTC.hwiCallbackFxn = Calibration_RTCTimerCallback;
LGPparams_RTC.prescalerDiv = 48 - 1;
uint32_t counterTarget_RTC;
hTimer_RTC = LGPTimerLPF3_open(CONFIG_LGPTIMER_1, &LGPparams_RTC);
if(hTimer == NULL)
{
// while(1){}
}
counterTarget_RTC = 1000 - 1; // 8ms with a system clock of 48MHz
LGPTimerLPF3_setInitialCounterTarget(hTimer_RTC, counterTarget_RTC, true);
g_tRTC.uiRTC_Calibration_Count = 0;
g_tRTC.uiRTC_Calibration_8us_old = HWREG(RTC_BASE + RTC_O_TIME8U);
LGPTimerLPF3_enableInterrupt(hTimer_RTC, LGPTimerLPF3_INT_TGT);
LGPTimerLPF3_start(hTimer_RTC, LGPTimerLPF3_CTL_MODE_UP_PER);

void Calibration_RTCTimerCallback(LGPTimerLPF3_Handle lgptHandle, LGPTimerLPF3_IntMask interruptMask)
{
    g_tRTC.uiRTC_Calibration_Count++;
    if(g_tRTC.uiRTC_Calibration_Count >= 1000)
    {
        g_tRTC.uiRTC_Calibration_8us = HWREG(RTC_BASE + RTC_O_TIME8U);
        LGPTimerLPF3_disableInterrupt (hTimer_RTC, LGPTimerLPF3_INT_TGT);
        LGPTimerLPF3_stop(hTimer_RTC);
        if(g_tRTC.uiRTC_Calibration_8us < g_tRTC.uiRTC_Calibration_8us_old)
            g_tRTC.iRTC_Calibration_8us_diff = (g_tRTC.uiRTC_Calibration_8us + 0xFFFFFFFF) + g_tRTC.uiRTC_Calibration_8us_old;
        else
            g_tRTC.iRTC_Calibration_8us_diff = g_tRTC.uiRTC_Calibration_8us - g_tRTC.uiRTC_Calibration_8us_old;

        g_tRTC.dRTC_Calibration_perSecond = ((double)g_tRTC.iRTC_Calibration_8us_diff - 125000) * 0.000008;
    }
}

I also made sure that the syscfg in the project settings was correctly set to LF RCOSC



1. I suspect that when the 48M Timer is running, the RTC is also running with a 48M oscillator, resulting in a large difference between the calibration value and the data value. In other words, the RTC is actually equal to 48M, resulting in the theoretical values of the RTC and 48M being almost the same

2. Is there a way to ensure that when using the 48M Timer, the RTC clock source is definitely using the internal 32.768K oscillator?

  • Hi Ryan,

    Thank you for raising this topic again as I've further discussed with the TI Drivers Team about CC2340R5 LFOSC calibration 

    1. Regardless of using “LFOSC Compensation” or not, the HW will always calibrate LFOSC against HFOSC/HFXT while active (unless it is explicitly disabled).
    2. The “LFOSC Compensation” feature would only be relevant during standby. What it should do is schedule additional “dummy” wakeups, for which the frequency of these needs to be higher than the frequency of the actual wakeups (performed by your application) that the system requires, such that the any drift in frequency is actually caught before the system wakeup.
    3. For https://e2e.ti.com/f/1/t/1519507 the use of LGPT which is disallowing standby while running a LFOSC compensation feature will not improve anything, since the device will not enter standby and the LFOSC is already continuously calibrated against HFXT (as mentioned in point 1 above).

    So you are correct in your observations that the RTC closely follows the 48M clock, since LFOSC is calibrated against HFOSC/HFXT while active which is true since you are exclusively using the LGPT in your test.  By this manner the 48M Timer cannot be used to calibrate the internal 32.768K RTC, since it is performed by HW automatically during active mode, and the true LFOSC compensation must be accomplished while in standby.  The ClockP module (operational during standby mode) can be used to schedule both wakeups, Power_setConstraint(PowerLPF3_DISALLOW_STANDBY), and delays (recommend 1 ms) before returning to standby, Power_releaseConstraint(PowerLPF3_DISALLOW_STANDBY).  Additional active cycles will create a tradeoff between LFOSC accuracy and power consumption.

    Regards,
    Ryan