nrf52, use Systick or RTC?


After reading some questions about these topics I became a little confused.

I want to count milliseconds, so should I use Systick_Handler or use Real Time Counter Handler?

I've read that on sleep mode, Systick does not work, so this can be a pro to use RTC, but probably I will not set the NRF52 to sleep mode, so a simple and fast solution is to use Systick.

I've already tried with Systick, but the Systick_Handler never occurs, I'm not using sd_app_evt_wait(). What am I missing?

volatile uint32_t time = 0;

/* SysTick interrupt Handler. */
void SysTick_Handler(void)  {

int main(void)
    SysTick_Config(SystemCoreClock / 1000);

while (true) {}
  • Probably not a good idea to try to count milliseconds in code. Several things can and will go wrong with this. The first is that you will generate 1,000 interrupts every second, so depending on how much other code you run on the system the possibility of the NVIC dumping some of your interrupts due to overflow is real.

    Also, your code is secondary in the system. So if you choose to run the SD, your interrupts will only get serviced after the SD interrupts. Or, another way to think of it is that whenever any radio activity is going on, your code is not being serviced.

    Finally due to all of the other interrupts and their relative priority (eg, radio activity) the latency in servicing your millisecond handler could easily be nearly 1 millisecond.

    The only effective way to count milliseconds is in hardware. There are several dedicated counters that can be tied to the RTC or main system clock for this purpose. Then you only need to capture the counter value during events to find out the millisecond interval that has elapsed.

    Someone else recently had a very similar question. You can see it here:

  • Regarding "but probably I will not set the NRF52 to sleep mode"; Note that if you don't put the CPU in System ON Idle mode, the CPU will be in RUN mode all the time and consume a lot of power, and this would not be recommend if you are powering your chip from a battery. Using systick is therefore generally not recommended. The RTC as AmbystomaLabs mentioned is recommended for low-power applications.

  • Thanks AmbystomaLabs, I used RTC module and it works! On the future we will decide better how to measure time.

  • Thanks Sigurd. I am expecting not to use sleep mode but of course it always better to develop a scalable solution.

  • AmbystomaLabs, do you known if there is any peripheral on NRF52 to count time?