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 Reply
  • First compare(NRF_DRV_RTC_INT_COMPARE0) : delay +- 62ns(max) ---- 1 every second

    -> nrf_drv_rtc_counter_clear(&rtc) : + 46us(max)

    Second compare(NRF_DRV_RTC_INT_COMPARE0) : delay +- 62ns(max)

    -> nrf_drv_rtc_counter_clear(&rtc) : + 46us(max)

    .....

    1 sec = 1sec + (+46us +- 62ns)

    24hours = 3600sec + (+46us +- 62ns)x3600

    "some clocks are more accurate than others." what? some clock???

    I don't understand. This delay is not accurate. never.

Children
No Data
Related