Skip to content

Commit 9d11dd3

Browse files
fix: loss in accuracy by not adding 1: #534 (comment)
1 parent 4ae1dbb commit 9d11dd3

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

Src/HALAL/Services/Time/Scheduler.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,8 @@ void Scheduler::schedule_next_interval() {
227227
Scheduler::global_timer_enable();
228228
uint8_t next_id = Scheduler::front_id(); // sorted_task_ids_[0]
229229
Task& next_task = tasks_[next_id];
230-
uint64_t delta = (next_task.next_fire_us > global_tick_us_)
231-
? (next_task.next_fire_us - global_tick_us_ + 1ULL) : 1ULL; // +1 to ensure we don't miss, means loss in accuracy
232-
233-
//TODO: Adding 1 accumulates drift over time analyze if acceptable, it can be solved by adding an extra if
230+
uint64_t delta = (next_task.next_fire_us > (global_tick_us_ - 1ULL))
231+
? (next_task.next_fire_us - global_tick_us_) : 1ULL;
234232

235233
if (delta > kMaxIntervalUs) [[unlikely]] {
236234
current_interval_us_ = kMaxIntervalUs;

0 commit comments

Comments
 (0)