Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

otPWM Class Reference
[PWM - Class for PWM managementPWM - Class for PWM management]

Class that stores state and functions for interacting with PCA9685 PWM chip.

#include <otPWM.h>

Inheritance diagram for otPWM:

otScorpio

Public Types

enum  Constants {
  SERVOMIN = 150, SERVOMAX = 600, USMIN = 600, USMAX = 2400,
  SERVO_FREQ = 50
}

Public Member Functions

 otPWM ()
bool init (U8 addr=0x40, U8 prescale=0)
bool reset ()
void sleep ()
void wakeup ()
void setExtClk (U8 prescale)
void setPWMFreq (float freq)
void setOutputMode (bool totempole)
U8 getPWM (U8 num)
void setPWM (U8 num, U16 on, U16 off)
void setPin (U8 num, U16 val, bool invert=false)
U8 readPrescale (void)
void writeMicroseconds (U8 num, U16 Microseconds)
void setTimebase (U32 freq)
U32 getTimebase ()

Member Enumeration Documentation

enum otPWM::Constants
 

Enumeration values:
SERVOMIN  This is the 'minimum' pulse length count (out of 4096).
SERVOMAX  This is the 'maximum' pulse length count (out of 4096).
USMIN  This is the rounded 'minimum' microsecond length based on the minimum pulse of 150.
USMAX  This is the rounded 'maximum' microsecond length based on the maximum pulse of 600.
SERVO_FREQ  Analog servos run at ~50 Hz updates.


Constructor & Destructor Documentation

otPWM.otPWM  ) 
 

Create the class


Member Function Documentation

U8 otPWM.getPWM U8  num  ) 
 

Gets the PWM output of one of the PCA9685 pins

Parameters:
num One of the PWM output pins, from 0 to 15
Returns:
Requested PWM output value

U32 otPWM.getTimebase  ) 
 

Getter for the internally tracked oscillator used for freq calculations.

Returns:
The PCA9685 frequency

bool otPWM.init U8  addr = 0x40,
U8  prescale = 0
 

Init PWM. Call this method as first!

Parameters:
addr I2C address, accepted range is 0x40 to 0x7F
prescale Sets External Clock
Returns:
True on success

Reimplemented in otScorpio.

U8 otPWM.readPrescale void   ) 
 

Reads set Prescale from PCA9685

Returns:
prescale value

bool otPWM.reset  ) 
 

Sends a reset command to the PCA9685 chip over I2C

void otPWM.setExtClk U8  prescale  ) 
 

Sets EXTCLK pin to use the external clock

Parameters:
prescale Sets External Clock

void otPWM.setOutputMode bool  totempole  ) 
 

Sets the output mode of the PCA9685 to either open drain or push pull / totempole. Warning: LEDs with integrated zener diodes should only be driven in open drain mode.

Parameters:
totempole Totempole if true, open drain if false.

void otPWM.setPin U8  num,
U16  val,
bool  invert = false
 

Helper to set pin PWM output. Sets pin without having to deal with on/off tick placement and properly handles a zero value as completely off and 4095 as completely on. Optional invert parameter supports inverting the pulse for sinking to ground.

Parameters:
num One of the PWM output pins, from 0 to 15
val The number of ticks out of 4096 to be active, should be a value from 0 to 4095 inclusive.
invert If true, inverts the output, defaults to 'false'

void otPWM.setPWM U8  num,
U16  on,
U16  off
 

Sets the PWM output of one of the PCA9685 pins

Parameters:
num One of the PWM output pins, from 0 to 15
on At what point in the 4096-part cycle to turn the PWM output ON
off At what point in the 4096-part cycle to turn the PWM output OFF

void otPWM.setPWMFreq float  freq  ) 
 

Sets the PWM frequency for the entire chip, up to ~1.6 KHz

Parameters:
freq Floating point frequency that we will attempt to match

void otPWM.setTimebase U32  freq  ) 
 

Setter for the internally tracked oscillator used for freq calculations

Parameters:
freq The frequency the PCA9685 should use for frequency calculations

void otPWM.sleep  ) 
 

Puts PWM into sleep mode

void otPWM.wakeup  ) 
 

Wakes PWM from sleep

void otPWM.writeMicroseconds U8  num,
U16  Microseconds
 

Sets the PWM output of one of the PCA9685 pins based on the input microseconds, output is not precise

Parameters:
num One of the PWM output pins, from 0 to 15
Microseconds The number of Microseconds to turn the PWM output ON


The documentation for this class was generated from the following file: footer
otStudio - Library Reference - (C) 2020-23 Officina Turini, All Rights Reserved
Document built with Doxygen 1.4.0