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

nrfx timer - How to set a timer prescaler?

A simple question - if using the nrfx timer library how do I set a timer prescaler?

I'm using timers 3 & 4 in compare/capture mode to measure pulse widths (not the application timer)

  • Hi,

    The prescaler is set by the frequency parameter in the config that you pass to nrfx_timer_init(). I should be set to one of the frequnecies defined in nrf_timer_frequency_t.

    PRESCALER register is set by the HAL function nrf_timer_frequency_set(), which is called in nrfx_timer_init().

    Best regards,
    Jørgen

  • OK thanks.

    Trying to use the nrfx driver is really giving me a headache! For some reason my code only compiles if I have both TIMER_ENABLED and NRFX_TIMER_ENABLED in sdk_config.h  at the same time, which directly  contradicts the advice I've found on the devzone  here

    This is the code

      nrfx_timer_config_t t4_cfg      = NRFX_TIMER_DEFAULT_CONFIG;
      t4_cfg.frequency                = NRF_TIMER_FREQ_8MHz;
      t4_cfg.bit_width                = NRF_TIMER_BIT_WIDTH_32;
      err_code = nrfx_timer_init(&m_t4, &t4_cfg, timer4_handler);
      nrfx_timer_compare(&m_t4,NRF_TIMER_CC_CHANNEL0,PULSE1_MIN,true);
      nrfx_timer_compare(&m_t4,NRF_TIMER_CC_CHANNEL1,PULSE1_MAX,true);
      nrfx_timer_compare(&m_t4,NRF_TIMER_CC_CHANNEL2,PULSE2_MIN,true);
      nrfx_timer_compare(&m_t4,NRF_TIMER_CC_CHANNEL3,PULSE2_MAX,true);
      nrfx_timer_clear(&m_t4);
      nrfx_timer_enable(&m_t4);

    ant the failures are

    undefined reference to `nrfx_timer_init'
    undefined reference to `nrfx_timer_compare'
    undefined reference to `nrfx_timer_compare'
    undefined reference to `nrfx_timer_compare'
     undefined reference to `nrfx_timer_compare'
    undefined reference to `nrfx_timer_clear'
    undefined reference to `nrfx_timer_enable'
    undefined reference to `nrfx_timer_init'

    In fact the code compiles if TIMER_ENABLED is set, irrespective of NRFX_TIMER_ENABLED

    Any ideas? 

  • The legacy API configs will overwrite NRFX configs in apply_old_config.h if the legacy config is defined, regardless of if it is set or not. You need to completely remove the legacy configs from the sdk_config.h file in order for the NRFX configs to not be overwritten.

Related