Hi,
I just want to learn if we can use high-freq clock to measure time in nanosecs precision.
SoC: nRF52840
SDK: nRF Connect SDK (v1.9)
I know that it was not possible 2 years ago but I just wonder whether it can be enabled in nRF Connect SDK-v1.9 somehow.
For example, this doesn't work properly:
static void heartbeat(void *p1, void *p2, void *p3)
{
timing_t start_time = 0, end_time = 0;
uint64_t total_cycles = 0;
uint64_t total_ns = 0;
timing_init();
timing_start();
while (1)
{
start_time = timing_counter_get();
k_msleep(1000);
end_time = timing_counter_get();
total_cycles = timing_cycles_get(&start_time, &end_time);
total_ns = timing_cycles_to_ns(total_cycles);
gpio_pin_toggle(led1.port, led1.pin);
printk("%s start=%llu end=%llu diff_ns=%llu\n", __func__, start_time, end_time, total_ns);
}
timing_stop();
}
Output:
heartbeat start=142232262 end=142238263 diff_ns=93765 heartbeat start=142539990 end=142545991 diff_ns=93765
The difference between start and end is around 6000 and the computed diff in ns is 93765, which is obviously wrong.
Any help with this example would be highly appreciated. Many thanks,
Ozan