Intermediate
30 min

Sync your LEDs easily with BD18337EFV-M and ATmega32

See the light, not the complexity!

LED Driver 14 Click with EasyAVR v7

Published Nov 01, 2023

Click board™

LED Driver 14 Click

Dev Board

EasyAVR v7

Compiler

NECTO Studio

MCU

ATmega32

With our LED driver solution, controlling multiple LEDs becomes as easy as flicking a switch, giving you the power to create captivating lighting environments effortlessly

A

A

Hardware Overview

How does it work?

LED Driver 14 Click is based on the BD18337EFV-M, a four-channel constant current LED driver with built-in MOSFET ideal for LED rear lamps (turn/stop), fog lamps, and turn signals for automotive use from Rohm Semiconductor. The BD18337EFV-M incorporates a proprietary thermal dissipation circuit, and individual LED control function to drive LED lamps with different specifications by one driver. This allows up to 3 LEDs in series on its output OUTx pin. It also has integrated protection circuitry to guard against output-short, overvoltage, LED short-circuit protections, and overtemperature. This Click board™ provides an output current of 150mA per channel with an output current accuracy of ±5%, limited by two MCP4661 digital potentiometers from Microchip Technology, which establishes communication with the MCU via I2C serial interface. The MCP4661 also allows the choice of the least significant bit (LSB) of its I2C slave address by positioning SMD jumpers labeled as ADDR SEL to an appropriate position marked as 1 and 0. The MCP4661 also has a configurable Write Protection function labeled as WP routed on the

RST pin of the mikroBUS™ socket, which protects the entire memory and all registers from write operations and must be set to a low logic state to inhibit all the write operations. The BD18337EFV-M offers two ways to implement LED dimming: analog and PWM. Both methods control the average current flowing through the LEDs. The analog dimming can be achieved by adjusting the LED current by using an external voltage source on the VIN terminal, while the PWM dimming is implemented by direct control of the dimming control signal routed to the PWM pin on the mikroBUS™ socket. The selection can be made by positioning the SMD jumper labeled CRT SEL to an appropriate position marked as PWM or VIN. This board also has a two-channel switch labeled MSET, which allows changing output channel operation mode based on detecting an LED error. It also uses the INT pin of the mikroBUS™ socket in two ways: a 'fault' indicator, which immediately notifies the host when a fault condition occurs, or as an input that turns off the output current. The output channel operation mode is automatically selected according to a switch position. More information

about these selectable modes can be found in the attached datasheet. This Click board™ supports an external power supply for the motor, which can be connected to the input terminal labeled as VIN and should be within the range of 5.5V to 20V (typically about 12V). This wide range can lead to significant device power consumption in applications where a high input voltage is applied to the device and the output is relatively low. This amount of power can increase the BD18337EFV-M internal temperature to an unacceptable level, depending on the package's thermal resistance. The BD18337EFV-M employs an Energy Sharing Control to solve this issue, dissipating the extra power that can overheat the device in external resistors R2 and R3 (R3 is unpopulated by default configuration). This Click board™ can operate with either 3.3V or 5V logic voltage levels selected via the VCC SEL jumper. This way, both 3.3V and 5V capable MCUs can use the communication lines properly. Also, this Click board™ comes equipped with a library containing easy-to-use functions and an example code that can be used as a reference for further development.

LED Driver 14 Click hardware overview image

Features overview

Development board

EasyAVR v7 is the seventh generation of AVR development boards specially designed for the needs of rapid development of embedded applications. It supports a wide range of 16-bit AVR microcontrollers from Microchip and has a broad set of unique functions, such as a powerful onboard mikroProg programmer and In-Circuit debugger over USB. The development board is well organized and designed so that the end-user has all the necessary elements in one place, such as switches, buttons, indicators, connectors, and others. With four different connectors for each port, EasyAVR v7 allows you to connect accessory boards, sensors, and custom electronics more

efficiently than ever. Each part of the EasyAVR v7 development board contains the components necessary for the most efficient operation of the same board. An integrated mikroProg, a fast USB 2.0 programmer with mikroICD hardware In-Circuit Debugger, offers many valuable programming/debugging options and seamless integration with the Mikroe software environment. Besides it also includes a clean and regulated power supply block for the development board. It can use a wide range of external power sources, including an external 12V power supply, 7-12V AC or 9-15V DC via DC connector/screw terminals, and a power source via the USB Type-B (USB-B)

connector. Communication options such as USB-UART and RS-232 are also included, alongside the well-established mikroBUS™ standard, three display options (7-segment, graphical, and character-based LCD), and several different DIP sockets which cover a wide range of 16-bit AVR MCUs. EasyAVR v7 is an integral part of the Mikroe ecosystem for rapid development. Natively supported by Mikroe software tools, it covers many aspects of prototyping and development thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

EasyAVR v7 horizontal image

Microcontroller Overview

MCU Card / MCU

default

Architecture

AVR

MCU Memory (KB)

32

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

2048

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
DIGIPOT Write Protect
PA6
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
PWM Signal
PD4
PWM
Interrupt
PD2
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PC0
SCL
I2C Data
PC1
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Schematic

LED Driver 14 Click Schematic schematic

Step by step

Project assembly

EasyAVR v7 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the EasyAVR v7 as your development board.

EasyAVR v7 front image hardware assembly
GNSS2 Click front image hardware assembly
MCU DIP 40 hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
EasyAVR v7 Access DIP MB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
NECTO Compiler Selection Step Image hardware assembly
NECTO Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
Necto DIP image step 7 hardware assembly
EasyPIC PRO v7a Display Selection Necto Step hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image hardware assembly

Track your results in real time

Application Output via UART Mode

1. Once the code example is loaded, pressing the "FLASH" button initiates the build process, and programs it on the created setup.

2. After the programming is completed, click on the Tools icon in the upper-right panel, and select the UART Terminal.

3. After opening the UART Terminal tab, first check the baud rate setting in the Options menu (default is 115200). If this parameter is correct, activate the terminal by clicking the "CONNECT" button.

4. Now terminal status changes from Disconnected to Connected in green, and the data is displayed in the Received data field.

UART_Application_Output

Software Support

Library Description

This library contains API for LED Driver 14 Click driver.

Key functions:

  • leddriver14_set_rset - This function sets the resistance of the selected rset channel

  • leddriver14_get_int_pin - This function returns the int pin logic state

  • leddriver14_set_duty_cycle - This function sets the PWM duty cycle in percentages ( Range[ 0..1 ] )

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * @file main.c
 * @brief LEDDriver14 Click example
 *
 * # Description
 * This example demonstrates the use of LED Driver 14 click board by controlling
 * the brightness of LEDs by changing the PWM Duty Cycle.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the click default configuration.
 *
 * ## Application Task
 * Adjusts the LEDs' brightness by changing the PWM duty cycle every 500ms.
 * A duty cycle value is being displayed on the USB UART.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "leddriver14.h"

static leddriver14_t leddriver14;
static log_t logger;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    leddriver14_cfg_t leddriver14_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.
    leddriver14_cfg_setup( &leddriver14_cfg );
    LEDDRIVER14_MAP_MIKROBUS( leddriver14_cfg, MIKROBUS_1 );
    err_t init_flag = leddriver14_init( &leddriver14, &leddriver14_cfg );
    if ( ( I2C_MASTER_ERROR == init_flag ) || ( PWM_ERROR == init_flag ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( LEDDRIVER14_ERROR == leddriver14_default_cfg ( &leddriver14 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    static int8_t duty_cnt = 1;
    static int8_t duty_inc = 1;
    float duty = duty_cnt / 10.0;
    
    leddriver14_set_duty_cycle ( &leddriver14, duty );
    log_printf( &logger, "> Duty: %d%%\r\n", ( uint16_t )( duty_cnt * 10 ) );
    
    if ( 10 == duty_cnt ) 
    {
        duty_inc = -1;
    }
    else if ( 0 == duty_cnt ) 
    {
        duty_inc = 1;
    }
    duty_cnt += duty_inc;
    
    if ( !leddriver14_get_int_pin ( &leddriver14 ) )
    {
        log_info ( &logger, " Abnormality such as LED Open or the OUTx pin short circuit occured " );
    }
    
    Delay_ms( 500 );
}

void main ( void ) 
{
    application_init( );

    for ( ; ; ) 
    {
        application_task( );
    }
}

// ------------------------------------------------------------------------ END

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.