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

RTC accurate

Hi. I will make clock.

I use RTC2 + Softdevice. (PCA10040 , NRF52832 , s132_nrf52_2.0.0_softdevice.hex )

Base Source code = nRF5_SDK_11.0.0_89a8197\examples\ble_peripheral\ble_app_uart

const nrf_drv_rtc_t rtc = NRF_DRV_RTC_INSTANCE(2);

static void appRTCHandler(nrf_drv_rtc_int_type_t int_type)
{
        if(int_type == NRF_DRV_RTC_INT_TICK)
	{
			LEDS_INVERT(BSP_LED_1_MASK);
	}
}

void appRTCInit(void)
{
	uint32_t err_code;

	//Initialize RTC instance
	err_code = nrf_drv_rtc_init(&rtc, NULL, appRTCHandler);
	APP_ERROR_CHECK(err_code);

	//Enable tick event & interrupt
	nrf_drv_rtc_tick_enable(&rtc, true);
	//Power on RTC instance
	nrf_drv_rtc_enable(&rtc);
}

int main(void)
{
	uint32_t err_code;
	bool erase_bonds;

	// Initialize.
	APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
	
	uart_init();
		
	buttons_leds_init(&erase_bonds);

	LEDS_ON(BSP_LED_3_MASK);

	ble_stack_init();
		
	gap_params_init();
	services_init();
	advertising_init();
	conn_params_init();

	appRTCInit();

	err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
	APP_ERROR_CHECK(err_code);
	// Enter main loop.
	for(;;)
	{
		  power_manage();		
	}
}

LED0 Toggle is success.

but... not 125 msec.

tick time = 125.01ms or 125.21ms or 125.12ms ...(measurement by oscilloscope)

Why a such a result?

I need accurate time.

How do make accurate 125ms. or accurate 1sec.

Parents
  • Hi,

    At least two things will affect RTC accuracy:

    In addition you should expect jitter of magnitude 15-46 us.

    What do you need accurate time for? Other ways to do this may be better, like using the timer peripheral. Even using a clock IC may be an option, if what you need is to keep accurate time over long periods of time. It all really depends on what you need.

    Regards, Terje

  • Jitter does not equal delay. Imagine a bus table that says a bus will arrive at 8 a.m. every day. If there is a jitter of +/- 10 minutes then the bus will arrive some time between 7:50 and 8:10 every day. The delay is always less than 10 minutes. The bus arrives with an accuracy of 10 minutes today, and it arrives with an accuracy of 10 minutes in a thousand years. This is the same for the jitter on the RTC clock. After 24 hours it will still fire within 15-46 us every time the clock reaches the trigger value.

    The accuracy of the clock itself depens on the clock source.

    Now to your particular use case: What do you need a clock for, and how accurate must it be? I can not give any good suggestions for what to use before I know the answers to these two questions. (There are other options than RTC, which may be better for you use case, but I really do not know what you need yet.)

Reply
  • Jitter does not equal delay. Imagine a bus table that says a bus will arrive at 8 a.m. every day. If there is a jitter of +/- 10 minutes then the bus will arrive some time between 7:50 and 8:10 every day. The delay is always less than 10 minutes. The bus arrives with an accuracy of 10 minutes today, and it arrives with an accuracy of 10 minutes in a thousand years. This is the same for the jitter on the RTC clock. After 24 hours it will still fire within 15-46 us every time the clock reaches the trigger value.

    The accuracy of the clock itself depens on the clock source.

    Now to your particular use case: What do you need a clock for, and how accurate must it be? I can not give any good suggestions for what to use before I know the answers to these two questions. (There are other options than RTC, which may be better for you use case, but I really do not know what you need yet.)

Children
No Data
Related