Make CAN publication frequency more accurate

Using K_TIMEOUT_ABS_MS for k_sleep calculate exact 1s interval.
This commit is contained in:
Martin Jäger
2020-08-03 14:52:20 +02:00
parent 8f96343cf1
commit 445359c3b5
+4 -1
View File
@@ -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));
}
}