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

timestamping w/o active timer (APP_TIMER_KEEPS_RTC_ACTIVE = 1)

hello,

i am using the nrf52840 preview devkit and am currently trying to find a solution for timestamping / for a time-base. the idea was to use the RTC for that since it provides a pretty accurate time reference and i really don't want to create ISRs or my own tick-implementation.

i found the APP_TIMER module, looked at the WDT example to get up the lf-clock and also found the configuration macro to keep the RTC alive (APP_TIMER_KEEPS_RTC_ACTIVE) but it somehow doesn't seem to work, i.e., if i don't have some dummy counter running then i can't get any values with app_timer_cnt_get (always zero see other questions).

is this a known issue? the following is a reduced example which i basically copied together from the csense driver to get the app_timer_cnt_get function up and running but only with a dummy timer:

#define APP_TIMER_PRESCALER     0
#define APP_TIMER_OP_QUEUE_SIZE 2

/* Time between RTC interrupts. */
#define APP_TIMER_TICKS_TIMEOUT 2000

static ret_code_t clock_config(void)
{
    ret_code_t err_code;

    err_code = nrf_drv_clock_init();
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    nrf_drv_clock_lfclk_request(NULL);

    return NRF_SUCCESS;
}

static void timeout_handler(void * p_context)
{
    NRF_LOG_INFO("Busy.\r\n");
}

void start_app_timer(void)
{
    ret_code_t err_code;
        
    /* APP_TIMER definition for csense example. */
    APP_TIMER_DEF(timer_0);

    err_code = app_timer_create(&timer_0, APP_TIMER_MODE_REPEATED, timeout_handler);
    APP_ERROR_CHECK(err_code);

    err_code = app_timer_start(timer_0, APP_TIMER_TICKS_TIMEOUT, NULL);
    APP_ERROR_CHECK(err_code);
}


uint32_t rtc_t0;

int main(void)
{
    uint32_t err_code = NRF_SUCCESS;
    bsp_board_leds_init();

    err_code = clock_config();
    APP_ERROR_CHECK(err_code);
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, NULL);
    
    start_app_timer(); 

    while (1)
    {
        rtc_t0 = app_timer_cnt_get ();
        __WFI();
    }
}

the timestamp rc_t0 will stay zero if i do not execute start_app_timer regardless of the SDK configuration (macro APP_TIMER_KEEPS_RTC_ACTIVE).

the workaround would be to use the dummy app-timer but i'd really like to avoid this since i cannot initialize a timer without callback.

also something that i still need to investigate: does this dummy timer then also have an influence on the resolution i get from app_timer_cnt_get ?

Related