modm API documentation

Classes

struct  modm::chrono::micro_clock
 
struct  modm::chrono::milli_clock
 

Typedefs

using modm::Clock = chrono::milli_clock
 
using modm::PreciseClock = chrono::micro_clock
 

Functions

template<class C , class D >
modm::IOStreammodm::operator<< (modm::IOStream &s, const std::chrono::time_point< C, D > &m)
 
template<class T , class R >
modm::IOStreammodm::operator<< (modm::IOStream &s, const std::chrono::duration< T, R > &m)
 

Detailed Description

lbuild module: modm:architecture:clock

To provide a system-wide time base this module provides two clocks:

These clocks are intended to measure time intervals:

const auto start = modm::PreciseClock::now();
how_long_does_this_function_take();
const auto duration = modm::PreciseClock::now() - start;
MODM_LOG_DEBUG << "Function took " << duration << modm::endl;

For additional common timeout and periodic timer use-cases also check out the modm:processing:timer module which uses these clocks.

Limitations

The clocks intended to be very lightweight to use, however, a few interface tradeoffs had to be made to achieve this goal.

    >
  1. The clocks are not steady with their 32-bit counters overflowing after a relatively short time. They must therefore only be used for measuring intervals, not absolute time.
  2. The clocks have unsigned durations to make it easy to work with intervals since the addition/subtraction of intervals works just fine on clocks wrapping around, on the important condition that the interval is shorter than the clocks wrap around time.
Warning
Use a RTC-backed calendar for timekeeping! These clocks are definitely not accurate over long periods of time, since they are based on the internal clock supplies, which may have significant drift and thus are no replacement for a Real-Time Clock!

Also check the modm:platform:clock module descriptions for additional limitations on clock resolution and clock drift depending on target.