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

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...
#include <fastarduino/timer.h>
Public Types  
using  TYPE = typename TRAIT::TYPE 
The timer type: either uint8_t or uint16_t ; this is defined and not changeable for each Timer. More...  
using  PRESCALER = typename PRESCALERS_TRAIT::TYPE 
The type (enum ) of the possible prescaler values for this timer; this is defined and not changeable for each Timer.  
Static Public Member Functions  
static constexpr PRESCALER  tick_prescaler (uint32_t us_per_tick) 
Computes the ideal prescaler to use for this timer, in order to generate timer ticks of us_per_tick microseconds or less. More...  
static constexpr uint32_t  ticks_to_us (PRESCALER prescaler, TYPE ticks) 
Computes the number of microseconds reached for a given number of ticks with a given prescaler . More...  
static constexpr TYPE  us_to_ticks (PRESCALER prescaler, uint32_t us) 
Computes the number of ticks needed for reaching the given us microseconds with a given prescaler . More...  
static constexpr PRESCALER  CTC_prescaler (uint32_t us) 
Computes the ideal prescaler value to use for this timer, in TimerMode::CTC mode, in order to be able to count up to us microseconds. More...  
static constexpr uint32_t  CTC_frequency (PRESCALER prescaler) 
Computes the frequency at which this timer would perform, in TimerMode::CTC mode, if it was using prescaler . More...  
static constexpr TYPE  CTC_counter (PRESCALER prescaler, uint32_t us) 
Computes the value of counter to use for this timer, in TimerMode::CTC mode, with prescaler , in order to reach us microseconds. More...  
static constexpr bool  is_adequate_for_CTC (PRESCALER prescaler, uint32_t us) 
Verifies that the given prescaler prescaler is suitable for this timer in TimerMode::CTC in order to be able to reach us microseconds. More...  
static constexpr PRESCALER  FastPWM_prescaler (uint16_t pwm_frequency) 
Computes the ideal prescaler value to use for this timer, in TimerMode::FAST_PWM mode, in order to be able to reach at least pwm_frequency . More...  
static constexpr uint16_t  FastPWM_frequency (PRESCALER prescaler) 
Computes the frequency at which this timer would perform, in TimerMode::FAST_PWM mode, if it was using prescaler . More...  
static constexpr PRESCALER  PhaseCorrectPWM_prescaler (uint16_t pwm_frequency) 
Computes the ideal prescaler value to use for this timer, in TimerMode::PHASE_CORRECT_PWM mode, in order to be able to reach at least pwm_frequency . More...  
static constexpr uint16_t  PhaseCorrectPWM_frequency (PRESCALER prescaler) 
Computes the frequency at which this timer would perform, in TimerMode::PHASE_CORRECT_PWM mode, if it was using prescaler . More...  
static constexpr PRESCALER  PulseTimer_prescaler (uint16_t max_pulse_width_us, uint16_t pulse_frequency) 
Computes the ideal prescaler value to use for this timer, when used in timer::PulseTimer, in order to be able to reach at least pulse_frequency with a maximum pulse width of max_pulse_width_us . More...  
static constexpr TYPE  PulseTimer_value (PRESCALER prescaler, uint16_t period_us) 
Computes the ideal value to use for this timer, when used in timer::PulseTimer, in order to produce a pulse of the required width period_us with the given prescaler . More...  
static constexpr PRESCALER  PWM_ICR_prescaler (uint16_t pwm_frequency) 
Computes the ideal prescaler value to use for this timer, when used in timer::PulseTimer, in order to be able to reach at least pulse_frequency with a maximum pulse width of max_pulse_width_us . More...  
static constexpr uint16_t  PWM_ICR_frequency (PRESCALER prescaler, uint16_t counter) 
Computes the frequency at which this timer would perform, when used in timer::PulseTimer, if it was using prescaler and counter . More...  
static constexpr uint16_t  PWM_ICR_counter (PRESCALER prescaler, uint16_t pwm_frequency) 
Computes the ideal counter TOP value to use for this timer, when used in timer::PulseTimer, in order to be able to reach at least pulse_frequency with the given prescaler . More...  
Static Public Attributes  
static constexpr const board::Timer  NTIMER = NTIMER_ 
The timer for which calculation methods are provided.  
static constexpr const TYPE  PWM_MAX = TRAIT::MAX_PWM 
The maximum value you can use for this timer in PWM modes: using this value will set PWM duty as 100%.  
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.
NTIMER_  the timer for which we need calculation methods 
using timer::Calculator< NTIMER_ >::TYPE = typename TRAIT::TYPE 

inlinestaticconstexpr 
Computes the ideal prescaler to use for this timer, in order to generate timer ticks of us_per_tick
microseconds or less.
Note this is a constexpr
method, i.e. it allows compiletime computation when provided a constant argument.
us_per_tick  the maximum number of us to be reached by one counter tick 

inlinestaticconstexpr 
Computes the number of microseconds reached for a given number of ticks
with a given prescaler
.
Note this is a constexpr
method, i.e. it allows compiletime computation when provided a constant argument.
prescaler  the prescaler used for this calculation 
ticks  the number of ticks for which we want to know the number of microseconds elapsed 
ticks
with prescaler

inlinestaticconstexpr 
Computes the number of ticks needed for reaching the given us
microseconds with a given prescaler
.
Note this is a constexpr
method, i.e. it allows compiletime computation when provided a constant argument.
prescaler  the prescaler used for this calculation 
us  the number of microseconds we want to reach 
us
microseconds elapsed

inlinestaticconstexpr 
Computes the ideal prescaler value to use for this timer, in TimerMode::CTC mode, in order to be able to count up to us
microseconds.
Note this is a constexpr
method, i.e. it allows compiletime computation when provided a constant argument.
us  the number of microseconds we want to be able to count up to 

inlinestaticconstexpr 
Computes the frequency at which this timer would perform, in TimerMode::CTC mode, if it was using prescaler
.
Note this is a constexpr
method, i.e. it allows compiletime computation when provided a constant argument.
prescaler  the prescaler value for which to compute timer frequency 
prescaler

inlinestaticconstexpr 
Computes the value of counter to use for this timer, in TimerMode::CTC mode, with prescaler
, in order to reach us
microseconds.
Note this is a constexpr
method, i.e. it allows compiletime computation when provided constant arguments.
prescaler  the prescaler used for this timer 
us  the number of microseconds to reach with this timer in CTC mode 
us

inlinestaticconstexpr 
Verifies that the given prescaler prescaler
is suitable for this timer in TimerMode::CTC in order to be able to reach us
microseconds.
This is normally not needed but can be helpful in a static_assert
in your code. Note this is a constexpr
method, i.e. it allows compiletime computation when provided constant arguments. You could use this method in static_assert()
in order to check that the requested period us
is OK for this timer.
prescaler  the prescaler used for this timer 
us  the number of microseconds to reach with this timer in CTC mode 
<tt>true</tt>  if prescaler and us are adequate for TIMER 
<tt>false</tt>  if prescaler and us are NOT adequate for TIMER 

inlinestaticconstexpr 
Computes the ideal prescaler value to use for this timer, in TimerMode::FAST_PWM mode, in order to be able to reach at least pwm_frequency
.
Note this is a constexpr
method, i.e. it allows compiletime computation when provided a constant argument.
pwm_frequency  the PWM frequency we want to reach 

inlinestaticconstexpr 
Computes the frequency at which this timer would perform, in TimerMode::FAST_PWM mode, if it was using prescaler
.
Note this is a constexpr
method, i.e. it allows compiletime computation when provided a constant argument.
prescaler  the prescaler value for which to compute timer frequency 
prescaler

inlinestaticconstexpr 
Computes the ideal prescaler value to use for this timer, in TimerMode::PHASE_CORRECT_PWM mode, in order to be able to reach at least pwm_frequency
.
Note this is a constexpr
method, i.e. it allows compiletime computation when provided a constant argument.
pwm_frequency  the PWM frequency we want to reach 

inlinestaticconstexpr 
Computes the frequency at which this timer would perform, in TimerMode::PHASE_CORRECT_PWM mode, if it was using prescaler
.
Note this is a constexpr
method, i.e. it allows compiletime computation when provided a constant argument.
prescaler  the prescaler value for which to compute timer frequency 
prescaler

inlinestaticconstexpr 
Computes the ideal prescaler value to use for this timer, when used in timer::PulseTimer, in order to be able to reach at least pulse_frequency
with a maximum pulse width of max_pulse_width_us
.
Note this is a constexpr
method, i.e. it allows compiletime computation when provided a constant argument.
max_pulse_width_us  the maximum pulse width, in microseconds, to produce 
pulse_frequency  the pulse frequency we want to reach 

inlinestaticconstexpr 
Computes the ideal value to use for this timer, when used in timer::PulseTimer, in order to produce a pulse of the required width period_us
with the given prescaler
.
Note this is a constexpr
method, i.e. it allows compiletime computation when provided a constant argument.
Note that this method is directly called as needed by timer::PulseTimer, hence you generally won't need to call it yourself.
prescaler  the prescaler value for which to compute value 
period_us  the pulse width, in microseconds, to produce 

inlinestaticconstexpr 
Computes the ideal prescaler value to use for this timer, when used in timer::PulseTimer, in order to be able to reach at least pulse_frequency
with a maximum pulse width of max_pulse_width_us
.
This method applies only to 16bits timers, for which PulseTimer uses FastPWM mode with register ICR
as TOP value. Note this is a constexpr
method, i.e. it allows compiletime computation when provided a constant argument.
Note that this method is directly called as needed by timer::PulseTimer, hence you generally won't need to call it yourself.
pwm_frequency  the pulse frequency we want to reach 

inlinestaticconstexpr 
Computes the frequency at which this timer would perform, when used in timer::PulseTimer, if it was using prescaler
and counter
.
This method applies only to 16bits timers, for which PulseTimer uses FastPWM mode with register ICR
as TOP value.
Note this is a constexpr
method, i.e. it allows compiletime computation when provided a constant argument.
prescaler  the prescaler value for which to compute timer frequency 
counter  the counter value for which to compute timer frequency 

inlinestaticconstexpr 
Computes the ideal counter TOP value to use for this timer, when used in timer::PulseTimer, in order to be able to reach at least pulse_frequency
with the given prescaler
.
This method applies only to 16bits timers, for which PulseTimer uses FastPWM mode with register ICR
as TOP value.
Note this is a constexpr
method, i.e. it allows compiletime computation when provided a constant argument.
prescaler  the prescaler value for which to compute timer frequency 
pwm_frequency  the pulse frequency we want to reach 
ICR
register