PCA9955A and PCA9956A class library. The PCA9955A is a 16-channel and the PCA9956A is a 24-channel Fm+ I2C-bus 57mA/20V constant current LED driver. The PCA9955A has a extended feature which called "Gradation control".

Dependencies:   CompLedDvrCC

Dependents:   PCA9956A_Hello pca9956b_two_demoboards PCA9955A_Gradation_control PCA9955A_Gradation_control ... more

What is this?

Code for PCA9956A and PCA9955A.
24-channel and 16-channel constant current type LED driver component class.

Please refer to the component page for details

PCA9955B and PCA9956B are I²C-bus controlled 16-channel constant current LED driver optimized for dimming and blinking.

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.
Output current also controllable by API function.
For detail information, refer API document of LedPwmOutCC Class class which is included in PCA995xA class library.

#include "mbed.h"
#include "PCA9956A.h"

PCA9956A    led_cntlr( p28, p27, 0xC4 );  //  SDA, SCL, Slave_address(option)
LedPwmOutCC 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

PCA9956A

The PCA9956A is an I2C-bus controlled 24-channel constant current LED driver optimized for dimming and blinking 57 mA LEDs. Each LED output has its own 8-bit resolution (256 steps) fixed frequency individual PWM controller that operates at 31.25 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/PCA9956A.pdf

PCA9955A

The PCA9955A is an I2C-bus controlled 16-channel constant current LED driver optimized for dimming and blinking 57 mA Red/Green/Blue/Amber (RGBA) LEDs in amusement products. Each LED output has its own 8-bit resolution (256 steps) fixed frequency individual PWM controller that operates at 31.25 kHz with a duty cycle that is adjustable from 0 % to 100 % to allow the LED to be set to a specific brightness value.

On addition to this, the PCA9955A has "Gradation control".
The gradation control is a new feature of PCA995xA series. After the register setting and start the control, the PCA9955A performs dimming cycles automatically without MCU intervention.

Datasheet: http://www.nxp.com/documents/data_sheet/PCA9955A.pdf

PCA9952 and PCA9955 (non-A version)

The PCA9955 and PCA9955 (no-A at end of the type number) is not supported by this component class.

PCA9955(non-A)

PCA9955A != PCA9955

PCA9955A is not software compatible to PCA9955(non-A version).
There are several differences between A and non-A versions.
Register mapping is one of the difference. Please make sure you are using PCA9955A.

How the API works?

When the instance is made, all set up for PWM operation are done automatically.
For the operation, user can control the LED brightness in two ways.

  • PWM
  • Current

PCA9955A and PCA9956A have internal 31.25kHz 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.

Another control is current. Since the PCA9955A and PCA9956A are constant current type LED driver, those have internal current sources. The current source on each channels has independent control of output current. The class' function current() provides interface to current change.

API_and_output

Tips for the chips

PCA995xA family

This PCA995xA components library can be used for both PCA9955A(16-channel) and PCA9956A(24-channel).
If you are using both chips on the I2C bus, those can be operated like..

#include "mbed.h"
 
#include "PCA9955A.h"
#include "PCA9956A.h"

PCA9955A    led0( p28, p27, 0xC0 );    //  SDA, SCL, Slave_address=0xC0 (16-channel chip)
PCA9956A    led1( p28, p27, 0xC2 );    //  SDA, SCL, Slave_address=0xC2 (24-channel chip)
 
int main()
{
    led0.current( ALLPORTS, 1.0 ); //  Set all ports output current 100%
    led1.current( ALLPORTS, 1.0 ); //  Set all ports output current 100%

    led0.pwm( ....    //  PWM control for PCA9955A(16-channel chip)
    led1.pwm( ....    //  PWM control for PCA9956A(24-channel chip)
    ...

Other sample code

For PCA9955A : http://developer.mbed.org/users/nxp_ip/code/PCA9955A_Hello/
For PCA9956A : http://developer.mbed.org/users/nxp_ip/code/PCA9956A_Hello/
For Gradation control of PCA9955A http://developer.mbed.org/users/nxp_ip/code/PCA9955A_Gradation_control/

Committer:
nxp_ip
Date:
Wed Mar 04 10:25:58 2015 +0000
Revision:
2:eeea2e848b81
Parent:
1:3522be54a4f5
Child:
4:fe221e1d4f44
LedPwmOut API (Constant-current type device version: LedPwmOutCC) is included

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxp_ip 0:a624e2eeccac 1 /** PCA9956A constant current LED driver
nxp_ip 0:a624e2eeccac 2 *
nxp_ip 0:a624e2eeccac 3 * An operation sample of PCA9956A 24-channel Fm+ I2C-bus 57mA/20V constant current LED driver.
nxp_ip 0:a624e2eeccac 4 * mbed accesses the PCA9956A registers through I2C.
nxp_ip 0:a624e2eeccac 5 *
nxp_ip 0:a624e2eeccac 6 * @class PCA9956A
nxp_ip 0:a624e2eeccac 7 * @author Akifumi (Tedd) OKANO, NXP Semiconductors
nxp_ip 0:a624e2eeccac 8 * @version 0.5
nxp_ip 0:a624e2eeccac 9 * @date 25-Feb-2015
nxp_ip 0:a624e2eeccac 10 *
nxp_ip 1:3522be54a4f5 11 * Released under the Apache 2 license
nxp_ip 0:a624e2eeccac 12 *
nxp_ip 0:a624e2eeccac 13 * About PCA9956A:
nxp_ip 0:a624e2eeccac 14 * http://www.nxp.com/products/interface_and_connectivity/i2c/i2c_led_display_control/PCA9956ATW.html
nxp_ip 0:a624e2eeccac 15 */
nxp_ip 0:a624e2eeccac 16
nxp_ip 0:a624e2eeccac 17 #ifndef MBED_PCA9956A
nxp_ip 0:a624e2eeccac 18 #define MBED_PCA9956A
nxp_ip 0:a624e2eeccac 19
nxp_ip 0:a624e2eeccac 20 #include "mbed.h"
nxp_ip 0:a624e2eeccac 21 #include "PCA995xA.h"
nxp_ip 2:eeea2e848b81 22 #include "LedPwmOutCC.h"
nxp_ip 0:a624e2eeccac 23
nxp_ip 0:a624e2eeccac 24 /** PCA9956A class
nxp_ip 0:a624e2eeccac 25 *
nxp_ip 0:a624e2eeccac 26 * This is a driver code for the PCA9956A 24-channel Fm+ I2C-bus 57mA/20V constant current LED driver.
nxp_ip 0:a624e2eeccac 27 * This class provides interface for PCA9956A operation and accessing its registers.
nxp_ip 0:a624e2eeccac 28 * Detail information is available on next URL.
nxp_ip 0:a624e2eeccac 29 * http://www.nxp.com/products/interface_and_connectivity/i2c/i2c_led_display_control/PCA9956ATW.html
nxp_ip 0:a624e2eeccac 30 *
nxp_ip 0:a624e2eeccac 31 * Example:
nxp_ip 0:a624e2eeccac 32 * @code
nxp_ip 0:a624e2eeccac 33 * #include "mbed.h"
nxp_ip 0:a624e2eeccac 34 *
nxp_ip 0:a624e2eeccac 35 * #include "PCA9956A.h"
nxp_ip 0:a624e2eeccac 36 * PCA9956A led_cntlr( p28, p27, 0x02 ); // SDA, SCL, Slave_address(option)
nxp_ip 0:a624e2eeccac 37 *
nxp_ip 0:a624e2eeccac 38 * int main()
nxp_ip 0:a624e2eeccac 39 * {
nxp_ip 0:a624e2eeccac 40 * led_cntlr.current( ALLPORTS, 1.0 ); // Set all ports output current 100%
nxp_ip 0:a624e2eeccac 41 *
nxp_ip 0:a624e2eeccac 42 * while(1) {
nxp_ip 0:a624e2eeccac 43 * for ( int port = 0; port < led_cntlr.number_of_ports(); port++ ) {
nxp_ip 0:a624e2eeccac 44 * for ( int i = 1; i <= 100; i++ ) {
nxp_ip 0:a624e2eeccac 45 * led_cntlr.pwm( port, (float)i / 100.0 );
nxp_ip 0:a624e2eeccac 46 * wait( 0.01 );
nxp_ip 0:a624e2eeccac 47 * }
nxp_ip 0:a624e2eeccac 48 * }
nxp_ip 0:a624e2eeccac 49 * led_cntlr.pwm( ALLPORTS, 0.0 );
nxp_ip 0:a624e2eeccac 50 * }
nxp_ip 0:a624e2eeccac 51 * }
nxp_ip 0:a624e2eeccac 52 * @endcode
nxp_ip 0:a624e2eeccac 53 */
nxp_ip 0:a624e2eeccac 54
nxp_ip 0:a624e2eeccac 55 class PCA9956A : public PCA995xA
nxp_ip 0:a624e2eeccac 56 {
nxp_ip 0:a624e2eeccac 57 public:
nxp_ip 0:a624e2eeccac 58 /** Name of the PCA9956A registers */
nxp_ip 0:a624e2eeccac 59 enum command_reg {
nxp_ip 0:a624e2eeccac 60 MODE1, MODE2,
nxp_ip 0:a624e2eeccac 61 LEDOUT0, LEDOUT1, LEDOUT2, LEDOUT3, LEDOUT4, LEDOUT5,
nxp_ip 0:a624e2eeccac 62 GRPPWM, GRPFREQ,
nxp_ip 0:a624e2eeccac 63 PWM0, PWM1, PWM2, PWM3,
nxp_ip 0:a624e2eeccac 64 PWM4, PWM5, PWM6, PWM7,
nxp_ip 0:a624e2eeccac 65 PWM8, PWM9, PWM10, PWM11,
nxp_ip 0:a624e2eeccac 66 PWM12, PWM13, PWM14, PWM15,
nxp_ip 0:a624e2eeccac 67 PWM16, PWM17, PWM18, PWM19,
nxp_ip 0:a624e2eeccac 68 PWM20, PWM21, PWM22, PWM23,
nxp_ip 0:a624e2eeccac 69 IREF0, IREF1, IREF2, IREF3,
nxp_ip 0:a624e2eeccac 70 IREF4, IREF5, IREF6, IREF7,
nxp_ip 0:a624e2eeccac 71 IREF8, IREF9, IREF10, IREF11,
nxp_ip 0:a624e2eeccac 72 IREF12, IREF13, IREF14, IREF15,
nxp_ip 0:a624e2eeccac 73 IREF16, IREF17, IREF18, IREF19,
nxp_ip 0:a624e2eeccac 74 IREF20, IREF21, IREF22, IREF23,
nxp_ip 0:a624e2eeccac 75 OFFSET = 0x3A,
nxp_ip 0:a624e2eeccac 76 SUBADR1, SUBADR2, SUBADR3, ALLCALLADR,
nxp_ip 0:a624e2eeccac 77 PWMALL, IREFALL,
nxp_ip 0:a624e2eeccac 78 EFLAG0, EFLAG1, EFLAG2, EFLAG3, EFLAG4, EFLAG5,
nxp_ip 0:a624e2eeccac 79
nxp_ip 0:a624e2eeccac 80 REGISTER_START = MODE1,
nxp_ip 0:a624e2eeccac 81 LEDOUT_REGISTER_START = LEDOUT0,
nxp_ip 0:a624e2eeccac 82 PWM_REGISTER_START = PWM0,
nxp_ip 0:a624e2eeccac 83 IREF_REGISTER_START = IREF0,
nxp_ip 0:a624e2eeccac 84 };
nxp_ip 0:a624e2eeccac 85
nxp_ip 0:a624e2eeccac 86 /** Create a PCA9629A instance connected to specified I2C pins with specified address
nxp_ip 0:a624e2eeccac 87 *
nxp_ip 0:a624e2eeccac 88 * @param i2c_sda I2C-bus SDA pin
nxp_ip 0:a624e2eeccac 89 * @param i2c_sda I2C-bus SCL pin
nxp_ip 0:a624e2eeccac 90 * @param i2c_address I2C-bus address (default: 0xC0)
nxp_ip 0:a624e2eeccac 91 */
nxp_ip 0:a624e2eeccac 92 PCA9956A( PinName i2c_sda, PinName i2c_scl, char i2c_address = PCA995xA::DEFAULT_I2C_ADDR );
nxp_ip 0:a624e2eeccac 93
nxp_ip 0:a624e2eeccac 94 /** Create a PCA9629A instance connected to specified I2C pins with specified address
nxp_ip 0:a624e2eeccac 95 *
nxp_ip 0:a624e2eeccac 96 * @param i2c_obj I2C object (instance)
nxp_ip 0:a624e2eeccac 97 * @param i2c_address I2C-bus address (default: 0xC0)
nxp_ip 0:a624e2eeccac 98 */
nxp_ip 0:a624e2eeccac 99 PCA9956A( I2C &i2c_obj, char i2c_address = PCA995xA::DEFAULT_I2C_ADDR );
nxp_ip 0:a624e2eeccac 100
nxp_ip 0:a624e2eeccac 101 /** Destractor
nxp_ip 0:a624e2eeccac 102 *
nxp_ip 0:a624e2eeccac 103 */
nxp_ip 0:a624e2eeccac 104 virtual ~PCA9956A();
nxp_ip 0:a624e2eeccac 105
nxp_ip 0:a624e2eeccac 106 /** Returns the number of output ports
nxp_ip 0:a624e2eeccac 107 *
nxp_ip 0:a624e2eeccac 108 * @returns
nxp_ip 0:a624e2eeccac 109 * The number of output ports
nxp_ip 0:a624e2eeccac 110 */
nxp_ip 0:a624e2eeccac 111 virtual int number_of_ports( void );
nxp_ip 0:a624e2eeccac 112
nxp_ip 0:a624e2eeccac 113 #if DOXYGEN_ONLY
nxp_ip 0:a624e2eeccac 114 /** Set the output duty-cycle, specified as a percentage (float)
nxp_ip 0:a624e2eeccac 115 *
nxp_ip 0:a624e2eeccac 116 * @param port Selecting output port
nxp_ip 0:a624e2eeccac 117 * 'ALLPORTS' can be used to set all port duty-cycle same value.
nxp_ip 0:a624e2eeccac 118 * @param v A floating-point value representing the output duty-cycle,
nxp_ip 0:a624e2eeccac 119 * specified as a percentage. The value should lie between
nxp_ip 1:3522be54a4f5 120 * 0.0f (representing on 0%) and 1.0f (representing on 99.6%).
nxp_ip 0:a624e2eeccac 121 * Values outside this range will have undefined behavior.
nxp_ip 0:a624e2eeccac 122 */
nxp_ip 0:a624e2eeccac 123 void pwm( int port, float v );
nxp_ip 0:a624e2eeccac 124
nxp_ip 0:a624e2eeccac 125 /** Set all output port duty-cycle, specified as a percentage (array of float)
nxp_ip 0:a624e2eeccac 126 *
nxp_ip 0:a624e2eeccac 127 * @param vp Aray to floating-point values representing the output duty-cycle,
nxp_ip 0:a624e2eeccac 128 * specified as a percentage. The value should lie between
nxp_ip 1:3522be54a4f5 129 * 0.0f (representing on 0%) and 1.0f (representing on 99.6%).
nxp_ip 0:a624e2eeccac 130 *
nxp_ip 0:a624e2eeccac 131 * @note
nxp_ip 0:a624e2eeccac 132 * The aray should have length of 24
nxp_ip 0:a624e2eeccac 133 */
nxp_ip 0:a624e2eeccac 134 void pwm( float *vp );
nxp_ip 0:a624e2eeccac 135
nxp_ip 0:a624e2eeccac 136 /** Set the output current, specified as a percentage (float)
nxp_ip 0:a624e2eeccac 137 *
nxp_ip 0:a624e2eeccac 138 * @param port Selecting output port
nxp_ip 0:a624e2eeccac 139 * 'ALLPORTS' can be used to set all port duty-cycle same value.
nxp_ip 0:a624e2eeccac 140 * @param v A floating-point value representing the output current,
nxp_ip 0:a624e2eeccac 141 * specified as a percentage. The value should lie between
nxp_ip 0:a624e2eeccac 142 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
nxp_ip 0:a624e2eeccac 143 * Values outside this range will have undefined behavior.
nxp_ip 0:a624e2eeccac 144 */
nxp_ip 0:a624e2eeccac 145 void current( int port, float vp );
nxp_ip 0:a624e2eeccac 146
nxp_ip 0:a624e2eeccac 147 /** Set all output port curent, specified as a percentage (array of float)
nxp_ip 0:a624e2eeccac 148 *
nxp_ip 0:a624e2eeccac 149 * @param vp Aray to floating-point values representing the output current,
nxp_ip 0:a624e2eeccac 150 * specified as a percentage. The value should lie between
nxp_ip 0:a624e2eeccac 151 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
nxp_ip 0:a624e2eeccac 152 *
nxp_ip 0:a624e2eeccac 153 * @note
nxp_ip 0:a624e2eeccac 154 * The aray should have length of 24
nxp_ip 0:a624e2eeccac 155 */
nxp_ip 0:a624e2eeccac 156 void current( float *vP );
nxp_ip 0:a624e2eeccac 157
nxp_ip 0:a624e2eeccac 158 /** Register write (single byte) : Low level access to device register
nxp_ip 0:a624e2eeccac 159 *
nxp_ip 0:a624e2eeccac 160 * @param reg_addr Register address
nxp_ip 0:a624e2eeccac 161 * @param data Value for setting into the register
nxp_ip 0:a624e2eeccac 162 */
nxp_ip 0:a624e2eeccac 163 void write( char reg_addr, char data );
nxp_ip 0:a624e2eeccac 164
nxp_ip 0:a624e2eeccac 165 /** Register write (multiple bytes) : Low level access to device register
nxp_ip 0:a624e2eeccac 166 *
nxp_ip 0:a624e2eeccac 167 * @param data Pointer to an array. First 1 byte should be the writing start register address
nxp_ip 0:a624e2eeccac 168 * @param length Length of data
nxp_ip 0:a624e2eeccac 169 */
nxp_ip 0:a624e2eeccac 170 void write( char *data, int length );
nxp_ip 0:a624e2eeccac 171
nxp_ip 0:a624e2eeccac 172 /** Register read (single byte) : Low level access to device register
nxp_ip 0:a624e2eeccac 173 *
nxp_ip 0:a624e2eeccac 174 * @param reg_addr Register address
nxp_ip 0:a624e2eeccac 175 * @return Read value from register
nxp_ip 0:a624e2eeccac 176 */
nxp_ip 0:a624e2eeccac 177 char read( char reg_addr );
nxp_ip 0:a624e2eeccac 178
nxp_ip 0:a624e2eeccac 179 /** Register write (multiple bytes) : Low level access to device register
nxp_ip 0:a624e2eeccac 180 *
nxp_ip 0:a624e2eeccac 181 * @param reg_addr Register address
nxp_ip 0:a624e2eeccac 182 * @param data Pointer to an array. The values are stored in this array.
nxp_ip 0:a624e2eeccac 183 * @param length Length of data
nxp_ip 0:a624e2eeccac 184 */
nxp_ip 0:a624e2eeccac 185 void read( char reg_addr, char *data, int length );
nxp_ip 0:a624e2eeccac 186 #endif
nxp_ip 0:a624e2eeccac 187
nxp_ip 0:a624e2eeccac 188 private:
nxp_ip 0:a624e2eeccac 189 void initialize( void );
nxp_ip 0:a624e2eeccac 190 virtual char pwm_register_access( int port );
nxp_ip 0:a624e2eeccac 191 virtual char current_register_access( int port );
nxp_ip 0:a624e2eeccac 192
nxp_ip 0:a624e2eeccac 193 const int n_of_ports;
nxp_ip 0:a624e2eeccac 194 }
nxp_ip 0:a624e2eeccac 195 ;
nxp_ip 0:a624e2eeccac 196
nxp_ip 0:a624e2eeccac 197 #endif // MBED_PCA9956A