ncs zephyr timer with highest resolution for nrf52840 or nrf53 and lowest jitter

Hi team,

In NRF5,  the app_timer requires a minimum of 5 ticks (150us) in the source code comment. I tested and checked on a scope and it looked very solid. As soon as the timer expires, I would write directly to the GPIO register or starts a PWM (NRF_PWM0->TASKS_SEQSTART[0] = 1;) to observe on the scope ( and to reduce the overhead delay of an indicator).

I'm completely new to ncs zephyr and would like to figure how to get the best timer resolution I can. From what I researched, ktimer would be equivalent to app_timer that uses a RTC. Based only the recent commit: https://github.com/zephyrproject-rtos/zephyr/tree/main/tests/kernel/timer It looks like the smallest resolution would be 2 ticks (@32khz) or (actually at 1 tick@16khz ~60us. But I'm wondering what is the smallest delay can I use. Would it be roughly similar to the app_timer 3ticks ~ 180us ? 

I couldn't find an example of how to use ktimer. Also how would I toggle a pin with the least overhead in ncs zephyr such that I could observe the performance on ktimer. Would gpio_pin_toggle_dt() from zephyr have nested calls and introduce variable delay? Could I write directly to the gpio register such as 

NRF_P0->OUTCLR = (1UL << PIN_LED1); or NRF_P0->OUTSET = (1UL << PIN_LED1);

to minimize the overhead for a better scope measurement.

I'm wondering if the callback from ktimer is a short deterministic delay as if it's a real ISR. In other words, the load of the system wouldn't affect the timing jitter of a periodic event from ktimer. Thanks.

  • Hi,

    There is an zephyr RTOS running that will handle a lot of threads with various priority, and especially if you are running a protocol like BLE, the application will for sure delay the callback with several tens of us to meet the real-time requirements of the BLE protocol. So, I am not sure how useful the measurements you are performing here is? Usually if you have some tight real-time requirements you can for instance prepare the peripheral you need to execute at a given time, and create a ppi channel between the timer or rtc compare event and the task you want to execute, then the task will be executed exactly at the capture event (with a potential delay of a very few 16MHz periods).

    To get familiar with zephyr and nRF Connect SDK check out: https://academy.nordicsemi.com/ 

    Kenneth

Related