PCA9624, PCA9622 and PCA9626 class library. The PCA9624 is a 8-channel, the PCA9622 is a 16-channel and the PCA9956A is a 24-channel Fm+ I2C-bus 100mA/40V LED driver.
Dependents: PCA9626_Hello PCA9624_Hello PCA9622_Hello
What is this?
Code for PCA9626, PCA9622 and PCA9624.
24-channel, 16-channel and 8-channel PWM output LED driver component class.
Please refer to the component page for details
High-level API is available
A high-level API that can be used as the "PwmOut" of bed-SDK is available.
This API enables to make instances of each LED output pins and control PWM duty cycle by assignment.
For detail information, refer API document of LedPwmOut Class
class which is included in PCA962xA class library.
#include "mbed.h" #include "PCA9626.h" PCA9626 led_cntlr( p28, p27, 0xC4 ); // SDA, SCL, Slave_address(option) LedPwmOut led( led_cntlr, L0 ); int main() { while( 1 ) { for( float p = 0.0f; p < 1.0f; p += 0.1f ) { led = p; wait( 0.1 ); } } }
About the chips
PCA9626
The PCA9626 is an I2C-bus controlled 24-bit LED driver optimized for voltage switch dimming and blinking 100 mA LEDs. Each LED output has its own 8-bit resolution (256 steps) fixed frequency individual PWM controller that operates at 97 kHz with a duty cycle that is adjustable from 0 % to 99.6 % to allow the LED to be set to a specific brightness value.
Datasheet: http://www.nxp.com/documents/data_sheet/PCA9626.pdf
PCA9622
The PCA9622 is an I2C-bus controlled 16-bit LED driver optimized for voltage switch dimming and blinking 100 mA LEDs. Each LED output has its own 8-bit resolution (256 steps) fixed frequency individual PWM controller that operates at 97 kHz with a duty cycle that is adjustable from 0 % to 99.6 % to allow the LED to be set to a specific brightness value.
Datasheet: http://www.nxp.com/documents/data_sheet/PCA9622.pdf
PCA9624
The PCA9624 is an I2C-bus controlled 8-bit LED driver optimized for voltage switch dimming and blinking 100 mA Red/Green/Blue/Amber (RGBA) LEDs. Each LED output has its own 8-bit resolution (256 steps) fixed frequency individual PWM controller that operates at 97 kHz with a duty cycle that is adjustable from 0 % to 99.6 % to allow the LED to be set to a specific brightness value.
Datasheet: http://www.nxp.com/documents/data_sheet/PCA9624.pdf
How the API works?
When the instance is made, all set up for PWM operation are done automatically.
PCA9626, PCA9624 and PCA9622 have internal 97kHz oscillator to generate internal PWM waveform. This signal switchs the output current ON and OFF. The class' function pwm()
controls duty-cycle of this output.
Tips for the chips
PCA962x family
This PCA962x components library can be used for all PCA9926(24-channel), PCA9922(16-channel) and PCA9624(8-channel).
If you are using both chips on the I2C bus, those can be operated like..
#include "mbed.h" #include "PCA9622.h" #include "PCA9626.h" PCA9622 led0( p28, p27, 0xC0 ); // SDA, SCL, Slave_address=0xC0 (16-channel chip) PCA9626 led1( p28, p27, 0xC2 ); // SDA, SCL, Slave_address=0xC2 (24-channel chip) int main() { led0.pwm( .... // PWM control for PCA9955A(16-channel chip) led1.pwm( .... // PWM control for PCA9956A(24-channel chip) ...
Sample code for each types
For PCA9624 (8 channel) : http://developer.mbed.org/users/nxp_ip/code/PCA9624_Hello/
For PCA9622 (16 channel) : http://developer.mbed.org/users/nxp_ip/code/PCA9622_Hello/
For PCA9626 (24 channel) : http://developer.mbed.org/users/nxp_ip/code/PCA9626_Hello/
PCA9624/PCA9624.h@0:7a206e6db594, 2015-02-26 (annotated)
- Committer:
- nxp_ip
- Date:
- Thu Feb 26 09:16:41 2015 +0000
- Revision:
- 0:7a206e6db594
- Child:
- 1:6fcc4f604988
Initial version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nxp_ip | 0:7a206e6db594 | 1 | /** PCA9624 PWM control LED driver |
nxp_ip | 0:7a206e6db594 | 2 | * |
nxp_ip | 0:7a206e6db594 | 3 | * An operation sample of PCA9624 8-channel Fm+ I2C-bus 100mA/40V LED driver. |
nxp_ip | 0:7a206e6db594 | 4 | * mbed accesses the PCA9624 registers through I2C. |
nxp_ip | 0:7a206e6db594 | 5 | * |
nxp_ip | 0:7a206e6db594 | 6 | * @class PCA9624 |
nxp_ip | 0:7a206e6db594 | 7 | * @author Akifumi (Tedd) OKANO, NXP Semiconductors |
nxp_ip | 0:7a206e6db594 | 8 | * @version 0.5 |
nxp_ip | 0:7a206e6db594 | 9 | * @date 26-Feb-2015 |
nxp_ip | 0:7a206e6db594 | 10 | * |
nxp_ip | 0:7a206e6db594 | 11 | * Released under the Apache 2 license License |
nxp_ip | 0:7a206e6db594 | 12 | * |
nxp_ip | 0:7a206e6db594 | 13 | * About PCA9624: |
nxp_ip | 0:7a206e6db594 | 14 | * http://www.nxp.com/products/lighting_driver_and_controller_ics/i2c_led_display_control/series/PCA9624.html |
nxp_ip | 0:7a206e6db594 | 15 | */ |
nxp_ip | 0:7a206e6db594 | 16 | |
nxp_ip | 0:7a206e6db594 | 17 | #ifndef MBED_PCA9624 |
nxp_ip | 0:7a206e6db594 | 18 | #define MBED_PCA9624 |
nxp_ip | 0:7a206e6db594 | 19 | |
nxp_ip | 0:7a206e6db594 | 20 | #include "mbed.h" |
nxp_ip | 0:7a206e6db594 | 21 | #include "PCA962x.h" |
nxp_ip | 0:7a206e6db594 | 22 | |
nxp_ip | 0:7a206e6db594 | 23 | /** PCA9624 class |
nxp_ip | 0:7a206e6db594 | 24 | * |
nxp_ip | 0:7a206e6db594 | 25 | * This is a driver code for the PCA9624 8-channel Fm+ I2C-bus 100mA/40V PWM control LED driver. |
nxp_ip | 0:7a206e6db594 | 26 | * This class provides interface for PCA9624 operation and accessing its registers. |
nxp_ip | 0:7a206e6db594 | 27 | * Detail information is available on next URL. |
nxp_ip | 0:7a206e6db594 | 28 | * http://www.nxp.com/products/lighting_driver_and_controller_ics/i2c_led_display_control/series/PCA9624.html |
nxp_ip | 0:7a206e6db594 | 29 | * |
nxp_ip | 0:7a206e6db594 | 30 | * Example: |
nxp_ip | 0:7a206e6db594 | 31 | * @code |
nxp_ip | 0:7a206e6db594 | 32 | * #include "mbed.h" |
nxp_ip | 0:7a206e6db594 | 33 | * |
nxp_ip | 0:7a206e6db594 | 34 | * #include "PCA9624.h" |
nxp_ip | 0:7a206e6db594 | 35 | * PCA9624 led_cntlr( p28, p27, 0x3E ); // SDA, SCL, Slave_address(option) |
nxp_ip | 0:7a206e6db594 | 36 | * |
nxp_ip | 0:7a206e6db594 | 37 | * int main() |
nxp_ip | 0:7a206e6db594 | 38 | * { |
nxp_ip | 0:7a206e6db594 | 39 | * while(1) { |
nxp_ip | 0:7a206e6db594 | 40 | * for ( int port = 0; port < led_cntlr.number_of_ports(); port++ ) { |
nxp_ip | 0:7a206e6db594 | 41 | * for ( int i = 1; i <= 100; i++ ) { |
nxp_ip | 0:7a206e6db594 | 42 | * led_cntlr.pwm( port, (float)i / 100.0 ); |
nxp_ip | 0:7a206e6db594 | 43 | * wait( 0.01 ); |
nxp_ip | 0:7a206e6db594 | 44 | * } |
nxp_ip | 0:7a206e6db594 | 45 | * } |
nxp_ip | 0:7a206e6db594 | 46 | * led_cntlr.pwm( ALLPORTS, 0.0 ); |
nxp_ip | 0:7a206e6db594 | 47 | * } |
nxp_ip | 0:7a206e6db594 | 48 | * } |
nxp_ip | 0:7a206e6db594 | 49 | * @endcode |
nxp_ip | 0:7a206e6db594 | 50 | */ |
nxp_ip | 0:7a206e6db594 | 51 | |
nxp_ip | 0:7a206e6db594 | 52 | class PCA9624 : public PCA962x |
nxp_ip | 0:7a206e6db594 | 53 | { |
nxp_ip | 0:7a206e6db594 | 54 | public: |
nxp_ip | 0:7a206e6db594 | 55 | /** Name of the PCA9624 registers */ |
nxp_ip | 0:7a206e6db594 | 56 | enum command_reg { |
nxp_ip | 0:7a206e6db594 | 57 | MODE1, MODE2, |
nxp_ip | 0:7a206e6db594 | 58 | PWM0, PWM1, PWM2, PWM3, |
nxp_ip | 0:7a206e6db594 | 59 | PWM4, PWM5, PWM6, PWM7, |
nxp_ip | 0:7a206e6db594 | 60 | GRPPWM, GRPFREQ, |
nxp_ip | 0:7a206e6db594 | 61 | LEDOUT0, LEDOUT1, |
nxp_ip | 0:7a206e6db594 | 62 | SUBADR1, SUBADR2, SUBADR3, ALLCALLADR, |
nxp_ip | 0:7a206e6db594 | 63 | |
nxp_ip | 0:7a206e6db594 | 64 | REGISTER_START = MODE1, |
nxp_ip | 0:7a206e6db594 | 65 | LEDOUT_REGISTER_START = LEDOUT0, |
nxp_ip | 0:7a206e6db594 | 66 | PWM_REGISTER_START = PWM0, |
nxp_ip | 0:7a206e6db594 | 67 | }; |
nxp_ip | 0:7a206e6db594 | 68 | |
nxp_ip | 0:7a206e6db594 | 69 | /** Create a PCA9629A instance connected to specified I2C pins with specified address |
nxp_ip | 0:7a206e6db594 | 70 | * |
nxp_ip | 0:7a206e6db594 | 71 | * @param i2c_sda I2C-bus SDA pin |
nxp_ip | 0:7a206e6db594 | 72 | * @param i2c_sda I2C-bus SCL pin |
nxp_ip | 0:7a206e6db594 | 73 | * @param i2c_address I2C-bus address (default: 0xC0) |
nxp_ip | 0:7a206e6db594 | 74 | */ |
nxp_ip | 0:7a206e6db594 | 75 | PCA9624( PinName i2c_sda, PinName i2c_scl, char i2c_address = PCA962x::DEFAULT_I2C_ADDR ); |
nxp_ip | 0:7a206e6db594 | 76 | |
nxp_ip | 0:7a206e6db594 | 77 | /** Create a PCA9629A instance connected to specified I2C pins with specified address |
nxp_ip | 0:7a206e6db594 | 78 | * |
nxp_ip | 0:7a206e6db594 | 79 | * @param i2c_obj I2C object (instance) |
nxp_ip | 0:7a206e6db594 | 80 | * @param i2c_address I2C-bus address (default: 0xC0) |
nxp_ip | 0:7a206e6db594 | 81 | */ |
nxp_ip | 0:7a206e6db594 | 82 | PCA9624( I2C &i2c_obj, char i2c_address = PCA962x::DEFAULT_I2C_ADDR ); |
nxp_ip | 0:7a206e6db594 | 83 | |
nxp_ip | 0:7a206e6db594 | 84 | /** Destractor |
nxp_ip | 0:7a206e6db594 | 85 | * |
nxp_ip | 0:7a206e6db594 | 86 | */ |
nxp_ip | 0:7a206e6db594 | 87 | virtual ~PCA9624(); |
nxp_ip | 0:7a206e6db594 | 88 | |
nxp_ip | 0:7a206e6db594 | 89 | /** Returns the number of output ports |
nxp_ip | 0:7a206e6db594 | 90 | * |
nxp_ip | 0:7a206e6db594 | 91 | * @returns |
nxp_ip | 0:7a206e6db594 | 92 | * The number of output ports |
nxp_ip | 0:7a206e6db594 | 93 | */ |
nxp_ip | 0:7a206e6db594 | 94 | virtual int number_of_ports( void ); |
nxp_ip | 0:7a206e6db594 | 95 | |
nxp_ip | 0:7a206e6db594 | 96 | #if DOXYGEN_ONLY |
nxp_ip | 0:7a206e6db594 | 97 | /** Set the output duty-cycle, specified as a percentage (float) |
nxp_ip | 0:7a206e6db594 | 98 | * |
nxp_ip | 0:7a206e6db594 | 99 | * @param port Selecting output port |
nxp_ip | 0:7a206e6db594 | 100 | * 'ALLPORTS' can be used to set all port duty-cycle same value. |
nxp_ip | 0:7a206e6db594 | 101 | * @param v A floating-point value representing the output duty-cycle, |
nxp_ip | 0:7a206e6db594 | 102 | * specified as a percentage. The value should lie between |
nxp_ip | 0:7a206e6db594 | 103 | * 0.0f (representing on 0%) and 1.0f (representing on 100%). |
nxp_ip | 0:7a206e6db594 | 104 | * Values outside this range will have undefined behavior. |
nxp_ip | 0:7a206e6db594 | 105 | */ |
nxp_ip | 0:7a206e6db594 | 106 | void pwm( int port, float v ); |
nxp_ip | 0:7a206e6db594 | 107 | |
nxp_ip | 0:7a206e6db594 | 108 | /** Set all output port duty-cycle, specified as a percentage (array of float) |
nxp_ip | 0:7a206e6db594 | 109 | * |
nxp_ip | 0:7a206e6db594 | 110 | * @param vp Aray to floating-point values representing the output duty-cycle, |
nxp_ip | 0:7a206e6db594 | 111 | * specified as a percentage. The value should lie between |
nxp_ip | 0:7a206e6db594 | 112 | * 0.0f (representing on 0%) and 1.0f (representing on 100%). |
nxp_ip | 0:7a206e6db594 | 113 | * |
nxp_ip | 0:7a206e6db594 | 114 | * @note |
nxp_ip | 0:7a206e6db594 | 115 | * The aray should have length of 8 |
nxp_ip | 0:7a206e6db594 | 116 | */ |
nxp_ip | 0:7a206e6db594 | 117 | void pwm( float *vp ); |
nxp_ip | 0:7a206e6db594 | 118 | |
nxp_ip | 0:7a206e6db594 | 119 | /** Register write (single byte) : Low level access to device register |
nxp_ip | 0:7a206e6db594 | 120 | * |
nxp_ip | 0:7a206e6db594 | 121 | * @param reg_addr Register address |
nxp_ip | 0:7a206e6db594 | 122 | * @param data Value for setting into the register |
nxp_ip | 0:7a206e6db594 | 123 | */ |
nxp_ip | 0:7a206e6db594 | 124 | void write( char reg_addr, char data ); |
nxp_ip | 0:7a206e6db594 | 125 | |
nxp_ip | 0:7a206e6db594 | 126 | /** Register write (multiple bytes) : Low level access to device register |
nxp_ip | 0:7a206e6db594 | 127 | * |
nxp_ip | 0:7a206e6db594 | 128 | * @param data Pointer to an array. First 1 byte should be the writing start register address |
nxp_ip | 0:7a206e6db594 | 129 | * @param length Length of data |
nxp_ip | 0:7a206e6db594 | 130 | */ |
nxp_ip | 0:7a206e6db594 | 131 | void write( char *data, int length ); |
nxp_ip | 0:7a206e6db594 | 132 | |
nxp_ip | 0:7a206e6db594 | 133 | /** Register read (single byte) : Low level access to device register |
nxp_ip | 0:7a206e6db594 | 134 | * |
nxp_ip | 0:7a206e6db594 | 135 | * @param reg_addr Register address |
nxp_ip | 0:7a206e6db594 | 136 | * @return Read value from register |
nxp_ip | 0:7a206e6db594 | 137 | */ |
nxp_ip | 0:7a206e6db594 | 138 | char read( char reg_addr ); |
nxp_ip | 0:7a206e6db594 | 139 | |
nxp_ip | 0:7a206e6db594 | 140 | /** Register write (multiple bytes) : Low level access to device register |
nxp_ip | 0:7a206e6db594 | 141 | * |
nxp_ip | 0:7a206e6db594 | 142 | * @param reg_addr Register address |
nxp_ip | 0:7a206e6db594 | 143 | * @param data Pointer to an array. The values are stored in this array. |
nxp_ip | 0:7a206e6db594 | 144 | * @param length Length of data |
nxp_ip | 0:7a206e6db594 | 145 | */ |
nxp_ip | 0:7a206e6db594 | 146 | void read( char reg_addr, char *data, int length ); |
nxp_ip | 0:7a206e6db594 | 147 | #endif |
nxp_ip | 0:7a206e6db594 | 148 | |
nxp_ip | 0:7a206e6db594 | 149 | private: |
nxp_ip | 0:7a206e6db594 | 150 | virtual void initialize( void ); |
nxp_ip | 0:7a206e6db594 | 151 | virtual char pwm_register_access( int port ); |
nxp_ip | 0:7a206e6db594 | 152 | |
nxp_ip | 0:7a206e6db594 | 153 | const int n_of_ports; |
nxp_ip | 0:7a206e6db594 | 154 | } |
nxp_ip | 0:7a206e6db594 | 155 | ; |
nxp_ip | 0:7a206e6db594 | 156 | |
nxp_ip | 0:7a206e6db594 | 157 | #endif // MBED_PCA9624 |