How to overcome timer delay


Dinh, Kien T
 

Hi,

I’m developing an app which requires fast sampling rate (~500 times per sec) via the ADC on the Arduino 101. It was alright using nano_timer_init/start/test APIs up version 1.5. However, after upgrading to version 1.6, noticeable time delay has been observed. To remove possible effects from other drivers, I’ve used the following code to test the time delay and got the below results.

It seems that the amount of delay is inversely proportional to the interval. For interval = 1000 ms, the delay is just 10 ms. But for interval as high as 10 ms, the delay becomes 1000 ms, making it impossible to use for high sampling rate app. Is there any Kconfig needs to be set or any way to minimize such delay?

=====

#include <zephyr.h>
#include <misc/printk.h>

#define INTERVAL 1

static int count;
static int t;

void timer_handler(struct k_timer *a_timer)
{
count += INTERVAL;
if (count % 1000 == 0) {
printk("Count %d, delta = %d\n", count,
k_uptime_get_32() - t);
t = k_uptime_get_32();
}
}

void main(void)
{
struct k_timer my_timer;

printk("Hello World! %s\n", CONFIG_ARCH);
k_timer_init(&my_timer, timer_handler, NULL);
t = k_uptime_get_32();
while (1) {
k_timer_start(&my_timer, INTERVAL, K_FOREVER);
k_timer_status_sync(&my_timer);
}
}
====

I got the same following outputs for both x86 qemu and Arduino 101 (x86):

* INTERVAL = 1000 (one second)
Count 1000, delta = 1010
Count 2000, delta = 1010
Count 3000, delta = 1010


* INTERVAL = 100 (one hundred millisecs)
Count 1000, delta = 1100
Count 2000, delta = 1100
Count 3000, delta = 1100


* INTERVAL = 10 (ten millisecs)
Count 1000, delta = 2000
Count 2000, delta = 2000
Count 3000, delta = 2000


* INTERVAL = 1 (one millisec)
Count 1000, delta = 20000
Count 2000, delta = 20000
Count 3000, delta = 20000


Thanks,
Kien

Join devel@lists.zephyrproject.org to automatically receive all group messages.