46 template<board::Timer NTIMER_, board::PWMPin OUTPUT_>
class SquareWave
72 using TRAIT = board_traits::PWMPin_trait<OUTPUT>;
73 static_assert(TRAIT::COM == 0,
"Only OCnA pin is supported for wave generation");
107 const uint32_t period = ONE_SECOND / 2 / frequency;
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 b...
Simple API to generate a square wave to an output pin.
void start_frequency(typename TIMER::PRESCALER prescaler, typename TIMER::TYPE counter)
Start producing, on the output pin, a square wave, which frequency matches the specified prescaler an...
static constexpr const board::Timer NTIMER
The AVR timer used for the underlying Timer.
void start_frequency(uint32_t frequency)
Start producing, on the ouput pin, a square wave with the specified frequency.
static constexpr const board::DigitalPin PIN
The pin to which this SquareWave generator is connected.
analog::PWMOutput< OUTPUT > PWMPIN
The analog::PWMOutput type for the OUTPUT board::PWMPin.
const TIMER & timer() const
Return the underlying timer::Timer of this SquareWave generator.
TIMER & timer()
Return the underlying timer::Timer of this SquareWave generator.
static constexpr const board::PWMPin OUTPUT
The board::PWMPin connected to this SquareWave generator.
timer::Timer< NTIMER > TIMER
The type of underlying timer::Timer used by this SquareWave generator.
SquareWave()
Instantiate a SquareWave generator.
void stop()
Stop square wave generation.
void begin(TYPE max=0)
Start this timer in the currently selected mode, with the provided prescaler value and max value.
typename TRAIT::TYPE TYPE
The type of this timer's counter (either uint8_t or uint16_t).
typename PRESCALERS_TRAIT::TYPE PRESCALER
The enum type listing all available precaler values for this timer.
void end()
Completely stop this timer: timer interrupts are disabled and counter is stopped.
void set_prescaler(PRESCALER prescaler)
Change prescaler for this timer.
PWMPin
Defines all digital output pins of target MCU, capable of PWM output.
DigitalPin
Defines all available digital input/output pins of the target MCU.
Timer
Defines all timers available for target MCU.
Defines all API to manipulate AVR Timers.
TimerOutputMode
Defines the "connection" between this timer and specific PWM output pins.
@ TOGGLE
Pin is toggled on Compare Match.
@ CTC
Timer "Clear Timer on Compare match" mode: counter is incremented until it reaches "TOP" (OCRxA regis...
Defines a set of calculation methods for the given NTIMER_ The behavior of these methods is specific ...
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,...
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...