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>

Inheritance diagram for SerialWombatPWM:
SerialWombatPin SerialWombatPWM_18AB SerialWombatPWM_4AB

Public Member Functions

 SerialWombatPWM (SerialWombatChip &serialWombat)
 Constructor for SerialWombatPWM class. More...
 
int16_t begin (uint8_t pin, uint16_t dutyCycle=0, bool invert=false)
 Initialize a pin that has been declared as PWM. More...
 
void writeDutyCycle (uint16_t dutyCycle)
 
- Public Member Functions inherited from SerialWombatPin
 SerialWombatPin (SerialWombatChip &serialWombatChip)
 Instantiates a Serial Wombat Pin. More...
 
 SerialWombatPin (SerialWombatChip &serialWombatChip, uint8_t pin)
 Instantiates a Serial Wombat Pin. More...
 
uint16_t readPublicData ()
 Read the 16 Bit public data associated with this pin. More...
 
void pinMode (uint8_t mode, bool pullDown=false, bool openDrain=false)
 Set pin to INPUT or OUTPUT, with options for pull Ups and open Drain settings. More...
 
void digitalWrite (uint8_t val)
 Set output pin High or Low. More...
 
int digitalRead ()
 Reads the state of the Pin. More...
 
uint16_t writePublicData (uint16_t value)
 Write a 16 bit value to this pin. More...
 
uint8_t pin ()
 Returns the current SW pin number. Used primarily for virtual calls by derived classes. More...
 
uint8_t swPinModeNumber ()
 Returns the Mode number. Used primarily by derived classes to populate packet data. More...
 
int16_t initPacketNoResponse (uint8_t packetNumber, uint8_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55, uint8_t param4=0x55)
 
int16_t initPacketNoResponse (uint8_t packetNumber, uint16_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55)
 
int16_t initPacketNoResponse (uint8_t packetNumber, uint16_t param0, uint16_t param1, uint8_t param2=0x55)
 
int16_t disable ()
 Disables the pin mode (if applicable) More...
 

Additional Inherited Members

- Protected Attributes inherited from SerialWombatPin
uint8_t _pin = 255
 
SerialWombatChip_sw
 
uint8_t _pinMode = 0
 

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.

SW4A / SW4B 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.

SW4A/4B 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.

Serial Wombat 18AB PWM outputs are driven either by hardware peripherals or by a DMA based software PWM scheme. Up to 6 hardware PWM outputs are avaialble on Enhanced Digital Performance pins (0-4,7,9-19). The first six Enhanced Digitial Performance pins configured after reset will claim hardware resources. Any additional pins configured for PWM will use DMA based output. Hardware capable pins can generate high resolution signals up to about 100kHz. DMA based output is limited to transitions every 17uS, so a 1kHz output will have about 6 bits of resolution and a 100 Hz output will have about 9 bit resolution.

Constructor & Destructor Documentation

◆ SerialWombatPWM()

SerialWombatPWM::SerialWombatPWM ( SerialWombatChip serialWombat)
inline

Constructor for SerialWombatPWM class.

Parameters
serialWombatSerialWombat chip on which the PWM will run

Member Function Documentation

◆ begin()

int16_t SerialWombatPWM::begin ( uint8_t  pin,
uint16_t  dutyCycle = 0,
bool  invert = false 
)
inline

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

◆ writeDutyCycle()

void SerialWombatPWM::writeDutyCycle ( uint16_t  dutyCycle)
inline