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

Single Shot timer

Hi,

I wanted to build a single shot timer using the nrf_timer library. I went into the library code and I couldn't understand some of the enumeration due to some lack of documentation. In the example simple_timer application, the single shot timer uses nrf_drv_timer_extended_compare instead of nrf_drv_timer_compare. Also it uses the NRF_TIMER_SHORT_COMPARE0_STOP_MASK.

Does STOP mean that the timer stops or does it keep counting under the hood?

Also does nrfx_timer_disable() mean that the counting stops in the physical timer or the software abstraction of the timer?

Can you give me a brief explanation of STOP vs CLEAR as well as COMPARE(x) types? Does CLEAR/STOP indicate that it reloads the timer thus making it a normal repeating timer?

Moreover, can you give me a simple way of implementing a single shot timer using the library and give me a way to reload it later and start again as I need?

Thanks!

  • Hi,

    Does STOP mean that the timer stops or does it keep counting under the hood?

     Yes, this is a low-level driver for the TIMER hardware peripheral. Triggering the STOP task will stop the timer.

    Also does nrfx_timer_disable() mean that the counting stops in the physical timer or the software abstraction of the timer?

    See answer above.

    Can you give me a brief explanation of STOP vs CLEAR as well as COMPARE(x) types? Does CLEAR/STOP indicate that it reloads the timer thus making it a normal repeating timer?

    STOP task will stop the timer from running/counting. CLEAR will reset the counter in the timer to 0. COMPARE is events that will be generated whenever the counter in the timer match whatever you have set in the CC registers. If you clear the timer on a compare event, it will become a repeated timer. Stopping the timer on a compare event will give you a one-shot timer.

    See the TIMER peripheral documentation for more details.

    If you do not need high-precision timers, you should consider using the app_timer library. This runs on the RTC/LFCLK, giving you much lower current consumption. There is a tutorial available here.

    Best regards,
    Jørgen

Related