Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
HardwarePWM Class Reference

Hardware pulse width modulation. More...

#include <HardwarePWM.h>

Public Member Functions

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

Detailed Description

Hardware pulse width modulation.

Constructor & Destructor Documentation

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

Instantiate hardware PWM object.

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

Member Function Documentation

bool HardwarePWM::analogWrite ( uint8  pin,
uint32  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
uint8 HardwarePWM::getChannel ( uint8  pin)

Get channel number for a pin.

Parameters
pinGPIO to interrogate
Return values
uint8Channel of GPIO
uint32 HardwarePWM::getDuty ( uint8  pin)
inline

Get PWM duty cycle.

Parameters
pinGPIO to get duty cycle for
Return values
uint32Value of PWM duty cycle
uint32 HardwarePWM::getDutyChan ( uint8  chan)

Get PWM duty cycle.

Parameters
chanChannel to get duty cycle for
Return values
uint32Value of PWM duty cycle
uint32 HardwarePWM::getMaxDuty ( )
inline

Get the maximum duty cycle value.

Return values
uint32Maximum permissible duty cycle
Note
Attempt to set duty of a pin above this value will fail
uint32 HardwarePWM::getPeriod ( void  )

Get PWM period.

Return values
uint32Value of PWM period
bool HardwarePWM::setDuty ( uint8  pin,
uint32  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.
bool HardwarePWM::setDutyChan ( uint8  chan,
uint32  duty,
bool  update = true 
)

Set PWM duty cycle for a channel.

Parameters
channelChannel to set
dutyValue of duty cycle to set channel to
updateUpdate PWM output
Return values
boolTrue on success
void HardwarePWM::setPeriod ( uint32  period)

Set PWM period.

Parameters
periodPWM period
Note
All PWM pins share the same period
void HardwarePWM::update ( )

This function is used to actually update the PWM.