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.

Dependencies:   CompLedDvr

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

8, 16 & 24-channel Fm+ I2C-bus 100mA/40 V LED driver

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.

API_and_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/

Committer:
nxp_ip
Date:
Thu Mar 19 10:02:57 2015 +0000
Revision:
7:7ebf563f6e6c
Parent:
0:7a206e6db594
API document update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxp_ip 0:7a206e6db594 1 #include "mbed.h"
nxp_ip 0:7a206e6db594 2 #include "PCA962x.h"
nxp_ip 0:7a206e6db594 3
nxp_ip 0:7a206e6db594 4 PCA962x::PCA962x( PinName i2c_sda, PinName i2c_scl, char i2c_address )
nxp_ip 0:7a206e6db594 5 : i2c_p( new I2C( i2c_sda, i2c_scl ) ), i2c( *i2c_p ), address( i2c_address )
nxp_ip 0:7a206e6db594 6 {
nxp_ip 0:7a206e6db594 7 }
nxp_ip 0:7a206e6db594 8
nxp_ip 0:7a206e6db594 9 PCA962x::PCA962x( I2C &i2c_, char i2c_address )
nxp_ip 0:7a206e6db594 10 : i2c_p( NULL ), i2c( i2c_ ), address( i2c_address )
nxp_ip 0:7a206e6db594 11 {
nxp_ip 0:7a206e6db594 12 }
nxp_ip 0:7a206e6db594 13
nxp_ip 0:7a206e6db594 14 PCA962x::~PCA962x()
nxp_ip 0:7a206e6db594 15 {
nxp_ip 0:7a206e6db594 16 if ( NULL != i2c_p )
nxp_ip 0:7a206e6db594 17 delete i2c_p;
nxp_ip 0:7a206e6db594 18 }
nxp_ip 0:7a206e6db594 19
nxp_ip 0:7a206e6db594 20 void PCA962x::reset( void )
nxp_ip 0:7a206e6db594 21 {
nxp_ip 0:7a206e6db594 22 char va[] = { 0xA5, 0x5A };
nxp_ip 0:7a206e6db594 23 i2c.write( 0x06, va, sizeof( va ) );
nxp_ip 0:7a206e6db594 24 }
nxp_ip 0:7a206e6db594 25
nxp_ip 0:7a206e6db594 26 void PCA962x::pwm( int port, float v )
nxp_ip 0:7a206e6db594 27 {
nxp_ip 0:7a206e6db594 28 char reg_addr;
nxp_ip 0:7a206e6db594 29
nxp_ip 0:7a206e6db594 30 reg_addr = pwm_register_access( port );
nxp_ip 0:7a206e6db594 31
nxp_ip 0:7a206e6db594 32 if ( PWMALL == reg_addr ) {
nxp_ip 0:7a206e6db594 33 int np = number_of_ports();
nxp_ip 0:7a206e6db594 34 float va[ np ];
nxp_ip 0:7a206e6db594 35
nxp_ip 0:7a206e6db594 36 for ( int i = 0; i < np; i++ )
nxp_ip 0:7a206e6db594 37 va[ i ] = v;
nxp_ip 0:7a206e6db594 38
nxp_ip 0:7a206e6db594 39 pwm( va );
nxp_ip 0:7a206e6db594 40
nxp_ip 0:7a206e6db594 41 } else {
nxp_ip 0:7a206e6db594 42 write( reg_addr, (char)(v * 255.0) );
nxp_ip 0:7a206e6db594 43 }
nxp_ip 0:7a206e6db594 44 }
nxp_ip 0:7a206e6db594 45
nxp_ip 0:7a206e6db594 46 void PCA962x::pwm( float *vp )
nxp_ip 0:7a206e6db594 47 {
nxp_ip 0:7a206e6db594 48 int n_of_ports = number_of_ports();
nxp_ip 0:7a206e6db594 49 char data[ n_of_ports + 1 ];
nxp_ip 0:7a206e6db594 50
nxp_ip 0:7a206e6db594 51 *data = pwm_register_access( 0 );
nxp_ip 0:7a206e6db594 52
nxp_ip 0:7a206e6db594 53 for ( int i = 1; i <= n_of_ports; i++ )
nxp_ip 0:7a206e6db594 54 data[ i ] = (char)(*vp++ * 255.0);
nxp_ip 0:7a206e6db594 55
nxp_ip 0:7a206e6db594 56 write( data, sizeof( data ) );
nxp_ip 0:7a206e6db594 57 }
nxp_ip 0:7a206e6db594 58
nxp_ip 0:7a206e6db594 59 void PCA962x::write( char *data, int length )
nxp_ip 0:7a206e6db594 60 {
nxp_ip 0:7a206e6db594 61 *data |= AUTO_INCREMENT;
nxp_ip 0:7a206e6db594 62 i2c.write( address, data, length );
nxp_ip 0:7a206e6db594 63 }
nxp_ip 0:7a206e6db594 64
nxp_ip 0:7a206e6db594 65 void PCA962x::write( char reg_addr, char data )
nxp_ip 0:7a206e6db594 66 {
nxp_ip 0:7a206e6db594 67 char c[2];
nxp_ip 0:7a206e6db594 68
nxp_ip 0:7a206e6db594 69 c[0] = reg_addr;
nxp_ip 0:7a206e6db594 70 c[1] = data;
nxp_ip 0:7a206e6db594 71
nxp_ip 0:7a206e6db594 72 i2c.write( address, c, 2 );
nxp_ip 0:7a206e6db594 73 }
nxp_ip 0:7a206e6db594 74
nxp_ip 0:7a206e6db594 75 void PCA962x::read( char reg_addr, char *data, int length )
nxp_ip 0:7a206e6db594 76 {
nxp_ip 0:7a206e6db594 77 reg_addr |= 0x80;
nxp_ip 0:7a206e6db594 78 i2c.write( address, (char *)(&reg_addr), 1, true );
nxp_ip 0:7a206e6db594 79 i2c.read( address, data, length );
nxp_ip 0:7a206e6db594 80 }
nxp_ip 0:7a206e6db594 81
nxp_ip 0:7a206e6db594 82 char PCA962x::read( char reg_addr )
nxp_ip 0:7a206e6db594 83 {
nxp_ip 0:7a206e6db594 84 i2c.write( address, (char *)(&reg_addr), 1, true );
nxp_ip 0:7a206e6db594 85 i2c.read( address, (char *)(&reg_addr), 1 );
nxp_ip 0:7a206e6db594 86
nxp_ip 0:7a206e6db594 87 return ( reg_addr );
nxp_ip 0:7a206e6db594 88 }