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

SysTick timer on nRF52 fires 1/5 as often as expected

Hi,

I'm trying to use the SysTick timer on nRF52 to time some various tasks for debugging. I configured it like so, which I expected would cause SysTick_Handler to be called every 1ms (SystemCoreClock is indeed 64000000):

SysTick_Config(SystemCoreClock/1000);

However, if I simply increment a counter in the SysTick_Handler and print out the value every 1s (I'm using app_timer to fire a timer every 1000ms), the counter only increments by 200 every second, instead of 1000.

Has anyone been able to use SysTick successfully on nRF52? Note that this is with PCA10036 - I looked in the errata but didn't see any issues related to SysTick_Config.

Parents
  • Hi,

    Seems to work fine at my end. Here's my code-snippet (based on blinky):

    const uint8_t leds_list[LEDS_NUMBER] = LEDS_LIST;
    
    static uint32_t m_systick_cnt;
    
    void SysTick_Handler(void) {
        m_systick_cnt++;
        if ((m_systick_cnt % 100) == 0)
            nrf_gpio_pin_toggle(BSP_LED_0); 
    }
    
    int main(void)  
    {
        // Configure LED-pins as outputs.
        LEDS_CONFIGURE(LEDS_MASK);
        SysTick_Config(64000);
        NVIC_EnableIRQ(SysTick_IRQn);
        while (true);      
    }
    

    And here's the measured interval, based on 100 ticks: image description

    Cheers, Håkon

  • Hi @Håkon Alseth - thanks for your reply and for testing this! I was also able to reproduce your results using blinky.

    It turns out my issue was caused by my app calling sd_app_evt_wait() in the main loop, which calls __WFE(). Apparently, __WFE slows down the system clock which affects the SysTick frequency.

    If I omit sd_app_evt_wait() from my application, the counter increments at the expected rate.
    Thanks again for testing this out, it really helped to figure out the issue!!

Reply
  • Hi @Håkon Alseth - thanks for your reply and for testing this! I was also able to reproduce your results using blinky.

    It turns out my issue was caused by my app calling sd_app_evt_wait() in the main loop, which calls __WFE(). Apparently, __WFE slows down the system clock which affects the SysTick frequency.

    If I omit sd_app_evt_wait() from my application, the counter increments at the expected rate.
    Thanks again for testing this out, it really helped to figure out the issue!!

Children
No Data
Related