From 445359c3b5a68fcda25ce4077bba21a6952c99ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=A4ger?= Date: Mon, 3 Aug 2020 14:51:54 +0200 Subject: [PATCH] Make CAN publication frequency more accurate Using K_TIMEOUT_ABS_MS for k_sleep calculate exact 1s interval. --- src/ext/can.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ext/can.cpp b/src/ext/can.cpp index a9014dc..6702fcc 100644 --- a/src/ext/can.cpp +++ b/src/ext/can.cpp @@ -133,6 +133,8 @@ void can_pub_thread() can_dev = device_get_binding("CAN_1"); + int64_t t_start = k_uptime_get(); + while (true) { watchdog_feed(wdt_channel); @@ -158,7 +160,8 @@ void can_pub_thread() } } - k_sleep(K_MSEC(1000)); + t_start += 1000; + k_sleep(K_TIMEOUT_ABS_MS(t_start)); } }