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

Measuring time between events

Hi all,

I am struggling measuring time between events. I thought to use the timer driver and the nrf_drv_timer_capture_get function. This is my test code:

const nrf_drv_timer_t timer2 = NRF_DRV_TIMER_INSTANCE(1);

...

int main(void) {

....

  nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
  timer_cfg.frequency = NRF_TIMER_FREQ_16MHz;
  timer_cfg.mode = NRF_TIMER_MODE_COUNTER;
  timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;
  err_code = nrf_drv_timer_init(&timer2, &timer_cfg, null_event_handler);
  APP_ERROR_CHECK(err_code);
  nrf_drv_timer_enable(&timer2);
  
   for (;;) {

    uint32_t current = nrf_drv_timer_capture_get(&timer2, NRF_TIMER_CC_CHANNEL0);
    NRF_LOG_INFO("Current %d", current);

    
    if (NRF_LOG_PROCESS() == false) {
      power_manage();
    }
  }
}

I expected to see the current value getting greater, instead it is always 0.

Why?

Thanks.

Related