FastArduino  v1.7
C++ library to build fast but small Arduino/AVR projects
analog::PWMOutput< PWMPIN_, PULSED_ > Class Template Reference

Construct a new handler for a PWM output pin. More...

#include <fastarduino/pwm.h>

Public Types

using TIMER = timer::Timer< TRAIT::TIMER >
 The actual timer::Timer type associated to this PWMOutput.
 
using TYPE = typename TIMER_TRAIT::TYPE
 The type (either uint8_t or uint16_t) of values acceptable for duty in set_duty(). More...
 

Public Member Functions

 PWMOutput (const PWMOutput< PWMPIN_, PULSED_ > &)=delete
 
PWMOutput< PWMPIN_, PULSED_ > & operator= (const PWMOutput< PWMPIN_, PULSED_ > &)=delete
 
 PWMOutput (TIMER &timer, TimerOutputMode output_mode=TimerOutputMode::NON_INVERTING)
 Construct a new PWM output pin, connected to timer, using output_mode. More...
 
void set_output_mode (TimerOutputMode output_mode)
 Change the connection output mode of this PWM pin to its timer. More...
 
void set_duty (TYPE duty)
 Set the duty cycle for this PWM pin, from 0 (0% duty cycle) to MAX (100%), any value above MAX will be used as 100%. More...
 

Static Public Attributes

static constexpr const board::PWMPin PWMPIN = PWMPIN_
 The PWM pin for this PWMOutput.
 
static constexpr const bool PULSED = PULSED_
 Whether this PWMOutput uses a timer::PulseTimer instead of a timer::Timer.
 
static constexpr const board::DigitalPin PIN = TRAIT::ACTUAL_PIN
 The digital pin for this PWMOutput.
 
static constexpr const TYPE MAX = TIMER_TRAIT::MAX_PWM
 The maximum acceptable value for duty in set_duty(). More...
 

Detailed Description

template<board::PWMPin PWMPIN_, bool PULSED_ = false>
class analog::PWMOutput< PWMPIN_, PULSED_ >

Construct a new handler for a PWM output pin.

Template Parameters
PWMPIN_the board::PWMPin to use as PWM output
PULSED_whether to use a timer::PulseTimer instead of a timer::Timer; this is useful when e.g. you want to use a PWM pin to manage a servo motor, where pulses shall be limited to a few ms but triggered every few dozen ms.

Definition at line 53 of file pwm.h.

Member Typedef Documentation

◆ TYPE

template<board::PWMPin PWMPIN_, bool PULSED_ = false>
using analog::PWMOutput< PWMPIN_, PULSED_ >::TYPE = typename TIMER_TRAIT::TYPE

The type (either uint8_t or uint16_t) of values acceptable for duty in set_duty().

See also
set_duty()
MAX

Definition at line 119 of file pwm.h.

Constructor & Destructor Documentation

◆ PWMOutput()

template<board::PWMPin PWMPIN_, bool PULSED_ = false>
analog::PWMOutput< PWMPIN_, PULSED_ >::PWMOutput ( TIMER timer,
TimerOutputMode  output_mode = TimerOutputMode::NON_INVERTING 
)
inline

Construct a new PWM output pin, connected to timer, using output_mode.

This will not compile if PIN is not a PWM pin or its is not connectable to timer.

Parameters
timerthe timer to which this PWM pin must be connected
output_modethe connection output mode to use; note this is not used in pulsed mode, i.e. when PULSED template argument is true.

Definition at line 93 of file pwm.h.

Member Function Documentation

◆ set_output_mode()

template<board::PWMPin PWMPIN_, bool PULSED_ = false>
void analog::PWMOutput< PWMPIN_, PULSED_ >::set_output_mode ( TimerOutputMode  output_mode)
inline

Change the connection output mode of this PWM pin to its timer.

Parameters
output_modethe new connection output mode to use; note this is not used in pulsed mode, i.e. when PULSED template argument is true.

Definition at line 108 of file pwm.h.

◆ set_duty()

template<board::PWMPin PWMPIN_, bool PULSED_ = false>
void analog::PWMOutput< PWMPIN_, PULSED_ >::set_duty ( TYPE  duty)
inline

Set the duty cycle for this PWM pin, from 0 (0% duty cycle) to MAX (100%), any value above MAX will be used as 100%.

Parameters
dutynew duty cycle for this PWM pin
See also
TYPE
MAX

Definition at line 135 of file pwm.h.

Member Data Documentation

◆ MAX

template<board::PWMPin PWMPIN_, bool PULSED_ = false>
constexpr const TYPE analog::PWMOutput< PWMPIN_, PULSED_ >::MAX = TIMER_TRAIT::MAX_PWM
staticconstexpr

The maximum acceptable value for duty in set_duty().

See also
set_duty()
TYPE

Definition at line 126 of file pwm.h.


The documentation for this class was generated from the following file: