How many system ticks mean 1ms?

Hi,

     I need to use system tick to do some math calculate. So I create a new function to get systick like as below. then I can get some number.

uint32_t nrf_drv_systick_get_for_cadence()
{
    return nrf_systick_val_get();
}

And I create a 200ms timer to get systick every 200ms. like as below

static void data_process_handler(void * p_context)
{ 
    uint32_t time_diff;
    
    time_diff = nrf_drv_systick_get_for_cadence();
    printf("%d\r\n",time_diff);
}

In my understanding, 52832 cpu frequency is fixed on 64MHz. So I refer to below function. I guess 64000 systick is mean "1ms"

So if I printf systick result every 200ms, I think that the result is always increase 64000 * 200 = 12800000

static inline uint32_t nrf_drv_systick_ms_tick(uint32_t ms)
{
    return ms * ((SystemCoreClock) / NRF_DRV_SYSTICK_MS);
}
 

But the result is not my imagination.

31298
4007830
7984375
11960898
15937430
3136746
7113278
11089819
15066342
2265658
6242190
10218722
14195271
1394570
5371102
9347634
13324166
523499
4500014
8476546
12453078

So My question is how many system ticks mean "1ms"? Is there anything I misunderstood?

Thank you.

John.

  • Hi,

           Add a bit of information.

    1. Based on my result. sound like 19885 systicks mean "1ms"

    2. I don't use nrf_pwr_mgmt_run()

    void main()
    {
        for (;;)
        {
            if (m_saadc_calibrate == true) 
            {
                nrf_drv_saadc_abort();
                while(nrf_drv_saadc_calibrate_offset() != NRF_SUCCESS); //Trigger calibration task
                m_saadc_calibrate = false;
            }
            //nrf_pwr_mgmt_run();
        }
    }

  • Hi,

    You are right that the SysTick frequency is 64 MHz. I see in your update you commented out nrf_pwr_mgmt_run(), and in that case you will get predictable values. In most real prodcuts the SysTick implementation is not practical though, as it pauses when the CPU pauses.

    I did not understand the use case, but in most practical applications where you want to call a function repeatedly at a specific interval you would want to use the RTC instead, as it runs always and is low power. If that is what you are after, then the app_timer library is probably what you want.

  • Hi,

         In fact, I want to have a number so that I can continue to get it. And the resolution of the number has to be very high.

    Because I want to develop cycling cadence algorithm and I want to get systick number. I use last systick number and presen t systick number to get a difference time to calculate.

    cadence_time_end = nrf_drv_systick_get_for_cadence();
    cadence_time_diff = (0xFFFFFF & (cadence_time_start - cadence_time_end));
    cadence_time_start = cadence_time_end;
            
    gear_ratio_temp = CalGearRatio(cadence_time_diff);
    if(gear_ratio_temp != -1.0)
        v_gear_ratio = gear_ratio_temp;

    Or do you have any better suggestions?

  • Will this cycle computer be battery operated? If so, will this algorithm run continuously? If so this is very likely not a sensibel approach, simply from an energy perspective. As mentioned systick does not work while the CPU is sleeping, so you cannot be low power.

    Can you quantify how high resolution you need? If a 32.768 kHz clock is enough, then you can get very low power using an RTC (often via app_timer so you don't need a dedicated RTC instance). If you need higher resolution but with more flexibility, then a TIMER peripheral is what you want.

  • Hi,

         This device can be plugged into a power outlet. So don't worry about power consumption issue.

    I need a maximum resolution. The bigger the better. That’s why I want to use this method. This is the method with the largest timer resolution I can think about.

    Thank you.

    John.

        

Related