Serial Wombat Arduino Library
Public Member Functions | List of all members
SerialWombatPWM Class Reference

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 ()
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ SerialWombatPWM()

SerialWombatPWM::SerialWombatPWM ( SerialWombat serialWombat)

Constructor for SerialWombatPWM class.

Parameters
serialWombatSerialWombat on which the PWM will run

◆ ~SerialWombatPWM()

SerialWombatPWM::~SerialWombatPWM ( )

Member Function Documentation

◆ begin() [1/3]

void SerialWombatPWM::begin ( uint8_t  pin)

Initialize a pin that has been declared as PWM. Starts with 0 duty cycle.

Parameters
pinThe pin to become a PWM. Valid values for SW4A: 0-3 SW4B: 1-3

◆ begin() [2/3]

void SerialWombatPWM::begin ( uint8_t  pin,
uint16_t  dutyCycle 
)

Initialize a pin that has been declared as PWM.

Parameters
pinThe pin to become a PWM. Valid values for SW4A: 0-3 SW4B: 1-3
dutyCycleA value from 0 to 65535 representing duty cycle

◆ begin() [3/3]

void SerialWombatPWM::begin ( uint8_t  pin,
uint16_t  dutyCycle,
bool  invert 
)

Initialize a pin that has been declared as PWM.

Parameters
pinThe pin to become a PWM. Valid values for SW4A: 0-3 SW4B: 1-3
dutyCycleA value from 0 to 65535 representing duty cycle
invertif true, internally adjust duty cycle to 65535-duty cycle

◆ setFrequency_SW4AB()

void SerialWombatPWM::setFrequency_SW4AB ( Wombat4A_B_PWMFrequencyValues_t  frequency)

Set PWM Frequency (Adjusts all PWM outputs' frequency on a SerialWombat)

Parameters
frequencyA 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.

Warning
This function will likely not be compatible with other models in the Serial Wombat family based on other hardware that are released in the future because it is tightly coupled to the PIC16F15214 hardware.

◆ writeDutyCycle()

void SerialWombatPWM::writeDutyCycle ( uint16_t  dutyCycle)

Set PWM duty cycle.

Parameters
dutyCycleA value from 0 to 65535 representing duty cycle