diff --git a/firmware/util/timer.cpp b/firmware/util/timer.cpp index b30ab89..77be3d2 100644 --- a/firmware/util/timer.cpp +++ b/firmware/util/timer.cpp @@ -54,6 +54,8 @@ bool Timer::hasElapsedMs(float milliseconds) const { return hasElapsedUs(milliseconds * 1000); } +static const float usPerTick = 1000000.0 / CH_CFG_ST_FREQUENCY; + bool Timer::hasElapsedUs(float microseconds) const { auto delta = getTimestamp() - m_lastReset; @@ -64,10 +66,9 @@ bool Timer::hasElapsedUs(float microseconds) const { auto delta32 = (uint32_t)delta; - return delta32 > TIME_US2I(microseconds); + return delta32 > (microseconds / usPerTick); } - float Timer::getElapsedSeconds() const { return getElapsedSeconds(getTimestamp()); } @@ -96,7 +97,7 @@ float Timer::getElapsedUs(int64_t stamp) const { auto delta32 = (uint32_t)deltaNt; - return TIME_I2US(delta32); + return delta32 * usPerTick; } float Timer::getElapsedSecondsAndReset() {