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 Children
  • hi, Terje

    two things make delay(15~46 us).

    I need zero delay.

    Clock need no delay.

  • There is no clock that is infinitely accurate, but some clocks are more accurate than others. What do you need this clock for, what is the use case? And how accurate must it be?

  • 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.

  • 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.)

    1. I will make stopwatch. or clock or watch...

    2. I need 1ms.(accurate)

    3. I did use RTC.

    4. I made 1ms.(Choice of prescaler)

    5. But, This RTC is not 1ms. (1.001ms or 1.0005ms or 1.0008ms ...)

    6. Eventually, I will not make stopwatch. because RTC is not accurate.

    7. I have not external RTC IC.

    8. Do you know I need ?

Related