Jump to content

Component: PWM 16CH 12Bit (PCA9685) (General Output): Difference between revisions

From Flowcode Help
No edit summary
m Text replacement - "style="background-color:#EAE1EA;"" to "class="mtx-class-propfolder""
 
(5 intermediate revisions by the same user not shown)
Line 92: Line 92:


===GetClockFrequency===
===GetClockFrequency===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetClockFrequency'''
| width="90%" class="mtx-class-macrohead" | '''GetClockFrequency'''
|-
|-
| colspan="2" | Returns the current clock frequency 
| colspan="2" | Returns the current clock frequency 
Line 106: Line 106:


===Initialise===
===Initialise===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise'''
| width="90%" class="mtx-class-macrohead" | '''Initialise'''
|-
|-
| colspan="2" | Sets up the I2C ready for communications to begin 
| colspan="2" | Sets up the I2C ready for communications to begin 
Line 120: Line 120:


===Reset===
===Reset===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Reset'''
| width="90%" class="mtx-class-macrohead" | '''Reset'''
|-
|-
| colspan="2" | Sends a reset command to the PCA9685 chip over I2C 
| colspan="2" | Sends a reset command to the PCA9685 chip over I2C 
Line 134: Line 134:


===SetAddress===
===SetAddress===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetAddress'''
| width="90%" class="mtx-class-macrohead" | '''SetAddress'''
|-
|-
| colspan="2" | Allows a different I2C address to be specified allowing one component to control multiple PCA9685 modules. 
| colspan="2" | Allows a different I2C address to be specified allowing one component to control multiple PCA9685 modules. 
Line 153: Line 153:


===SetClockFrequency===
===SetClockFrequency===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetClockFrequency'''
| width="90%" class="mtx-class-macrohead" | '''SetClockFrequency'''
|-
|-
| colspan="2" | Sets the current clock frequency, used for things like calculating the PWM frequency and Microsecond duty. 
| colspan="2" | Sets the current clock frequency, used for things like calculating the PWM frequency and Microsecond duty. 
Line 172: Line 172:


===SetExternalClock===
===SetExternalClock===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetExternalClock'''
| width="90%" class="mtx-class-macrohead" | '''SetExternalClock'''
|-
|-
| colspan="2" | Sets EXTCLK pin to use the external clock 
| colspan="2" | Sets EXTCLK pin to use the external clock 
Line 191: Line 191:


===SetOutputMode===
===SetOutputMode===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetOutputMode'''
| width="90%" class="mtx-class-macrohead" | '''SetOutputMode'''
|-
|-
| colspan="2" | Sets the output mode of the PCA9685 to either open drain or push pull. Warning: LEDs with integrated zener diodes should only be driven in open drain mode. 
| colspan="2" | Sets the output mode of the PCA9685 to either open drain or push pull. Warning: LEDs with integrated zener diodes should only be driven in open drain mode. 
Line 210: Line 210:


===SetPWM===
===SetPWM===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetPWM'''
| width="90%" class="mtx-class-macrohead" | '''SetPWM'''
|-
|-
| colspan="2" | Sets the PWM output of one of the PCA9685 pins 
| colspan="2" | Sets the PWM output of one of the PCA9685 pins 
Line 239: Line 239:


===SetPWMFrequency===
===SetPWMFrequency===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetPWMFrequency'''
| width="90%" class="mtx-class-macrohead" | '''SetPWMFrequency'''
|-
|-
| colspan="2" | Sets the PWM frequency for the entire chip, up to approx 1.6 KHz 
| colspan="2" | Sets the PWM frequency for the entire chip, up to approx 1.6 KHz 
Line 258: Line 258:


===SetPin===
===SetPin===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetPin'''
| width="90%" class="mtx-class-macrohead" | '''SetPin'''
|-
|-
| colspan="2" | 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. 
| colspan="2" | 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. 
Line 287: Line 287:


===Sleep===
===Sleep===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Sleep'''
| width="90%" class="mtx-class-macrohead" | '''Sleep'''
|-
|-
| colspan="2" | Puts the module into Sleep mode 
| colspan="2" | Puts the module into Sleep mode 
Line 301: Line 301:


===WakeUp===
===WakeUp===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''WakeUp'''
| width="90%" class="mtx-class-macrohead" | '''WakeUp'''
|-
|-
| colspan="2" | Wakes the module from Sleep mode 
| colspan="2" | Wakes the module from Sleep mode 
Line 315: Line 315:


===WriteMicroseconds===
===WriteMicroseconds===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''WriteMicroseconds'''
| width="90%" class="mtx-class-macrohead" | '''WriteMicroseconds'''
|-
|-
| colspan="2" | Sets the PWM output of one of the PCA9685 pins based on the input microseconds, output is not precise 
| colspan="2" | Sets the PWM output of one of the PCA9685 pins based on the input microseconds, output is not precise 
Line 340: Line 340:
==Property reference==
==Property reference==


{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-prop-icon.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties'''  
| width="90%" class="mtx-class-macrohead" | '''Properties'''  
|-
|-
|-
|-
Line 386: Line 386:
| colspan="2" | Number of microseconds the PWM output can resolve to 
| colspan="2" | Number of microseconds the PWM output can resolve to 
|-
|-
| width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
| width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]]
| width="90%" style="background-color:#EAE1EA; color:#4B008D;" | I2C Communications
| width="90%" class="mtx-class-propfolder" | I2C Communications
|-
|-
|-
|-
Line 420: Line 420:
| colspan="2" | On older microcontroller devices there is a potential for the I2C hardware channel to lock up if there is not  a 10ms delay between an I2C stop event and the next I2C start event.  Most modern microcontrollers will not have a problem so this property can be disabled to speed up the  I2C communications.  
| colspan="2" | On older microcontroller devices there is a potential for the I2C hardware channel to lock up if there is not  a 10ms delay between an I2C stop event and the next I2C start event.  Most modern microcontrollers will not have a problem so this property can be disabled to speed up the  I2C communications.  
|-
|-
| width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
| width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]]
| width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Simulation
| width="90%" class="mtx-class-propfolder" | Simulation
|-
|-
|-
|-

Latest revision as of 14:36, 13 July 2026

Author Matrix TSL
Version 1.0
Category General Output


PWM 16CH 12Bit (PCA9685) component

The PCA9685 is an I²C-bus controlled 16-channel LED controller optimized for Red/Green/Blue/Amber (RGBA) color backlighting or Servo motor applications. Each output has its own 12-bit resolution (4096 steps) fixed frequency individual PWM controller that operates at a programmable frequency from a typical of 24 Hz to 1526 Hz. All outputs are set to the same PWM frequency. Up to 64 devices can be chained together on a single I²C-bus to provide up to 1024 individual PWM outputs.

Component Source Code

Please click here to download the component source project: FC_Comp_Source_PCA9685_16_Channel_PWM.fcfx

Please click here to view the component source code (Beta): FC_Comp_Source_PCA9685_16_Channel_PWM.fcfx

Detailed description

No detailed description exists yet for this component

Examples

No additional examples







Macro reference

GetClockFrequency

GetClockFrequency
Returns the current clock frequency 
- ULONG Return


Initialise

Initialise
Sets up the I2C ready for communications to begin 
- VOID Return


Reset

Reset
Sends a reset command to the PCA9685 chip over I2C 
- VOID Return


SetAddress

SetAddress
Allows a different I2C address to be specified allowing one component to control multiple PCA9685 modules. 
- BYTE Address
Range: 0x40 - 0x7F 
- VOID Return


SetClockFrequency

SetClockFrequency
Sets the current clock frequency, used for things like calculating the PWM frequency and Microsecond duty. 
- ULONG Clock
 
- VOID Return


SetExternalClock

SetExternalClock
Sets EXTCLK pin to use the external clock 
- BYTE Prescale
External Clock Prescaler - Range: 3-255 
- VOID Return


SetOutputMode

SetOutputMode
Sets the output mode of the PCA9685 to either open drain or push pull. Warning: LEDs with integrated zener diodes should only be driven in open drain mode. 
- BOOL Mode
0=OpenDrain, 1=Push/Pull 
- VOID Return


SetPWM

SetPWM
Sets the PWM output of one of the PCA9685 pins 
- BYTE Output
One of the PWM output pins - Range: 0 to 15 
- UINT On
At what point in the 4096-part cycle to turn the PWM output ON 
- UINT Off
At what point in the 4096-part cycle to turn the PWM output OFF 
- VOID Return


SetPWMFrequency

SetPWMFrequency
Sets the PWM frequency for the entire chip, up to approx 1.6 KHz 
- FLOAT Frequency
Floating point frequency that we will attempt to match 
- VOID Return


SetPin

SetPin
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. 
- BYTE Output
One of the PWM output pins - Range: 0 to 15 
- UINT Duty
The number of ticks out of 4096 to be active 
- BOOL Invert
0=Normal, 1=Inverted 
- VOID Return


Sleep

Sleep
Puts the module into Sleep mode 
- VOID Return


WakeUp

WakeUp
Wakes the module from Sleep mode 
- VOID Return


WriteMicroseconds

WriteMicroseconds
Sets the PWM output of one of the PCA9685 pins based on the input microseconds, output is not precise 
- BYTE Output
One of the PWM output pins - Range: 0 to 15 
- UINT Microseconds
The number of Microseconds to turn the PWM output ON 
- VOID Return


Property reference

Properties
Address
Module I2C Address. This setting can be overridden using the SetAddress component macro. 
Output Mode
Sets the output mode of the PCA9685 to either open drain or push pull. Warning: LEDs with integrated zener diodes should only be driven in open drain mode. Can be overridden using the SetOutputMode component macro. 
Clock Type
Configures the input clock source to the module. 
Clock Frequency
Frequency of the module. Internal oscillator defaults to 250000000 or 25MHz but can actually be anywhere from 23 to 27MHz. External clock frequency can be specified here up to a max value of 50000000 or 50MHz. This setting can be overridden using the SetClockFrequency component macro. 
Prescaler
External Clock Prescaler Range: 3 to 255 
Target PWM Frequency
The ideal PWM frequency we would like to generate on the output pins. Servo motors require an output frequency around 50Hz. LEDs require a mugh higher output frequency to avoid visible flicker. 
Actual PWM Frequency
The calculated actual PWM frequency available using the Clock Frequency and Prescaler 
PWM Resolution
Number of microseconds the PWM output can resolve to 
I2C Communications
Channel
Channel selection 
Baud Select
Baud rate option selector 
Baud Rate
Baud rate to be used 
SDA
Pin used for SDA (data signal) 
SCL
Pin used for SCL (clock signal) 
Stop Delay
On older microcontroller devices there is a potential for the I2C hardware channel to lock up if there is not a 10ms delay between an I2C stop event and the next I2C start event. Most modern microcontrollers will not have a problem so this property can be disabled to speed up the I2C communications.  
Simulation
Simulate Comms