I am struggling measuring time between two events. I thought to use the timer driver and the nrf_drv_timer_capture_get function and start/stop the timer with nrf_drv_timer_enable/nrf_drv_timer_disable. This is my starting 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);
// Enter main loop.
for (;;) {
uint32_t current = nrf_drv_timer_capture_get(&timer2, NRF_TIMER_CC_CHANNEL0);
NRF_LOG_INFO("Current %d", current);
app_sched_execute();
if (NRF_LOG_PROCESS() == false) {
power_manage();
}
}
}
I expected to see the current value getting greater, instead it is always 0.
Why?
Thanks