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

Microsecond timer for nRF52

Hello,

I would like to implement a precise timer which calculates/counts the time in microseconds which I can use for calculating the time elapsed between parts of the code. The timer just needs to run continously and start over once it overflows.

What is the simplest way to implement such a timer?

Thanks.

  • You can use the TIMER, a TIMER on the nRF52 running on 16MHz clock so the lowest resolution is 62,5 nanosecond, it should be easy to count microseconds. You can use the CAPTURE task to capture the value of the timer. You can use the TIMER directly or use our nrf_drv_timer provided in the SDK.

  • Thanks for your reply. I have now searched the forum for more information about the TIMER and the nrf_drv_timer driver and I can see that someone mentions, that the timers are not accurate, when a softdevice is used in the application. Is that correct?

  • Yes, you may get latency when the softdevice is active (when there is BLE event) and need to occupy the CPU, same when you have any flash activity. The TIMER is still running property, but the CPU may be delayed to serve the interrupt handler.

    However, we provided some solutions to overcome this, one is to use radio notification. You can use the radio notification to know that the softdevice will not be active after the event, at least for a period of time (dozens of miliseconds depends on your connection interval). Another option is to use timeslot

    How often do you need to measure code processing time ? Can measuring be done by PPI and CAPTURE task (so no CPU be involved) or it must the CPU be involved ?

Related