Skyward boardcore
|
Driver for easy access to the PWM capabilities of the general purpose timers. More...
#include <PWM.h>
Public Types | |
enum class | Polarity : uint16_t { NORMAL = 0 , REVERSED = 0x1 } |
Public Member Functions | |
PWM (TIM_TypeDef *const pulseTimer, uint16_t pulseFrequency=50) | |
Sets up and enables the PWM timer. | |
~PWM () | |
void | setFrequency (uint16_t pulseFrequency) |
void | setDutyCycleResolution (uint16_t dutyCycleResolution) |
void | enableChannel (TimerUtils::Channel channel, Polarity polarity=Polarity::NORMAL) |
void | disableChannel (TimerUtils::Channel channel) |
bool | isChannelEnabled (TimerUtils::Channel channel) |
void | setDutyCycle (TimerUtils::Channel channel, float dutyCycle) |
Sets the duty cycle for the specified channel. | |
float | getDutyCycle (TimerUtils::Channel channel) |
Return the channel's duty cycle in the range [0,1]. | |
GP16bitTimer & | getTimer () |
Returns the timer used to generate the pwm signal. | |
Driver for easy access to the PWM capabilities of the general purpose timers.
Note that the pwm timer is started when the object is created (and disabled when deleted) but no channels are enabled. This means that you will only need to use the channels without worrying about the underlying timer.
The PWM driver accepts a pointer to the peripheral registers of a timer and uses it as a 16bit general purpose timer. No checks are in place to this pointer, thus make sure to pass a proper value!
Moreover, even 32bit general purpose timers are used as if they where 16bit. At the moment there is no need for further accuracy but if it ever will be, exceeding this class is simple, just add a template parameter and pass it to the GeneralPurposeTimer parameter.
Check out the following spread sheet to visually see how the timers registers are calculated and the accuracy achieved: https://docs.google.com/spreadsheets/d/1FiNDVU7Rg98yZzz1dZ4GDAq3-nEg994ziezCawJ-OK4/edit#gid=0
|
strong |
|
explicit |
void Boardcore::PWM::disableChannel | ( | TimerUtils::Channel | channel | ) |
void Boardcore::PWM::enableChannel | ( | TimerUtils::Channel | channel, |
Polarity | polarity = Polarity::NORMAL ) |
float Boardcore::PWM::getDutyCycle | ( | TimerUtils::Channel | channel | ) |
GP16bitTimer & Boardcore::PWM::getTimer | ( | ) |
bool Boardcore::PWM::isChannelEnabled | ( | TimerUtils::Channel | channel | ) |
void Boardcore::PWM::setDutyCycle | ( | TimerUtils::Channel | channel, |
float | dutyCycle ) |
void Boardcore::PWM::setDutyCycleResolution | ( | uint16_t | dutyCycleResolution | ) |