This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Frequency shift with RTC on nRF52832

Hello,

I use the LAIRD module BL652 with an nRF52832.

My project used the RTC as date/hour counter. I used this RTC to increment a counter each 125 ms of RTC interrupt. I use a external Crystal of 32.768 kHz to supply the RTC, this Crystal have 20 ppm (and we test with a 5 ppm Crystal too). We have a lot of time shifting with this functionality, as 10 seconds of delay by day with a 20 ppm Crystal, as 2 seconds of delay by day with a 5 ppm Crystal.

The product go and out from sleep mode, each second by a timer and each 125 ms with this RTC interrupt.

My RTC configuration is :

static void rtc_config(void)
{
    uint32_t err_code;

    //Initialize RTC instance
    nrf_drv_rtc_config_t config = NRF_DRV_RTC_DEFAULT_CONFIG;
    config.prescaler = 4095;	// To have 125 ms : 4095;
    
    err_code = nrf_drv_rtc_init(&rtc, &config, rtc_handler);
    APP_ERROR_CHECK(err_code);

    //Enable tick event & interrupt
    nrf_drv_rtc_tick_enable(&rtc,true);

    // Désactiver la comparaison
    nrf_drv_rtc_cc_disable(&rtc, 0);

    //Power on RTC instance
    nrf_drv_rtc_enable(&rtc);
}

Into the "rtc_handle" function, I increment a counter to count each 125 ms. With this, I can manage the date and the hour of the product.

The define part for the RTC is :

#define RTC_ENABLED 1
#define RTC2_ENABLED 1

#define RTC_DEFAULT_CONFIG_FREQUENCY 32768

#define RTC_DEFAULT_CONFIG_IRQ_PRIORITY 7

#define RTC_DEFAULT_CONFIG_RELIABLE 0

#define NRF_MAXIMUM_LATENCY_US 2000

To define the external Crystal, I have this part :

#define CLOCK_ENABLED 1

#define CLOCK_CONFIG_LF_SRC 1

#define CLOCK_CONFIG_IRQ_PRIORITY 7

#define NRF_SDH_CLOCK_LF_SRC 1

#define NRF_SDH_CLOCK_LF_XTAL_ACCURACY 7

#define NRF_SDH_CLOCK_LF_RC_CTIV 0

#define NRF_SDH_CLOCK_LF_RC_TEMP_CTIV 0

So, for me, I have a good configuration to use the external Crystal !!!   but perhaps, a "Crystal calibration" is required !! but I Don't know how enable this calibration.

How can I have a better accurancy with a external Crystal ??

How can I do to reduce this shifting ??

If someone else have another idea to mange the date/hour, I take it.

Best regards,

Damien

  • Hi,

    To achieve correct oscillation frequency, the load capacitance must match the specification in the crystal data sheet. So the first thing to check is that you have reasonable load capacitance values for C11 and C12. General rule of thumb is to use C11 = C12 = 2*CL - 4 pF, where CL is the load capacitance of the crystal you are using (found in the crystal datasheet), and that C_pcb + C_pin is approximately 4 pF.
    You might also find this repo useful. Also note that the SoftDevice uses RTC0, and app_timer uses RTC1.

  • Hi,

    Thank you for your response. And sorry for my long time message.

    I have effectively change the capacitor and the quartz works little fine. I have 1 seconds of delay for each day passed.

    (It's better than 10 seconds by day).

    But in fact, when we compute the delay for a 20 ppm Crystal, we find a delay of 0.127 seconds by day.

    It exist another function or peripheral to improve and reduce this delay ??

    Thank you,

    Best regards.

    Damien ALTMANN

Related