PCA9632 - 4-bit Fm+ I2C-bus low power LED driver

Description

Library for interfacing NXP PCA9632 4-channel, 8-bit PWM controller for LED

The PCA9632 is an I2C-bus controlled 4-bit LED driver optimized for Red/Green/Blue/Amber (RGBA) color mixing applications. -) I2C interface with communication speed up to 1 MHz (I2C Fast Mode Plus) -) Two hardware address pins allow up to 4 devices on the same bus (10-pin package option only) -) 256 steps (8-bit PWM) of individual PWM (e.g. LED brightness) control

OVERVIEW

PCA9632_Abstract:
This library can be used to handle the NXP PCA9632 4-bit Fast-Mode Plus I2C-bus low power LED driver.

Interface: 1x I2C

The PCA9632 is an I2C-bus controlled 4-bit LED driver optimized for Red/Green/Blue/Amber (RGBA) color mixing applications. The PCA9632 is a drop-in upgrade for the PCA9633 with 40x power reduction.
  • 4 LED drivers. Each output programmable.
  • 1 MHz Fast-mode Plus I2C-bus interface with 30 mA high drive capability on SDA output
  • 256-step (8-bit) linear programmable brightness per LED output varying from fully off (default) to maximum brightness using a 1.5625 kHz PWM signal in Individual brightness mode
  • 64-step (6-bit) linear programmable brightness for each LED output varying from fully off (default) to maximum brightness using a 6.25 kHz PWM signal in group dimming mode
  • In group dimming mode, 16-step group brightness control allows global dimming (using a 190 Hz PWM signal) from fully off to maximum brightness (default)
  • 256-step (8-bit) linear programmable brightness per LED output varying from fully off (default) to maximum brightness using a 1.5625 kHz PWM signal in group blinking mode
  • 64-step group blinking with frequency programmable from 24 Hz to 6 Hz and duty cycle from 0 % to 98.4 %
  • 256-step group blinking with frequency programmable from 6 Hz to 0.09 Hz (10.73 s) and duty cycle from 0 % to 99.6 %
  • Four totem pole outputs (sink 25 mA and source 10 mA at 5 V) with software programmable open-drain LED outputs selection (default at high-impedance). No input function.
  • 10-pin package option provides two hardware address pins
  • Output state change programmable on the Acknowledge or the STOP Command

  • For more information, see the NXP website
    PCA9632_How_to_use:
    /* Hardware setup */ const { PORT_I2C = 0, // The first I2C interface should be used. CHIP_ADDR = PCA9632_I2C_ADR0, // I2C Address of the chip // (depends on the logic level at the chip's ADDR pins - A0/A1) } /* Handles for available sensors */ static hPCA9632[TPCA9632_Config]; // Handle to manage the PCA9632 #callback Timer2s() { static iState = 0; new iLed0 = PCA9632_LEDOUT_LED_OFF; new iLed1 = PCA9632_LEDOUT_LED_OFF; new iLed2 = PCA9632_LEDOUT_LED_OFF; new iLed3 = PCA9632_LEDOUT_LED_OFF; iState++; iState %= 6; // Set local variable for LEDOUT for individual state representation switch (iState) { case 1: iLed0 = PCA9632_LEDOUT_LED_ON; case 2: iLed1 = PCA9632_LEDOUT_LED_ON; case 3: iLed2 = PCA9632_LEDOUT_LED_ON; case 4: iLed3 = PCA9632_LEDOUT_LED_ON; case 5: { iLed0 = PCA9632_LEDOUT_LED_ON; iLed1 = PCA9632_LEDOUT_LED_ON; iLed2 = PCA9632_LEDOUT_LED_ON; iLed3 = PCA9632_LEDOUT_LED_ON; } } #log("PCA9632: State=%d, LedOut=%02xh: %s%s%s%s%s%s", iState, iLed0 | iLed1<2 | iLed2<4 | iLed3<6, iState==0?"ALL OFF":"", iState==1?"LED0":"", iState==2?"LED1":"", iState==3?"LED2":"", iState==4?"LED3":"", iState==5?"ALL ON":""); // Inits the I2C interface catch(rM2M_I2cInit(PORT_I2C, PCA9632_CLOCK, 0)); // Set LEDOUT state catch(PCA9632_SetLedOut(hPCA9632, iLed0, iLed1, iLed2, iLed3)); // Close the I2C interface catch(rM2M_I2cClose(PORT_I2C)); } #callback TestPCA9632() { // Inits the I2C interface catch(rM2M_I2cInit(PORT_I2C, PCA9632_CLOCK, 0)); // Inits the PCA9646 lib catch(PCA9632_Init(hPCA9632, PORT_I2C, CHIP_ADDR)); // Write Mode1 configuration. Using 0x00 means: // -) Normal mode // -) Does not respond to I2C-bus subaddress 1 // -) Does not respond to I2C-bus subaddress 2 // -) Does not respond to I2C-bus subaddress 3 // -) Does not respond to LED All Call I2C Addresses catch(PCA9632_SetMode1(hPCA9632, 0x00)); // Write Mode2 configuration (hardware dependent) // -) Group control = dimming // -) PCA9632_MODE2_INVERTED : Output logic state inverted // -) Outputs change on STOP command // -) PCA9632_MODE2_OUTDRV_POLE: Totem pole structure catch(PCA9632_SetMode2(hPCA9632, PCA9632_MODE2_OUTDRV_POLE|PCA9632_MODE2_INVERTED)); // Read back the current mode configuration new iMode1, iMode2; catch(PCA9632_GetMode1(hPCA9632, iMode1)); catch(PCA9632_GetMode2(hPCA9632, iMode2)); #log("PCA9632: Mode1: %02xh, Mode2: %02xh", iMode1, iMode2); // Close the I2C interface catch(rM2M_I2cClose(PORT_I2C)); // start periodically timer setInterval(Timer2s, 2000); } /* Application entry point */ main() { salve(TestPCA9632); }

    BASIC

    PCA9632_CLOCK -

    typical I2C clock speed to be used (400kHz, I2C Fast-Mode)

    TPCA9632_I2C_ADRx:

    Available I2C addresses

    The corresponding I2C address must be used if the condition applies (A1 to A0):
    Use "PCA9632_I2C_ADR2" when using the 8-pin version (without A1-A0 address pins) of the PCA9632.
    PCA9632_I2C_ADR0 - 0 0
    PCA9632_I2C_ADR1 - 0 1
    PCA9632_I2C_ADR2 - 1 0
    PCA9632_I2C_ADR3 - 1 1
    TPCA9632_MODE1:

    Available Mode1 options

    PCA9632_MODE1_AI_x - bit 5-7: Auto-Increment options (Read only)
    PCA9632_MODE1_SLEEP - bit 4 (0x10):
    0 - Normal mode
    1 - Sleep Mode enabled (Oscillator off, default)
  • When the oscillator is off (Sleep mode), the LED outputs cannot be turned on, off or dimmed/blinked. Sleep Mode is enabled after power-on (Default).
  • It takes 500 µs max. for the oscillator to be up and running once SLEEP bit has been set to logic 0. Timings on LEDn outputs are not guaranteed if PWMx, GRPPWM or GRPFREQ registers are accessed within the 500 µs window.
  • PCA9632_MODE1_SUBADR1_ON - bit3 (0x08):
    0 - Does not respond to I2C-bus subaddress 1 (default)
    1 - Respond to I2C-bus subaddress 1
    PCA9632_MODE1_SUBADR2_ON - bit3 (0x04):
    0 - Does not respond to I2C-bus subaddress 2 (defalut)
    1 - Respond to I2C-bus subaddress 2
    PCA9632_MODE1_SUBADR3_ON - bit3 (0x02):
    0 - Does not respond to I2C-bus subaddress 3 (defalut)
    1 - Respond to I2C-bus subaddress 3
    PCA9632_MODE1_ALLCALL_ON - bit3 (0x01):
    0 - Does not respond to LED All Call I2C Addresses
    1 - Respond to LED All Call I2C Addresses (default)
    PCA9632_MODE1_AI_x:

    Auto-Increment options (Mode1 Register, bit 5-7)

    PCA9632_MODE1_AI_OFF - (0x00 << 5): no Auto-Increment
    PCA9632_MODE1_AI_ALL - (0x04 << 5): Auto-Increment for all registers. Roll over to PCA9632_REG_MODE1 (0x00) after the last register PCA9632_REG_ALLCALLADR (0x0C) is accessed. (default)
    PCA9632_MODE1_AI_PWM - (0x05 << 5): Auto-Increment for Individual brightness registers only. Roll over to PCA9632_REG_PWM0 (0x02) after the last register PCA9632_REG_PWM3 (0x05) is accessed.
    PCA9632_MODE1_AI_GLOBAL - (0x06 << 5): Auto-Increment for global control registers only. Roll over to PCA9632_REG_GRPPWM (0x06) after the last register PCA9632_REG_GRPFREQ (0x07) is accessed.
    PCA9632_MODE1_AI_PWM_AND_GLOBAL - (0x07 << 5):Auto-Increment for individual and global control registers only. Roll overto PCA9632_REG_PWM0 (0x02) after the last register PCA9632_REG_GRPFREQ (0x07) is accessed.
    PCA9632_MODE1_AI_MSK - (0x07 << 5): Auto-Increment options bit mask
    TPCA9632_MODE2:

    Available Mode2 options

    PCA9632_MODE2_RESERVED_MSK - (0xC0): Bit mask for reserved bit 6-7 (reserved bits 6-7 are Read only, default = 0)
    PCA9632_MODE2_DMBLNK - bit 5 (0x20): Group control
    0 - dimming (default)
    1 - blinking
    PCA9632_MODE2_INVERTED - bit 4 (0x10): Output logic configuration
    0 - Output logic state not inverted. Value to use when no external driver used. (default)
    1 - Output logic state inverted. Value to use when external driver used.
    PCA9632_MODE2_OCH_ACK - bit 3 (0x08): Output change configuration
    0 - Outputs change on STOP command. (default)
    Change of the outputs at the STOP command allows synchronizing outputs of more than one PCA9632. Applicable to
    registers from PCA9632_REG_PWM0 (0x02) to PCA9632_REG_LEDOUT (0x08) only.
    1 - Outputs change on ACK.
    PCA9632_MODE2_OUTDRV_POLE - bit 2 (0x04): Output driver configuration
    0 - The 4 LED outputs are configured with an open-drain structure. (default)
    1 - The 4 LED outputs are configured with a totem pole structure.
    PCA9632_MODE2_UNUSED - bit 0-1: Unused (default 0x01)
    PCA9632_MODE2_UNUSED_MSK - (0x03): Bit mask for unused bit 0-1
    TPCA9632_LEDOUT:

    Available LEDOUT options for LEDx (Value | Access | Description)

    PCA9632_LEDOUT_LED_OFF - 0x00 | RW | LED driver x is off. (defalut)
    PCA9632_LEDOUT_LED_ON - 0x01 | RW | LED driver x is fully on (individual brightness and group dimming/blinking not controlled).
    PCA9632_LEDOUT_LED_PWM - 0x02 | RW | LED driver x individual brightness can be controlled through its PCA9632_REG_PWMx (0x02 - 0x05) register.
    PCA9632_LEDOUT_LED_GRPPWM - 0x03 | RW | LED driver x individual brightness and group dimming/blinking can be controlled through its PCA9632_REG_PWMx (0x02 - 0x05) register and the PCA9632_REG_GRPPWM (0x06) registers.
    PCA9632_Init(hCfg[TPCA9632_Config], iI2C, iAdr)

    Initializes I2C communication with the PCA9632.


    It simply copies the I2C port, I2C address to the transferred empty device handle.

    hCfg : TPCA9632_Config - Empty device handle for a PCA9632
    iI2C : s32 - I2C interface where PCA9632 is connected to
    The I2C interface must be initialized before using rM2M_I2cInit().
    iAdr : TPCA9632_I2C_ADRx - I2C Address of the chip (depends on the logic level at the chip's A0-A1 pins)
    returns : s32
    OK - If successful (Currently no errors are detected)
    PCA9632_SetSleep(hCfg[TPCA9632_Config], bool:bSleep)

    Activates/Deactivates the PCA9685 by clearing/setting the "SLEEP" bit in the "MODE1" register


    hCfg : TPCA9632_Config - Device handle of a specific PCA9632 (Initialized by PCA9632_Init() )
    bSleep : blool - Operating mode selection
    true - Set the PCA9685 into sleep mode (i.e. Oscillator is off) and thus grants minimum power consumption
    false - Normal mode is activated
    returns : s32
    OK - if successful
    < OK - if an error occurs
    PCA9632_GetMode1(hCfg[TPCA9632_Config], &iMode1)

    Reads the contents of mode register 1 from the PCA9632.


    hCfg : TPCA9632_Config - Device handle of a specific PCA9632 (Initialized by PCA9632_Init() )
    iMode1 : TPCA9632_MODE1 - Buffer for storing the data read from the Mode register 1
    returns : s32
    OK - if successful
    < OK - if an error occurs
    PCA9632_SetMode1(hCfg[TPCA9632_Config], iMode1)

    Sets the mode register 1 of the PCA9632.


    hCfg : TPCA9632_Config - Device handle of a specific PCA9632 (Initialized by PCA9632_Init() )
    iMode1 : TPCA9632_MODE1 - Value that should be written to Mode register 1
    returns : s32
    OK - if successful
    < OK - if an error occurs
    PCA9632_GetMode2(hCfg[TPCA9632_Config], &iMode2)

    Reads the contents of mode register 2 from the PCA9632.


    hCfg : TPCA9632_Config - Device handle of a specific PCA9632 (Initialized by PCA9632_Init() )
    iMode2 : TPCA9632_MODE2 - Buffer for storing the data read from the Mode register 2
    returns : s32
    OK - if successful
    < OK - if an error occurs
    PCA9632_SetMode2(hCfg[TPCA9632_Config], iMode2)

    Sets the mode register 2 of the PCA9632.


    hCfg : TPCA9632_Config - Device handle of a specific PCA9632 (Initialized by PCA9632_Init() )
    iMode2 : TPCA9632_MODE2 - Value that should be written to Mode register 2
    returns : s32
    OK - if successful
    < OK - if an error occurs
    PCA9632_SetLedOut(hCfg[TPCA9632_Config], iLed0, iLed1, iLed2, iLed3)

    Sets the LED output state register.

    The mode (see TPCA9632_LEDOUT) can be set individually for each LED of the PCA9632. Use the PCA9632_SetLedOutAll() function to set all LEDs of the PCA9632 to the same mode.

    hCfg : TPCA9632_Config - Device handle of a specific PCA9632 (Initialized by PCA9632_Init() )
    iLed0 : TPCA9632_LEDOUT - Output state for LED0
    iLed1 : TPCA9632_LEDOUT - Output state for LED1
    iLed2 : TPCA9632_LEDOUT - Output state for LED2
    iLed3 : TPCA9632_LEDOUT - Output state for LED3
    returns : s32
    OK - if successful
    < OK - if an error occurs
    PCA9632_SetLedOutAll(hCfg[TPCA9632_Config], iLedOut)

    Sets the LED output state register.

    All LEDs of the PCA9632 are set to the same mode.

    hCfg : TPCA9632_Config - Device handle of a specific PCA9632 (Initialized by PCA9632_Init() )
    iLedOut : TPCA9632_LEDOUT - Output state for all LEDs
    returns : s32
    OK - if successful
    < OK - if an error occurs
    PCA9632_SetPwm(hCfg[TPCA9632_Config], iLed, iPWM)

    Sets the individual brightness control registers for a specific LED of the PCA9632.


    hCfg : TPCA9632_Config - Device handle of a specific PCA9632 (Initialized by PCA9632_Init() )
    iLed : u8 - Index of the LED whose register is to be set (0-3 allowed).
    iPWM : u8 - The PWM value that should be written to the specified LED register.
    returns : s32
    OK - if successful
    ERROR - Invalid LED index has been transferred
    < OK - if another error occurs

    Operating in Individual brightness mode (LEDx output state control = PCA9632_LEDOUT_LED_PWM)
  • Frequeny: 1.5625 kHz
  • Duty cycle: 0% - 99.6%
  • Steps:256 (i.e. all 8 bits of iPWM are used)
  • Duty cycle = iPWM/256

    Operating in group dimming mode (LEDx output state control = PCA9632_LEDOUT_LED_GRPPWM, Bit PCA9632_MODE2_DMBLNK of Mode 2 = 0 )
  • Frequeny: 6.25 kHz
  • Duty cycle: 0% - 98.4%
  • Steps:64 (i.e. bits 7-2 of iPWM are used, 2LSB are ignored)
  • Duty cycle = (iPWM & 0xFC)/256

    Operating in blink mode (LEDx output state control = PCA9632_LEDOUT_LED_GRPPWM, Bit PCA9632_MODE2_DMBLNK of Mode 2 = 1 )
  • Frequeny: 1.5625 kHz
  • Duty cycle: 0% - 99.6%
  • Steps:256 (i.e. all 8 bits of iPWM are used)
  • Duty cycle = iPWM/256
    PCA9632_SetGroupPwm(hCfg[TPCA9632_Config], iPwm)

    Sets the group duty cycle control register of the PCA9632.

    The group duty cycle control register is used to provide a global brightness control or a global blinking control for the LEDs.

    hCfg : TPCA9632_Config - Device handle of a specific PCA9632 (Initialized by PCA9632_Init() )
    iPWM : u8 - The PWM value that should be written to the group duty cycle control register.
    returns : s32
    OK - if successful
    < OK - if an error occurs

    Operating in group dimming mode (LEDx output state control = PCA9632_LEDOUT_LED_GRPPWM, Bit PCA9632_MODE2_DMBLNK of Mode 2 = 0 )
  • Frequeny: 190 Hz superimposed with 6.25 kHz Individual brightness control signal
  • Duty cycle: 0% - 93.75%
  • Steps:16 (i.e. bits 7-4 of iPWM are used, 4LSB are ignored)
  • Duty cycle = (iPWM & 0xF0)/256

    Operating in fast blink mode (LEDx output state control = PCA9632_LEDOUT_LED_GRPPWM, Bit PCA9632_MODE2_DMBLNK of Mode 2 = 1, PCA9632_REG_GRPFREQ = 24Hz to 6Hz)
  • Frequeny: 24Hz to 6Hz (Value of PCA9632_REG_GRPFREQ register)
  • Duty cycle: 0% - 98.4%
  • Steps:64 (i.e. bits 7-2 of iPWM are used, 2LSB are ignored)
  • Duty cycle = (iPWM & 0xFC)/256

    Operating in slow blink mode (LEDx output state control = PCA9632_LEDOUT_LED_GRPPWM, Bit PCA9632_MODE2_DMBLNK of Mode 2 = 1, PCA9632_REG_GRPFREQ = 6Hz to 0.09Hz)
  • Frequeny: 6Hz to 0.09Hz (Value of PCA9632_REG_GRPFREQ register)
  • Duty cycle: 0% - 99.6%
  • Steps:256 (i.e. all bits of iPWM are used)
  • Duty cycle = iPWM/256
    PCA9632_SetGroupFrequency(hCfg[TPCA9632_Config], iFrequency)

    Sets the group frequency register of the PCA9632.

    Value in the group frequency register is a ‘don’t care’ when PCA9632_MODE2_DMBLNK of mode 2 register = 0

    hCfg : TPCA9632_Config - Device handle of a specific PCA9632 (Initialized by PCA9632_Init() )
    iFrequency : u8 - Blinking period that should be written to the group frequency register.
    Global blinking period [in seconds] = (iFrequency +1)/24
    returns : s32
    OK - if successful
    < OK - if an error occurs

    EXPERT

    PCA9632_CLOCK_MAX -

    absolute maximum I2C clock speed (1MHz, I2C Fast-Mode Plus)

    TPCA9632_I2C_ADR_x:

    I2C bus addresses that provide special functionality

    Using these I2C bus addresses may interfere with other devices.
    PCA9632_I2C_ADR_SWRST - Allows the device to be reset through the I2C-bus
    PCA9632_I2C_ADR_LED_ALL - Allows all the PCA9632s on the bus to be programmed at the same time (ALLCALL_ON bit in register TPCA9632_MODE1 must be 1). The register address can be programmed (see TPCA9632_REG).
    PCA9632_I2C_ADR_LED_SUBADR1 - Allows a group of PCA9632s (devices with the same subaddress) on the bus to be programmed at the same time (SUBADRx_ON bit in register TPCA9632_MODE1 must be 1). The subaddresses 1-3 can be programmed (see TPCA9632_REG).
    PCA9632_I2C_ADR_LED_SUBADR2 - see PCA9632_I2C_ADR_LED_SUBADR1
    PCA9632_I2C_ADR_LED_SUBADR3 - see PCA9632_I2C_ADR_LED_SUBADR1
    TPCA9632_REG_x:

    Available I2C registers of the PCA9632 (Address | Default | Description)

    PCA9632_REG_MODE1 - 0x00 | 0x91 |
    Mode register 1 (use PCA9632_SetMode1() and PCA9632_GetMode1())
    PCA9632_REG_MODE2 - 0x01 | 0x01 |
    Mode register 2 (use PCA9632_SetMode2() and PCA9632_GetMode2())
    PCA9632_REG_PWM0 - 0x02 | 0x00 |
    Individual brightness control LED0 (use PCA9632_SetPwm() )
    PCA9632_REG_PWM1 - 0x03 | 0x00 |
    Individual brightness control LED1 (use PCA9632_SetPwm() )
    PCA9632_REG_PWM2 - 0x04 | 0x00 |
    Individual brightness control LED2 (use PCA9632_SetPwm() )
    PCA9632_REG_PWM3 - 0x05 | 0x00 |
    Individual brightness control LED3 (use PCA9632_SetPwm() )
    PCA9632_REG_GRPPWM - 0x06 | 0xFF |
    Group duty cycle control (use PCA9632_SetGroupPwm())
    PCA9632_REG_GRPFREQ - 0x07 | 0x00 |
    Group frequency (PCA9632_SetGroupFrequency() )
    PCA9632_REG_LEDOUT - 0x08 | 0x00 |
    LED driver output state (use PCA9632_SetLedOut() or PCA9632_SetLedOutAll())
    PCA9632_REG_SUBADR1 - 0x09 | 0xE2 |
    I2C-bus subaddress 1 (use PCA9632_Write() and PCA9632_Read())
    PCA9632_REG_SUBADR2 - 0x0A | 0xE4 |
    I2C-bus subaddress 2 (use PCA9632_Write() and PCA9632_Read())
    PCA9632_REG_SUBADR3 - 0x0B | 0xE8 |
    I2C-bus subaddress 3 (use PCA9632_Write() and PCA9632_Read())
    PCA9632_REG_ALLCALLADR - 0x0C | 0xE0 |
    LED All Call I2C-bus address (use PCA9632_Write() and PCA9632_Read())

    For more information, see the NXP PCA9632 Product data sheet
    PCA9632_Read(hCfg[TPCA9632_Config], iReg, &iValue)

    Reads the contents of a register from the PCA9632


    hCfg : TPCA9632_Config - Device handle of a specific PCA9632 (Initialized by PCA9632_Init() )
    iReg : TPCA9632_REG_x - Register address
    iValue : u8 - Variable for storing the read contents of the register, unchanged if result < OK
    returns : s32
    OK - if successful
    < OK - if an error occurs
    PCA9632_Write(hCfg[TPCA9632_Config], iReg, iValue)

    Writes the transferred data into the desired register of the PCA9632


    hCfg : TPCA9632_Config - Device handle of a specific PCA9632 (Initialized by PCA9632_Init() )
    iReg : TPCA9632_REG_x - Register address
    iValue : u8 - The value that should be written to the register.
    returns : s32
    OK - if successful
    < OK - if an error occurs
    PCA9632_SoftReset(hCfg[TPCA9632_Config])

    Performs a reset of the PCA9632 using the "Software Reset Call" command through the I2C-bus, identical to the Power-On Reset (POR) that initializes the registers to their default state causing the outputs to be set high-impedance.

    In order to be executed correctly, I2C-Bus must be functional
    All devices on the same I2C bus that support the "Software Reset Call" will perform a reset.
    hCfg : TPCA9632_Config - Device handle of a specific PCA9632 (Initialized by PCA9685_Init())
    returns : s32
    OK - If successful
    ERROR - If an error occurs

    DEBUG

    PCA9632_Debug_Config:
    To configure debug mode add the following macro to the main.dde file.
    /** * Use this macro to configure the debug mode: * * 0: No debugging * 1: Issues the following information via the console: * -) When initializing: I2C address used to access the PCA9632 * -) I2C address used, register address and content that was read from * the register when the function PCA9632_Read was called * -) I2C address used, register address and content that should be written to * the register when the function PCA9632_Write was called */ #define PCA9632_DEBUG 1

    On this page

    PCA9632 - 4-bit Fm+ I2C-bus low power LED driver