Component: PWM 16CH 12Bit (PCA9685) (General Output): Difference between revisions
XML import |
m Text replacement - "style="background-color:#EAE1EA;"" to "class="mtx-class-propfolder"" |
||
| (22 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
{| style="width:50%" | |||
{| | |||
|- | |- | ||
| width="20%" style="color: gray;" | Author | | width="20%" style="color:gray;" | Author | ||
| Matrix TSL | | Matrix TSL | ||
|- | |- | ||
| width="20%" style="color: gray;" | Version | | width="20%" style="color:gray;" | Version | ||
| 1.0 | | 1.0 | ||
|- | |- | ||
| width="20%" style="color: gray;" | Category | | width="20%" style="color:gray;" | Category | ||
| General Output | | 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: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_PCA9685_16_Channel_PWM.fcfx FC_Comp_Source_PCA9685_16_Channel_PWM.fcfx] | |||
Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_PCA9685_16_Channel_PWM.fcfx FC_Comp_Source_PCA9685_16_Channel_PWM.fcfx] | |||
== | ==Detailed description== | ||
''No detailed description exists yet for this component'' | |||
==Examples== | |||
''<span style="color:red;">No additional examples</span>'' | |||
==Macro reference== | |||
:'' | ===GetClockFrequency=== | ||
{| class="mtx-class-macrotable wikitable" | |||
|- | |||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | |||
| width="90%" class="mtx-class-macrohead" | '''GetClockFrequency''' | |||
|- | |||
| colspan="2" | Returns the current clock frequency | |||
|- | |||
|- | |||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u32-icon.png]] - ULONG | |||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | |||
|} | |||
=== | ===Initialise=== | ||
{| class="mtx-class-macrotable wikitable" | |||
|- | |||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | |||
| width="90%" class="mtx-class-macrohead" | '''Initialise''' | |||
|- | |||
| colspan="2" | Sets up the I2C ready for communications to begin | |||
|- | |||
|- | |||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | |||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | |||
|} | |||
===Reset=== | |||
:: | {| class="mtx-class-macrotable wikitable" | ||
|- | |||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | |||
| width="90%" class="mtx-class-macrohead" | '''Reset''' | |||
|- | |||
| colspan="2" | Sends a reset command to the PCA9685 chip over I2C | |||
|- | |||
|- | |||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | |||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | |||
|} | |||
===SetAddress=== | |||
:: | {| class="mtx-class-macrotable wikitable" | ||
|- | |||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | |||
| 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. | |||
|- | |||
|- | |||
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | |||
| width="90%" | Address | |||
|- | |||
| colspan="2" | Range: 0x40 - 0x7F | |||
|- | |||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | |||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | |||
|} | |||
'''Return | ===SetClockFrequency=== | ||
{| class="mtx-class-macrotable wikitable" | |||
|- | |||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | |||
| 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. | |||
|- | |||
|- | |||
| width="10%" align="center" | [[File:Fc9-u32-icon.png]] - ULONG | |||
| width="90%" | Clock | |||
|- | |||
| colspan="2" | | |||
|- | |||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | |||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | |||
|} | |||
===SetExternalClock=== | |||
{| class="mtx-class-macrotable wikitable" | |||
|- | |||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | |||
| width="90%" class="mtx-class-macrohead" | '''SetExternalClock''' | |||
|- | |||
| colspan="2" | Sets EXTCLK pin to use the external clock | |||
|- | |||
|- | |||
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | |||
| width="90%" | Prescale | |||
|- | |||
| colspan="2" | External Clock Prescaler - Range: 3-255 | |||
|- | |||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | |||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | |||
|} | |||
''' | ===SetOutputMode=== | ||
{| class="mtx-class-macrotable wikitable" | |||
|- | |||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | |||
| 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. | |||
|- | |||
|- | |||
| width="10%" align="center" | [[File:Fc9-bool-icon.png]] - BOOL | |||
| width="90%" | Mode | |||
|- | |||
| colspan="2" | 0=OpenDrain, 1=Push/Pull | |||
|- | |||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | |||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | |||
|} | |||
===SetPWM=== | |||
{| class="mtx-class-macrotable wikitable" | |||
|- | |||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | |||
| width="90%" class="mtx-class-macrohead" | '''SetPWM''' | |||
|- | |||
| colspan="2" | Sets the PWM output of one of the PCA9685 pins | |||
|- | |||
|- | |||
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | |||
| width="90%" | Output | |||
|- | |||
| colspan="2" | One of the PWM output pins - Range: 0 to 15 | |||
|- | |||
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | |||
| width="90%" | On | |||
|- | |||
| colspan="2" | At what point in the 4096-part cycle to turn the PWM output ON | |||
|- | |||
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | |||
| width="90%" | Off | |||
|- | |||
| colspan="2" | At what point in the 4096-part cycle to turn the PWM output OFF | |||
|- | |||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | |||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | |||
|} | |||
:'' | ===SetPWMFrequency=== | ||
{| class="mtx-class-macrotable wikitable" | |||
|- | |||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | |||
| width="90%" class="mtx-class-macrohead" | '''SetPWMFrequency''' | |||
|- | |||
| colspan="2" | Sets the PWM frequency for the entire chip, up to approx 1.6 KHz | |||
|- | |||
|- | |||
| width="10%" align="center" | [[File:Fc9-f32-icon.png]] - FLOAT | |||
| width="90%" | Frequency | |||
|- | |||
| colspan="2" | Floating point frequency that we will attempt to match | |||
|- | |||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | |||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | |||
|} | |||
=== | ===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. | {| class="mtx-class-macrotable wikitable" | ||
|- | |||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | |||
| 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. | |||
|- | |||
|- | |||
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | |||
| width="90%" | Output | |||
|- | |||
| colspan="2" | One of the PWM output pins - Range: 0 to 15 | |||
|- | |||
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | |||
| width="90%" | Duty | |||
|- | |||
| colspan="2" | The number of ticks out of 4096 to be active | |||
|- | |||
| width="10%" align="center" | [[File:Fc9-bool-icon.png]] - BOOL | |||
| width="90%" | Invert | |||
|- | |||
| colspan="2" | 0=Normal, 1=Inverted | |||
|- | |||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | |||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | |||
|} | |||
===Sleep=== | |||
:: | {| class="mtx-class-macrotable wikitable" | ||
|- | |||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | |||
| width="90%" class="mtx-class-macrohead" | '''Sleep''' | |||
|- | |||
| colspan="2" | Puts the module into Sleep mode | |||
|- | |||
|- | |||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | |||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | |||
|} | |||
===WakeUp=== | |||
:: | {| class="mtx-class-macrotable wikitable" | ||
|- | |||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | |||
| width="90%" class="mtx-class-macrohead" | '''WakeUp''' | |||
|- | |||
| colspan="2" | Wakes the module from Sleep mode | |||
|- | |||
|- | |||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | |||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | |||
|} | |||
===WriteMicroseconds=== | |||
{| class="mtx-class-macrotable wikitable" | |||
|- | |||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | |||
| 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 | |||
|- | |||
''' | |- | ||
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | |||
: | | width="90%" | Output | ||
|- | |||
| colspan="2" | One of the PWM output pins - Range: 0 to 15 | |||
|- | |||
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | |||
: | | width="90%" | Microseconds | ||
|- | |||
| colspan="2" | The number of Microseconds to turn the PWM output ON | |||
|- | |||
== | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | ||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | |||
'' | |} | ||
==Property reference== | ==Property reference== | ||
{| class="mtx-class-macrotable wikitable" | |||
|- | |||
Module I2C Address. | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-prop-icon.png]] | ||
| width="90%" class="mtx-class-macrohead" | '''Properties''' | |||
This setting can be overridden using the SetAddress component macro. | |- | ||
|- | |||
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | |||
| width="90%" | Address | |||
|- | |||
| colspan="2" | Module I2C Address. This setting can be overridden using the SetAddress component macro. | |||
Sets the output mode of the PCA9685 to either open drain or push pull. | |- | ||
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | |||
Warning: LEDs with integrated zener diodes should only be driven in open drain mode. | | width="90%" | Output Mode | ||
|- | |||
Can be overridden using the SetOutputMode component macro. | | 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. Can be overridden using the SetOutputMode component macro. | ||
|- | |||
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | |||
| width="90%" | Clock Type | |||
|- | |||
| colspan="2" | Configures the input clock source to the module. | |||
Configures the input clock source to the module. | |- | ||
| width="10%" align="center" | [[File:Fc9-type-21-icon.png]] | |||
| width="90%" | Clock Frequency | |||
|- | |||
| colspan="2" | 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. | |||
|- | |||
Frequency of the module. | | width="10%" align="center" | [[File:Fc9-type-21-icon.png]] | ||
| width="90%" | Prescaler | |||
Internal oscillator defaults to 250000000 or 25MHz but can actually be anywhere from 23 to 27MHz. | |- | ||
| colspan="2" | External Clock Prescaler Range: 3 to 255 | |||
External clock frequency can be specified here up to a max value of 50000000 or 50MHz. | |- | ||
| width="10%" align="center" | [[File:Fc9-type-15-icon.png]] | |||
This setting can be overridden using the SetClockFrequency component macro. | | width="90%" | Target PWM Frequency | ||
|- | |||
| colspan="2" | 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. | |||
|- | |||
| width="10%" align="center" | [[File:Fc9-type-15-icon.png]] | |||
| width="90%" | Actual PWM Frequency | |||
External Clock Prescaler | |- | ||
| colspan="2" | The calculated actual PWM frequency available using the Clock Frequency and Prescaler | |||
Range: 3 to 255 | |- | ||
| width="10%" align="center" | [[File:Fc9-type-15-icon.png]] | |||
| width="90%" | PWM Resolution | |||
|- | |||
| colspan="2" | Number of microseconds the PWM output can resolve to | |||
|- | |||
The ideal PWM frequency we would like to generate on the output pins. | | width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]] | ||
| width="90%" class="mtx-class-propfolder" | I2C Communications | |||
Servo motors require an output frequency around 50Hz. | |- | ||
|- | |||
LEDs require a mugh higher output frequency to avoid visible flicker. | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | ||
| width="90%" | Channel | |||
|- | |||
| colspan="2" | Channel selection | |||
|- | |||
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | |||
The calculated actual PWM frequency available using the Clock Frequency and Prescaler | | width="90%" | Baud Select | ||
|- | |||
| colspan="2" | Baud rate option selector | |||
|- | |||
| width="10%" align="center" | [[File:Fc9-type-14-icon.png]] | |||
| width="90%" | Baud Rate | |||
Number of microseconds the PWM output can resolve to | |- | ||
| colspan="2" | Baud rate to be used | |||
|- | |||
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]] | |||
| width="90%" | SDA | |||
|- | |||
Channel selection | | colspan="2" | Pin used for SDA (data signal) | ||
|- | |||
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]] | |||
| width="90%" | SCL | |||
|- | |||
| colspan="2" | Pin used for SCL (clock signal) | |||
Baud rate option selector | |- | ||
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]] | |||
| width="90%" | Stop Delay | |||
|- | |||
| 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. | |||
|- | |||
Baud rate to be used | | width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]] | ||
| width="90%" class="mtx-class-propfolder" | Simulation | |||
|- | |||
|- | |||
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]] | |||
| width="90%" | Simulate Comms | |||
Pin used for SDA (data signal) | |- | ||
| colspan="2" | | |||
|} | |||
Pin used for SCL (clock signal) | |||
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. | |||
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 | |
| Return | |
Initialise
| Initialise | |
| Sets up the I2C ready for communications to begin | |
| Return | |
Reset
| Reset | |
| Sends a reset command to the PCA9685 chip over I2C | |
| Return | |
SetAddress
| SetAddress | |
| Allows a different I2C address to be specified allowing one component to control multiple PCA9685 modules. | |
| Address | |
| Range: 0x40 - 0x7F | |
| Return | |
SetClockFrequency
| SetClockFrequency | |
| Sets the current clock frequency, used for things like calculating the PWM frequency and Microsecond duty. | |
| Clock | |
| Return | |
SetExternalClock
| SetExternalClock | |
| Sets EXTCLK pin to use the external clock | |
| Prescale | |
| External Clock Prescaler - Range: 3-255 | |
| Return | |
SetOutputMode
SetPWM
SetPWMFrequency
| SetPWMFrequency | |
| Sets the PWM frequency for the entire chip, up to approx 1.6 KHz | |
| Frequency | |
| Floating point frequency that we will attempt to match | |
| Return | |
SetPin
Sleep
| Sleep | |
| Puts the module into Sleep mode | |
| Return | |
WakeUp
| WakeUp | |
| Wakes the module from Sleep mode | |
| Return | |
WriteMicroseconds