rtic-rs / rtic

Real-Time Interrupt-driven Concurrency (RTIC) framework for ARM Cortex-M microcontrollers

Home Page:https://rtic.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Monotonic delays are too short

Finomnis opened this issue · comments

Given a monotonic tick rate of 1ms and we call DelayUs::delay_us(1200) on the monotonic.

  • Desired behavior: wait between 2ms and 3ms
  • Current behavior: wait between 0ms and 1ms (which isn't even correct sometimes)

Note that there is a discrepancy of 2ms (or rather: two timer ticks) between desired and current behavior.

  • 1ms comes from the fact that we need to compensate for timer uncertainty
  • 1ms comes from the fact that we use .micros() instead of .micros_at_least() in our DelayUs impls.

This is not only a problem in general, but also directly breaks the requirements of DelayUs:

Pauses execution for at minimum us microseconds. Pause can be longer if the implementation requires it due to precision/timing issues.