modm::PeriodicTimer::execute()
is very slow on first call after a longer pause
#1218
Labels
modm::PeriodicTimer::execute()
is very slow on first call after a longer pause
#1218
modm::PeriodicTimer::execute()
returns the passed cycles since the timer last expired. It computes them in a counting loop:In case the timer hasn't been used for a longer period of time the first run of
execute()
afterwards will be very slow. For a 2 hour break and a 5 ms period timer it blocks for 12ms on a 480 MHz H7. That equates to about 1.4 million counting cycles. It can be worked around by callingrestart()
after a longer delay, but I think this behaviour is unexpected and rather undesirable.My application doesn't require that counter. To quickly work around the issue in my code I've implemented a simplified version that only does:
I'm unsure what's the best way of addressing this in the modm implementation preserving the current functionality. Using division to calculate the missed cycles would be less efficient in the common case. Maybe only run one step of the loop and then do division if more cycles were skipped?
The text was updated successfully, but these errors were encountered: