Skyward boardcore
Loading...
Searching...
No Matches
Boardcore::PWM Class Reference

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].
 
GP16bitTimergetTimer ()
 Returns the timer used to generate the pwm signal.
 

Detailed Description

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

Definition at line 51 of file PWM.h.

Member Enumeration Documentation

◆ Polarity

enum class Boardcore::PWM::Polarity : uint16_t
strong
Enumerator
NORMAL 

Signal is high for the duty cycle time.

REVERSED 

Signal is low for the duty cycle time.

Definition at line 54 of file PWM.h.

Constructor & Destructor Documentation

◆ PWM()

Boardcore::PWM::PWM ( TIM_TypeDef *const pulseTimer,
uint16_t pulseFrequency = 50 )
explicit

Sets up and enables the PWM timer.

Parameters
pulseTimerTimer used for the generation of the PWM signal.
pulseFrequencyFrequency of the PWM signal.

Definition at line 30 of file PWM.cpp.

◆ ~PWM()

Boardcore::PWM::~PWM ( )

Definition at line 42 of file PWM.cpp.

Member Function Documentation

◆ disableChannel()

void Boardcore::PWM::disableChannel ( TimerUtils::Channel channel)

Definition at line 68 of file PWM.cpp.

◆ enableChannel()

void Boardcore::PWM::enableChannel ( TimerUtils::Channel channel,
Polarity polarity = Polarity::NORMAL )

Definition at line 56 of file PWM.cpp.

◆ getDutyCycle()

float Boardcore::PWM::getDutyCycle ( TimerUtils::Channel channel)

Return the channel's duty cycle in the range [0,1].

Definition at line 89 of file PWM.cpp.

◆ getTimer()

GP16bitTimer & Boardcore::PWM::getTimer ( )

Returns the timer used to generate the pwm signal.

Definition at line 95 of file PWM.cpp.

◆ isChannelEnabled()

bool Boardcore::PWM::isChannelEnabled ( TimerUtils::Channel channel)

Definition at line 73 of file PWM.cpp.

◆ setDutyCycle()

void Boardcore::PWM::setDutyCycle ( TimerUtils::Channel channel,
float dutyCycle )

Sets the duty cycle for the specified channel.

Changes the duty cycle only if the specified value is in the range [0,1].

Parameters
channelChannel to change the duty cycle.
dutyCycleRelative duty cycle, ranges from 0 to 1.

Definition at line 78 of file PWM.cpp.

◆ setDutyCycleResolution()

void Boardcore::PWM::setDutyCycleResolution ( uint16_t dutyCycleResolution)

Definition at line 50 of file PWM.cpp.

◆ setFrequency()

void Boardcore::PWM::setFrequency ( uint16_t pulseFrequency)

Definition at line 44 of file PWM.cpp.


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