leddriver16 2.1.0.0
Main Page

LED Driver 16 click

‍LED Driver 16 Click is a compact add-on board that simplifies the control of multiple LEDs. This board features the PCA9745B, an SPI-configurable sixteen-channel constant current LED driver from NXP Semiconductors. Each LED output has an 8-bit resolution (256 steps) fixed-frequency individual PWM controller that operates at 31.25kHz with an adjustable duty cycle from 0 to 100% to allow the LED to be set to a specific brightness value. Powered through a selected mikroBUS™ power rail, either 3.3V or 5V, it provides a maximum output current of 57mA per channel and multiple built-in protection functions that protect the circuit during abnormalities.

click Product page


Click library

  • Author : Stefan Filipovic
  • Date : Feb 2023.
  • Type : SPI type

Software Support

We provide a library for the LED Driver 16 Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.

Package can be downloaded/installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Library Description

‍This library contains API for LED Driver 16 Click driver.

Standard key functions :

Example key functions :

  • leddriver16_set_led_state This function sets the output state for the specified LEDs.
    err_t leddriver16_set_led_state ( leddriver16_t *ctx, uint16_t led_ch_mask, uint8_t state );
    err_t leddriver16_set_led_state(leddriver16_t *ctx, uint16_t led_ch_mask, uint8_t state)
    LED Driver 16 set led state function.
  • leddriver16_set_led_pwm This function sets the PWM duty cycle for the specified LEDs.
    err_t leddriver16_set_led_pwm ( leddriver16_t *ctx, uint16_t led_ch_mask, uint8_t duty_cycle );
    err_t leddriver16_set_led_pwm(leddriver16_t *ctx, uint16_t led_ch_mask, uint8_t duty_cycle)
    LED Driver 16 set led pwm function.
  • leddriver16_set_led_iref This function sets the gain settings for output current for the specified LEDs.
    err_t leddriver16_set_led_iref ( leddriver16_t *ctx, uint16_t led_ch_mask, uint8_t iref );
    err_t leddriver16_set_led_iref(leddriver16_t *ctx, uint16_t led_ch_mask, uint8_t iref)
    LED Driver 16 set led iref function.

Example Description

‍This example demonstrates the use of LED Driver 16 click board by performing 3 different types of LED control (LED PWM dimming, LED blinking, and LED curtain).

The demo application is composed of two sections :

Application Init

‍Initializes the driver and performs the click default configuration.

void application_init ( void )
{
log_cfg_t log_cfg;
leddriver16_cfg_t leddriver16_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
leddriver16_cfg_setup( &leddriver16_cfg );
LEDDRIVER16_MAP_MIKROBUS( leddriver16_cfg, MIKROBUS_1 );
if ( SPI_MASTER_ERROR == leddriver16_init( &leddriver16, &leddriver16_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( LEDDRIVER16_ERROR == leddriver16_default_cfg ( &leddriver16 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
#define LEDDRIVER16_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition leddriver16.h:251
@ LEDDRIVER16_ERROR
Definition leddriver16.h:309
void application_init(void)
Definition main.c:37

Application Task

‍Performs 3 different types of LED control examples. Each example repeats 5 times before

switching to another. The name of the currently set example will be displayed on the USB UART accordingly.

  • Example 1: LED PWM dimming - starts with min PWM duty cycle and increases it to max, then decreases it to min duty cycle in a loop with a 5ms delay on duty change.
  • Example 2: LED blinking - toggles all LEDs state from ON to OFF and vice-versa with a 500ms delay in between.
  • Example 3: LED curtain - turns ON the LEDs one by one from LED0 to LED15 with a 100ms delay on transition to the next LED.
void application_task ( void )
{
static uint8_t example_repeat_num = 5;
uint8_t repeat_cnt = 0;
log_printf( &logger, " LED PWM dimming\r\n\n" );
while ( repeat_cnt < example_repeat_num )
{
uint8_t pwm_duty = LEDDRIVER16_PWM_DUTY_MIN;
while ( pwm_duty < LEDDRIVER16_PWM_DUTY_MAX )
{
Delay_ms ( 5 );
pwm_duty++;
}
while ( pwm_duty > LEDDRIVER16_PWM_DUTY_MIN )
{
Delay_ms ( 5 );
pwm_duty--;
}
Delay_ms ( 100 );
repeat_cnt++;
}
log_printf( &logger, " LED blinking\r\n\n" );
repeat_cnt = 0;
while ( repeat_cnt < example_repeat_num )
{
Delay_ms ( 500 );
Delay_ms ( 500 );
repeat_cnt++;
}
log_printf( &logger, " LED curtain\r\n\n" );
repeat_cnt = 0;
while ( repeat_cnt < example_repeat_num )
{
uint8_t led_cnt = 0;
while ( led_cnt < 16 )
{
Delay_ms ( 100 );
led_cnt++;
}
Delay_ms ( 500 );
repeat_cnt++;
}
}
#define LEDDRIVER16_LEDOUT_PWM_ALL
Definition leddriver16.h:180
#define LEDDRIVER16_PWM_DUTY_MAX
Definition leddriver16.h:189
#define LEDDRIVER16_LED_CHANNEL_ALL
Definition leddriver16.h:222
#define LEDDRIVER16_LEDOUT_OFF
LED Driver 16 LEDOUTx register setting.
Definition leddriver16.h:178
#define LEDDRIVER16_LEDOUT_ON
Definition leddriver16.h:179
#define LEDDRIVER16_LED_CHANNEL_0
LED Driver 16 LED channel setting.
Definition leddriver16.h:202
#define LEDDRIVER16_PWM_DUTY_MIN
LED Driver 16 PWMx register setting.
Definition leddriver16.h:188
void application_task(void)
Definition main.c:73

The full application code, and ready to use projects can be installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Other Mikroe Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.LEDDriver16

Additional notes and informations

Depending on the development board you are using, you may need USB UART click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. UART terminal is available in all MikroElektronika compilers.