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

measuring interrupt interval with app_timer

I have an interrupt coming in every 50-150 microsecs and I want to measure these intervals as precisely as possible.

I tried this with SDK12.2:

APP_TIMER_INIT(0, 5, false);

then in the (GPIOTE) ISR:

uint32_t this_time=app_timer_cnt_get();

I always get zero back;

Presumably I need to initialise it in a different way?

Thx for any suggestion.

Parents
  • OK. Got this after much googling.

    #define NRF_DRV_TIMER_MY_CONFIG {
        .frequency          = (nrf_timer_frequency_t) NRF_TIMER_FREQ_1MHz,
        .mode               = (nrf_timer_mode_t) TIMER_MODE_MODE_Timer,
        .bit_width          = (nrf_timer_bit_width_t) TIMER_BITMODE_BITMODE_32Bit,
        .interrupt_priority = TIMER_DEFAULT_CONFIG_IRQ_PRIORITY,
        .p_context          = NULL
    }
    
    const nrf_drv_timer_t TIMER_INPUT = NRF_DRV_TIMER_INSTANCE(3);
    
    void timer_event_handler(nrf_timer_event_t event_type, void * p_context) { 
      return;  //  needed even if not used 
    }
    

    and in main()

    nrf_drv_timer_config_t in_config_f = NRF_DRV_TIMER_MY_CONFIG;
    err_code = nrf_drv_timer_init(&TIMER_INPUT, &in_config_f, timer_event_handler); 
    APP_ERROR_CHECK(err_code);
    nrf_drv_timer_enable(&TIMER_INPUT);
    

    then in ISR

    this_time=nrf_drv_timer_capture(&TIMER_INPUT, 0);
    

    (then handle delta microseconds and overflow.)

    seems to work well enough. note that putting NULL instead of timer_event_handler causes a an immediate crash.

  • See above. I can only answer once so I added the code to my previous answer.

Reply Children
No Data
Related