leddriver2 2.0.0.0
Main Page

LED Driver 2 click

LED driver 2 click carries the MCP1643 - LED constant current regulator, made by Microchip. It is a compact, high-efficiency, fixed frequency, synchronous step-up converter, optimized to drive one LED with the constant current.

click Product page


Click library

  • Author : Nikola Peric
  • Date : Feb 2022.
  • Type : PWM type

Software Support

We provide a library for the LedDriver2 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 form compilers IDE(recommended way), or downloaded from our LibStock, or found on mikroE github account.

Library Description

‍This library contains API for LedDriver2 Click driver.

Standard key functions :

Example key functions :

  • This function sets the PWM duty cycle

    ‍void leddriver2_set_duty_cycle ( leddriver2_t *ctx, pwm_data_t duty_cycle );

    - This function stops PWM module.

    ‍void leddriver2_pwm_stop ( leddriver2_t *ctx );

  • This function starts PWM module.

    ‍void leddriver2_pwm_start ( leddriver2_t *ctx );

    Examples Description

‍This app enables usage of compact, high-efficiency, fixed frequency, synchronous step-up converter, optimized to drive one LED with the constant current.

The demo application is composed of two sections :

Application Init

‍Initialization driver enables - GPIO, PWM initialization set PWM duty cycle and start PWM.

void application_init ( void )
{
log_cfg_t log_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, "---- Application Init ----" );
// Click initialization.
LEDDRIVER2_MAP_MIKROBUS( cfg, MIKROBUS_1 );
leddriver2_init( &leddriver2, &cfg );
leddriver2_pwm_start( &leddriver2 );
}
#define LEDDRIVER2_MAP_MIKROBUS(cfg, mikrobus)
Definition leddriver2.h:66
void leddriver2_cfg_setup(leddriver2_cfg_t *cfg)
Config Object Initialization function.
void leddriver2_pwm_start(leddriver2_t *ctx)
Start PWM module.
LEDDRIVER2_RETVAL leddriver2_init(leddriver2_t *ctx, leddriver2_cfg_t *cfg)
Initialization function.
void application_init(void)
Definition main.c:37
Click configuration structure definition.
Definition leddriver2.h:114

Application Task

‍This is an example that demonstrates the use of the LED Driver 2 Click board. This example shows the automatic control halogen bulb light intensity, the first intensity of light is rising and then the intensity of light is falling. Results are being sent to the Usart Terminal where you can track their changes.

void application_task ( void )
{
static int8_t duty_cnt = 1;
static int8_t duty_inc = 1;
float duty = duty_cnt / 10.0;
leddriver2_set_duty_cycle ( &leddriver2, duty );
log_printf( &logger, "> Duty: %d%%\r\n", ( uint16_t )( duty_cnt * 10 ) );
Delay_ms ( 500 );
if ( 10 == duty_cnt )
{
duty_inc = -1;
}
else if ( 0 == duty_cnt )
{
duty_inc = 1;
}
duty_cnt += duty_inc;
}
void leddriver2_set_duty_cycle(leddriver2_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
void application_task(void)
Definition main.c:64

The full application code, and ready to use projects can be installed directly form compilers IDE(recommneded) or found on LibStock page or mikroE GitHub accaunt.

Other mikroE Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.LedDriver2

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. The terminal available in all Mikroelektronika compilers, or any other terminal application of your choice, can be used to read the message.