modm API documentation
|
Classes | |
class | modm::platform::SysTickTimer |
lbuild module: modm:platform:clock
The SysTick timer is used to provide a time point at milli- and microsecond resolution to implement the modm::Clock::now()
and modm::PreciseClock::now()
interfaces defined in the modm:architecture:clock
module.
For this, the timer is configured to run at 1/8th HCLK frequency and the 24-bit counter is loaded for an interrupt every 250ms (on ARMv7-M) or every 1ms (ARMv6-M). The interrupt increments the 32-bit counters by 250ms and 250'000us (or 1ms and 1000us) respectively.
Since this comes nowhere near the 1us resolution we want, the SysTick->VAL
counter is used to interpolate the time between interrupts with this algorithm:
The actual algorithm avoids the floating point division and is instead approximated with a 32x32=64-bit multiplication and a bit shift without loosing accuracy. This computation is very, very fast on ARMv7-M.
However, since ARMv6-M only has a 32x32=32-bit multiplication, the interrupt runs at 1ms, thus eliminating the multiplication for the millisecond clock, and allowing to fit into a 32-bit multiplication for the microsecond clock.