Hardware pulse width modulation. More...

#include <HardwarePWM.h>

Public Member Functions

 HardwarePWM (uint8_t *pins, uint8_t no_of_pins)
 Instantiate hardware PWM object. More...
 
virtual ~HardwarePWM ()
 
bool analogWrite (uint8_t pin, uint32_t duty)
 Set PWM duty cycle. More...
 
bool setDutyChan (uint8_t chan, uint32_t duty, bool update=true)
 Set PWM duty cycle for a channel. More...
 
bool setDuty (uint8_t pin, uint32_t duty, bool update=true)
 Set PWM duty cycle. More...
 
uint32_t getDutyChan (uint8_t chan)
 Get PWM duty cycle. More...
 
uint32_t getDuty (uint8_t pin)
 Get PWM duty cycle. More...
 
void setPeriod (uint32_t period)
 Set PWM period. More...
 
uint32_t getPeriod ()
 Get PWM period. More...
 
uint8_t getChannel (uint8_t pin)
 Get channel number for a pin. More...
 
uint32_t getMaxDuty ()
 Get the maximum duty cycle value. More...
 
void update ()
 This function is used to actually update the PWM. More...
 
uint32_t getFrequency (uint8_t pin)
 Get PWM Frequency. More...
 

Detailed Description

Hardware pulse width modulation.

Constructor & Destructor Documentation

◆ HardwarePWM()

HardwarePWM::HardwarePWM ( uint8_t *  pins,
uint8_t  no_of_pins 
)

Instantiate hardware PWM object.

Parameters
pinsPointer to array of pins to control
no_of_pinsQuantity of elements in array of pins

◆ ~HardwarePWM()

virtual HardwarePWM::~HardwarePWM ( )
virtual

Member Function Documentation

◆ analogWrite()

bool HardwarePWM::analogWrite ( uint8_t  pin,
uint32_t  duty 
)
inline

Set PWM duty cycle.

Parameters
pinGPIO to set
dutyValue of duty cycle to set pin to
Return values
boolTrue on success
Note
Default frequency is 1khz but can be varied by various function

◆ getChannel()

uint8_t HardwarePWM::getChannel ( uint8_t  pin)

Get channel number for a pin.

Parameters
pinGPIO to interrogate
Return values
uint8_tChannel of GPIO

◆ getDuty()

uint32_t HardwarePWM::getDuty ( uint8_t  pin)
inline

Get PWM duty cycle.

Parameters
pinGPIO to get duty cycle for
Return values
uint32_tValue of PWM duty cycle

◆ getDutyChan()

uint32_t HardwarePWM::getDutyChan ( uint8_t  chan)

Get PWM duty cycle.

Parameters
chanChannel to get duty cycle for
Return values
uint32_tValue of PWM duty cycle

◆ getFrequency()

uint32_t HardwarePWM::getFrequency ( uint8_t  pin)

Get PWM Frequency.

Parameters
pinGPIO to get frequency for
Return values
uint32_tValue of Frequency

◆ getMaxDuty()

uint32_t HardwarePWM::getMaxDuty ( )
inline

Get the maximum duty cycle value.

Return values
uint32_tMaximum permissible duty cycle
Note
Attempt to set duty of a pin above this value will fail

◆ getPeriod()

uint32_t HardwarePWM::getPeriod ( )

Get PWM period.

Return values
uint32_tValue of PWM period

◆ setDuty()

bool HardwarePWM::setDuty ( uint8_t  pin,
uint32_t  duty,
bool  update = true 
)
inline

Set PWM duty cycle.

Parameters
pinGPIO to set
dutyValue of duty cycle to set pin to
updateUpdate PWM output
Return values
boolTrue on success
Note
This function is used to set the pwm duty cycle for a given pin. If parameter 'update' is false then you have to call update() later to update duties.

◆ setDutyChan()

bool HardwarePWM::setDutyChan ( uint8_t  chan,
uint32_t  duty,
bool  update = true 
)

Set PWM duty cycle for a channel.

Parameters
chanChannel to set
dutyValue of duty cycle to set channel to
updateUpdate PWM output
Return values
boolTrue on success

◆ setPeriod()

void HardwarePWM::setPeriod ( uint32_t  period)

Set PWM period.

Parameters
periodPWM period
Note
All PWM pins share the same period

◆ update()

void HardwarePWM::update ( )

This function is used to actually update the PWM.


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