FastArduino  v1.7
C++ library to build fast but small Arduino/AVR projects
timer Namespace Reference

Defines all API to manipulate AVR Timers. More...

Classes

struct  Calculator
 Defines a set of calculation methods for the given NTIMER_ The behavior of these methods is specific to each AVR Timer are there can be many important differences between 2 timers on AVR. More...
 
class  PulseTimer
 Special kind of timer::Timer, specialized in emitting pulses with accurate width, according to a slow frequency. More...
 
class  RTT
 API to handle a real-time timer. More...
 
class  RTTEventCallback
 Utility to generate events from an RTT instance at a given period. More...
 
class  RTTRawTime
 Utility class to avoid costly instantiation of time::RTTTime from an interrupt routine. More...
 
class  SquareWave
 Simple API to generate a square wave to an output pin. More...
 
class  Timer
 General API to handle an AVR timer. More...
 

Enumerations

enum  TimerMode : uint8_t {
  TimerMode::NORMAL,
  TimerMode::CTC,
  TimerMode::FAST_PWM,
  TimerMode::PHASE_CORRECT_PWM
}
 Defines the mode of operation of a timer. More...
 
enum  TimerInterrupt : uint8_t {
  TimerInterrupt::OVERFLOW = board_traits::TimerInterrupt::OVERFLOW,
  TimerInterrupt::OUTPUT_COMPARE_A = board_traits::TimerInterrupt::OUTPUT_COMPARE_A,
  TimerInterrupt::OUTPUT_COMPARE_B = board_traits::TimerInterrupt::OUTPUT_COMPARE_B,
  TimerInterrupt::OUTPUT_COMPARE_C = board_traits::TimerInterrupt::OUTPUT_COMPARE_C,
  TimerInterrupt::INPUT_CAPTURE = board_traits::TimerInterrupt::INPUT_CAPTURE
}
 Defines the interrupts that can be handled by a timer. More...
 
enum  TimerOutputMode : uint8_t {
  TimerOutputMode::DISCONNECTED,
  TimerOutputMode::TOGGLE,
  TimerOutputMode::NON_INVERTING,
  TimerOutputMode::INVERTING
}
 Defines the "connection" between this timer and specific PWM output pins. More...
 
enum  TimerInputCapture : uint8_t {
  TimerInputCapture::RISING_EDGE,
  TimerInputCapture::FALLING_EDGE
}
 Defines the type of input capture we want for a timer. More...
 

Functions

constexpr TimerInterrupt operator| (TimerInterrupt i1, TimerInterrupt i2)
 Combine 2 timer interrupts for use with Timer.set_interrupts(). More...
 

Detailed Description

Defines all API to manipulate AVR Timers.

In order to properly use Timers, some concepts are important to understand:

  • Frequency and Prescaler
  • BOTTOM, TOP and MAX values
  • Modes of operation
  • Output modes

These concepts are described in details in AVR datasheets.

Enumeration Type Documentation

◆ TimerMode

enum timer::TimerMode : uint8_t
strong

Defines the mode of operation of a timer.

Enumerator
NORMAL 

Timer "Normal" mode: counter is incremented up to maximum value (0xFF for 8-bits Timer, 0xFFFF for 16-bits Timer), and then resets to 0.

Timer Overflow may generate an interrupt.

CTC 

Timer "Clear Timer on Compare match" mode: counter is incremented until it reaches "TOP" (OCRxA register value), then it is reset to 0.

Reaching TOP may trigger an interrupt.

FAST_PWM 

Timer "Fast Phase Width Modulation" mode: counter is incremented until it reaches MAX value (0xFF for 8-bits Timer, 0x3FF for 16-bits Timer).

In this mode the timer can be linked to PWM output pins to be automatically set or cleared when:

  • counter reaches MAX
  • counter reaches TOP (OCRxA or OCRxB) Reaching TOP and MAX may trigger interrupts.
PHASE_CORRECT_PWM 

Timer "Phase Correct Pulse Width Modulation" mode: counter is incremented until MAX (0xFF for 8-bits Timer, 0x3FF for 16-bits Timer), then decremented until 0, and incremented again...

In this mode the timer can be linked to PWM output pins to be automatically set or cleared when:

  • counter reaches MAX
  • counter reaches TOP (OCRxA or OCRxB) Reaching TOP and MAX may trigger interrupts.

Definition at line 187 of file timer.h.

◆ TimerInterrupt

enum timer::TimerInterrupt : uint8_t
strong

Defines the interrupts that can be handled by a timer.

See also
Timer::set_interrupts()
Enumerator
OVERFLOW 

This interrupt occurs when the counter overflows it maximum value.

OUTPUT_COMPARE_A 

This interrupt occurs when the counter reached OCRA.

OUTPUT_COMPARE_B 

This interrupt occurs when the counter reached OCRB.

OUTPUT_COMPARE_C 

This interrupt occurs when the counter reached OCRC.

Note that this interrupt is not supported by all timers.

INPUT_CAPTURE 

This interrupt occurs during input capture, i.e.

when a signal (rising or falling edge, according to currently set TimerInputCapture) is detected. Note that this interrupt is not supported by all timers.

Definition at line 228 of file timer.h.

◆ TimerOutputMode

enum timer::TimerOutputMode : uint8_t
strong

Defines the "connection" between this timer and specific PWM output pins.

Enumerator
DISCONNECTED 

No connection for this pin: pin is unaffected by timer operation.

TOGGLE 

Pin is toggled on Compare Match.

NON_INVERTING 

Pin is cleared on Compare Match.

For TimerMode::FAST_PWM and TimerMode::PHASE_CORRECT_PWM modes, pin will also be set when counter reaches BOTTOM (0). This is also known as "non-inverting" mode).

INVERTING 

Pin is set on Compare Match.

For TimerMode::FAST_PWM and TimerMode::PHASE_CORRECT_PWM modes, pin will also be cleared when counter reaches BOTTOM (0). This is also known as "inverting" mode).

Definition at line 262 of file timer.h.

◆ TimerInputCapture

enum timer::TimerInputCapture : uint8_t
strong

Defines the type of input capture we want for a timer.

Enumerator
RISING_EDGE 

Input capture needed on rising edge of ICP pin.

FALLING_EDGE 

Input capture needed on falling edge of ICP pin.

Definition at line 285 of file timer.h.

Function Documentation

◆ operator|()

constexpr TimerInterrupt timer::operator| ( TimerInterrupt  i1,
TimerInterrupt  i2 
)
constexpr

Combine 2 timer interrupts for use with Timer.set_interrupts().

See also
Timer.set_interrupts()

Definition at line 254 of file timer.h.