Timer accuracy for micro seconds

Hi,

i defined timer 
K_TIMER_DEFINE(my_timer, my_timer_handler, NULL);

then i am starting  the timer with configuration :

k_timer_start(&my_timer, K_USEC(500), K_USEC(500));
The issue that the 
the handler prints log every 581.5 us instead of 500.
What can be the reason?or how to trigger some handler every 500 us
Thanks
Parents Reply Children
  • MaximSh said:
    So how to run polling of some code every 500 microseconds without using timer?

    Not sure if I understand this right, you want to have a time waiting code that waits for 500uS without using any timer? I am guessing that you want to use Kernel API for that instead of directly using timer API.

    In that case you can only sleep with a resolution of the timer tick(SYS_CLOCK_TICKS_PER_SEC default value is 32768 on RTC) . If you want  any better resolution, then you need to use high resolution timer API like nrfx_timer or nrfx_systick. The disadvantage of using high resolution timers is that they keep the high frequency clock on all the time and hence increasing the average power consumption of your application. If your application is running on a battery, it will be drained within days (if not hours)

Related