atMETEO
An ATmega based weather station
Files | Classes

Wrapper for accessing built-in timers facilities. More...

Collaboration diagram for Timer module:

Files

file  timer.h
 Wrapper for accessing built-in timers facilities.
 

Classes

struct  Avr::TimerUtils< prescaler >
 Compile time calculation of clock select and conversion of time (in us) to system clock ticks given the CPU frequency (F_CPU) and the prescaler. More...
 
class  Avr::TimerInputCapture< prescaler, TObserver >
 C++ wrapper for accessing the built-in input capture facility for measuring the width of external pulses. More...
 

Detailed Description

Wrapper for accessing built-in timers facilities.


Class Documentation

◆ Avr::TimerUtils

struct Avr::TimerUtils

template<uint16_t prescaler>
struct Avr::TimerUtils< prescaler >

Compile time calculation of clock select and conversion of time (in us) to system clock ticks given the CPU frequency (F_CPU) and the prescaler.

Template Parameters
prescalerThe prescaler for the timer configuration.

Static Public Member Functions

static constexpr uint8_t clockSelect ()
 Calculates the clock select value for the given prescaler. More...
 
template<uint16_t us>
static constexpr uint16_t usToTicks ()
 Converts us to ticks for the given CPU frequency and prescaler. More...
 

Member Function Documentation

◆ clockSelect()

template<uint16_t prescaler>
static constexpr uint8_t Avr::TimerUtils< prescaler >::clockSelect ( )
inlinestatic

Calculates the clock select value for the given prescaler.

The clock select value is needed to configure the timer with the given prescaler. Typically it has to be set in the Timer/Counter Control Register (TCCR).

Usage:

Returns
The clock select value needed to configure the timer.

◆ usToTicks()

template<uint16_t prescaler>
template<uint16_t us>
static constexpr uint16_t Avr::TimerUtils< prescaler >::usToTicks ( )
inlinestatic

Converts us to ticks for the given CPU frequency and prescaler.

While time values are typically needed when writing an application, the Timer/Counter Register (TCNT) counts (prescaled) system clock ticks.

Usage:

uint16_t ticks = Avr::TimerUtils<8>::usToTicks<100>()
Template Parameters
usTime value (in us) to be converted into system clock ticks.
Returns
System clock ticks representing the time value us.

◆ Avr::TimerInputCapture

class Avr::TimerInputCapture

template<uint16_t prescaler, class TObserver>
class Avr::TimerInputCapture< prescaler, TObserver >

C++ wrapper for accessing the built-in input capture facility for measuring the width of external pulses.

Usage:

struct MyTimerObserver {
static void pulseWidthReceived(uint16_t pulseWidth) {
// Input capture event received with measured pulse width
}
};
int main() {
// ...
sei();
// ...
}
Template Parameters
prescalerThe prescaler for the timer configuration.
TObserverThe observer that is notified of input capture events using its void pulseWidthReceived(uint16_t pulseWidth) function.

Static Public Member Functions

static TimerInputCaptureinstance ()
 Returns the Avr::TimerInputCapture instance. More...
 

Member Function Documentation

◆ instance()

template<uint16_t prescaler, class TObserver >
static TimerInputCapture& Avr::TimerInputCapture< prescaler, TObserver >::instance ( )
inlinestatic

Returns the Avr::TimerInputCapture instance.

Returns
The Avr::TimerInputCapture instance.