RTC Time Discrepancy Issue with nRF5340

Hello all,

We are currently working with the nRF5340 on a custom board and have encountered an issue with the Real-Time Counter (RTC) using the nrfx libraries. The problem is that the RTC is not syncing correctly with the actual time.

For example, while the actual time is 16:46:44:171, the RTC time reads as 16:46:42:735. This discrepancy is causing issues with time-sensitive operations in our application.

Here’s a brief overview of what we’ve tried so far:
- Verified that the RTC configuration in the code matches the expected settings.
- Reviewed the nrfx library documentation for any known issues or configurations related to RTC timekeeping.

Log is also attached for reference.

Has anyone experienced similar issues or have suggestions on how to troubleshoot or resolve this discrepancy? Any guidance or insights would be greatly appreciated.

Thank you in advance for your help!

Best regards,
Krishna Chandran

Parents
  • Hi!

    Could you explain a bit more on how you do this sync? How do you get the "actual time" ?

  • Hi,

    Could you explain a bit more on how you do this sync?

    Actually we are using a mobile app, using app(BLE)we are updating the time to device. 

    How do you get the "actual time" ?

    Actual time means the system time. 

    Regards,

    Krishnachandran

  • Depending on e.g. BLE connection interval, BLE connection Slave Latency, etc, there will be a bit delay from the time mobile phone sends the data, to it's received on the nRF, and you update the RTC. You could try requesting a lower connection interval when updating, and see if that improves things.

  • Hi Sigurd,

    Thank you for the update. The problem is that, although we updated RTC via the mobile app (using BLE) without any problems, there was a noticeable difference in RTC after around 30 minutes of operation (slow).

    For your reference, the RTC init and call back code are attached. Please review and share any recommendations.  

    void rtc_init()
    {
    
    	const nrfx_rtc_config_t config = {
    		.prescaler = NRF_RTC_FREQ_TO_PRESCALER(RTC_PRESCALAR), 
    		.interrupt_priority = NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY,
    		.tick_latency = NRFX_RTC_US_TO_TICKS(2000, 32768),
    		.reliable = true};
    		
    	// Function for initializing the RTC driver instance.
    	nrfx_rtc_init(&rtc_driver_instance_0, &config, rtc_callback);
    
    	IRQ_DIRECT_CONNECT(RTC0_IRQn, 0, nrfx_rtc_0_irq_handler, 0);
    
    	// Function for disabling the TICK event.
    	nrfx_rtc_tick_disable(&rtc_driver_instance_0);
    	
    	nrfx_rtc_tick_enable(&rtc_driver_instance_0,true);
    
    }
    
    void rtc_callback(nrfx_rtc_int_type_t val)
    {
    	nrfx_rtc_counter_clear(&rtc_driver_instance_0);
    	// Enable interupt
    	nrfx_rtc_int_enable(&rtc_driver_instance_0, 131072);
    	update_time(val);
    
        if(read_rtc_state == true && val == 4)
        {
            read_rtc_count++;
            if(read_rtc_count >= 100)
            {
                read_rtc_count = 0;
                rtc_read_callback_function();
            }
        }
        else if(read_rtc_state  == false && read_rtc_count != 0)
        {
            read_rtc_count =0;
        }
    }
    

    Regards,

    Krishna Chandran

Reply
  • Hi Sigurd,

    Thank you for the update. The problem is that, although we updated RTC via the mobile app (using BLE) without any problems, there was a noticeable difference in RTC after around 30 minutes of operation (slow).

    For your reference, the RTC init and call back code are attached. Please review and share any recommendations.  

    void rtc_init()
    {
    
    	const nrfx_rtc_config_t config = {
    		.prescaler = NRF_RTC_FREQ_TO_PRESCALER(RTC_PRESCALAR), 
    		.interrupt_priority = NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY,
    		.tick_latency = NRFX_RTC_US_TO_TICKS(2000, 32768),
    		.reliable = true};
    		
    	// Function for initializing the RTC driver instance.
    	nrfx_rtc_init(&rtc_driver_instance_0, &config, rtc_callback);
    
    	IRQ_DIRECT_CONNECT(RTC0_IRQn, 0, nrfx_rtc_0_irq_handler, 0);
    
    	// Function for disabling the TICK event.
    	nrfx_rtc_tick_disable(&rtc_driver_instance_0);
    	
    	nrfx_rtc_tick_enable(&rtc_driver_instance_0,true);
    
    }
    
    void rtc_callback(nrfx_rtc_int_type_t val)
    {
    	nrfx_rtc_counter_clear(&rtc_driver_instance_0);
    	// Enable interupt
    	nrfx_rtc_int_enable(&rtc_driver_instance_0, 131072);
    	update_time(val);
    
        if(read_rtc_state == true && val == 4)
        {
            read_rtc_count++;
            if(read_rtc_count >= 100)
            {
                read_rtc_count = 0;
                rtc_read_callback_function();
            }
        }
        else if(read_rtc_state  == false && read_rtc_count != 0)
        {
            read_rtc_count =0;
        }
    }
    

    Regards,

    Krishna Chandran

Children
Related