Hardware PWM using the timer peripheral. More...
Hardware PWM using the timer peripheral.
A single TIM peripheral can be used to control up to four PWM output channels, which share the same resolution and frequency but have independent duty cycles.
Note that PWM interferes with the use of a TimerHandle on the same timer.
Some channels have the option to choose which output pin they connect to. Only one pin can be connected to a given channel. Use the following table to determine which pin corresponds to each timer and channel.
TIM3:
TIM4:
TIM5:
Future work:
#include <pwm.h>
Classes | |
class | Channel |
struct | Config |
Configuration struct for the timer peripheral. More... | |
Public Types | |
enum class | Result { OK = 0 , ERR = 1 } |
Return values for PWM functions. More... | |
Public Member Functions | |
PWMHandle () | |
PWMHandle (const PWMHandle &other)=default | |
PWMHandle & | operator= (const PWMHandle &other)=default |
~PWMHandle () | |
Result | Init (const Config &config) |
Initialize the PWM peripheral according to the config. | |
Result | DeInit () |
Deinitialize the peripheral. | |
const Config & | GetConfig () const |
Returns a const reference to the Config struct. | |
Channel & | Channel1 () |
Get a reference to CH1 of this peripheral. Must be initialized before use. | |
Channel & | Channel2 () |
Get a reference to CH2 of this peripheral. Must be initialized before use. | |
Channel & | Channel3 () |
Get a reference to CH3 of this peripheral. Must be initialized before use. | |
Channel & | Channel4 () |
Get a reference to CH4 of this peripheral. Must be initialized before use. | |
void | SetPrescaler (uint32_t prescaler) |
Set the prescaler. | |
void | SetPeriod (uint32_t period) |
Set the period. | |
|
strong |
daisy::PWMHandle::PWMHandle | ( | ) |
|
default |
|
inline |
|
inline |
Get a reference to CH1 of this peripheral. Must be initialized before use.
|
inline |
Get a reference to CH2 of this peripheral. Must be initialized before use.
|
inline |
Get a reference to CH3 of this peripheral. Must be initialized before use.
|
inline |
Get a reference to CH4 of this peripheral. Must be initialized before use.
Result daisy::PWMHandle::DeInit | ( | ) |
Deinitialize the peripheral.
const Config & daisy::PWMHandle::GetConfig | ( | ) | const |
Returns a const reference to the Config struct.
Initialize the PWM peripheral according to the config.
void daisy::PWMHandle::SetPeriod | ( | uint32_t | period | ) |
Set the period.
void daisy::PWMHandle::SetPrescaler | ( | uint32_t | prescaler | ) |
Set the prescaler.