![]() |
Serial Wombat Arduino Library
|
A class representing a Serial Wombat PWM output. More...
#include <SerialWombatPWM.h>
Public Member Functions | |
SerialWombatPWM (SerialWombat &serialWombat) | |
Constructor for SerialWombatPWM class. More... | |
void | begin (uint8_t pin) |
Initialize a pin that has been declared as PWM. Starts with 0 duty cycle. More... | |
void | begin (uint8_t pin, uint16_t dutyCycle) |
Initialize a pin that has been declared as PWM. More... | |
void | begin (uint8_t pin, uint16_t dutyCycle, bool invert) |
Initialize a pin that has been declared as PWM. More... | |
void | writeDutyCycle (uint16_t dutyCycle) |
Set PWM duty cycle. More... | |
void | setFrequency_SW4AB (Wombat4A_B_PWMFrequencyValues_t frequency) |
Set PWM Frequency (Adjusts all PWM outputs' frequency on a SerialWombat) More... | |
~SerialWombatPWM () | |
A class representing a Serial Wombat PWM output.
An instance of this class should be declared for each pin to be used as a Serial Wombat PWM.
PWMs are initialized to a frequency of 31250 Hz at startup. This frequency can be changed using the setFrequency_SW4AB method. All PWM outputs use the same clock divider, so a change in frequency to one PWM output will affect other outputs.
PWM inputs are either 8 or 10 bit resolution, depending on frequency selection. The duty cycle parameter of methods that set duty cycle take a 16 bit value ranging from 0 to 65535 as an input regardless of resolution, with 0 being always low, and 65535 being always high.
SerialWombatPWM::SerialWombatPWM | ( | SerialWombat & | serialWombat | ) |
Constructor for SerialWombatPWM class.
serialWombat | SerialWombat on which the PWM will run |
SerialWombatPWM::~SerialWombatPWM | ( | ) |
void SerialWombatPWM::begin | ( | uint8_t | pin | ) |
Initialize a pin that has been declared as PWM. Starts with 0 duty cycle.
pin | The pin to become a PWM. Valid values for SW4A: 0-3 SW4B: 1-3 |
void SerialWombatPWM::begin | ( | uint8_t | pin, |
uint16_t | dutyCycle | ||
) |
Initialize a pin that has been declared as PWM.
pin | The pin to become a PWM. Valid values for SW4A: 0-3 SW4B: 1-3 |
dutyCycle | A value from 0 to 65535 representing duty cycle |
void SerialWombatPWM::begin | ( | uint8_t | pin, |
uint16_t | dutyCycle, | ||
bool | invert | ||
) |
Initialize a pin that has been declared as PWM.
pin | The pin to become a PWM. Valid values for SW4A: 0-3 SW4B: 1-3 |
dutyCycle | A value from 0 to 65535 representing duty cycle |
invert | if true, internally adjust duty cycle to 65535-duty cycle |
void SerialWombatPWM::setFrequency_SW4AB | ( | Wombat4A_B_PWMFrequencyValues_t | frequency | ) |
Set PWM Frequency (Adjusts all PWM outputs' frequency on a SerialWombat)
frequency | A value of the Wombat4A_B_PWMFrequencyValues_t enumeration |
This function changes the Serial Wombat 4A and 4B PWM output frequncy by adjusting the clock divisor for the PWM generation hardware. By default the value is 31250Hz. Changing the frequency may reduce PWM resolution from 10 bits to 8 bits for some frequencies. However, the input value for duty cycle for methods of this class continue to be 0 to 65535 and are scaled accordingly.
void SerialWombatPWM::writeDutyCycle | ( | uint16_t | dutyCycle | ) |
Set PWM duty cycle.
dutyCycle | A value from 0 to 65535 representing duty cycle |