Intermediate
30 min
0

Experience synchronized lighting effects with ALI782 and PIC18LF47K42

Smart lighting evolution starts here

Light Temp Click with EasyPIC v8

Published Sep 05, 2023

Click board™

Light Temp Click

Development board

EasyPIC v8

Compiler

NECTO Studio

MCU

PIC18LF47K42

Our dual-channel LED driver empowers SCL applications with independent control over two lighting channels, enabling dynamic color tuning and personalized lighting experiences

A

A

Hardware Overview

How does it work?

Light Temp Click is based on the AL1782, a dual-channel PWM dimmable linear LED driver by Diodes Incorporated. It is a constant-current driver, which can sink up to 1500mA combined or up to 750mA per channel. It has two low-side current sinks, which allow LED strips or LED bulbs to be connected in the common-anode topology for increased effectiveness and power optimization. Note that the constant current on this Click board™ is 750mA per channel. The AL1782 IC can be operated with a PWM signal in the frequency range from 1kHz to 40kHz. Applying the PWM signal with a duty cycle of less than 4ms makes it possible to tune the light intensity of the connected LED light element. A LOW pulse width of more than 4ms will set the device into the low-power mode (suspend). The lowest light intensity that can be reached by applying the PWM frequency of 1kHz is 0.1%, while 40kHz allows the lowest brightness level of 4% of the full light intensity. A High PWM frequency allows for less visible flickering but simultaneously limits the lowest light intensity level. PWM1 and PWM2 pins of the AL1782 are routed to the mikroBUS™ PWM and CS pins and are labeled as PW1 and PW2. Adaptive Thermal Management (ATM) scheme is one of the key features of the AL1782. It can be used to optimize the power consumption by

adjusting the voltage of the external power supply unit (PSU): the excessive voltage applied to the connected LED will be dissipated as heat within the AL1782. Therefore, the voltage level of the external PSU should be kept above the forward voltage of the connected LED plus minimum voltage headroom (VF + VLED_REG). The ATM injects current through the LEDPG pin of the AL1782. This current is converted to a voltage level, and it is sampled by the MCP3221, a low-power 12-bit A/D converter with an I2C interface, by Microchip. It has its I2C pins routed to the respective mikroBUS™ I2C pins, allowing the host MCU to read the LEDPG voltage and adjust the PSU voltage. Please note that if an external PSU with no external regulation is used, its voltage should stay within the mentioned range (VF of the connected LED element + VLEDx_REG as per AL1782 datasheet). However, the voltage should always stay below 30V. The AL1782 IC also integrates many protection features for increased reliability: undervoltage, open or short circuit at the output, and thermal protection. If any of these protections become activated, a fault event will be reported on a dedicated pin labeled FAULTB. This pin is routed to the mikroBUS™ INT pin and is asserted to a LOW logic level when a fault event occurs. Deep Dimming Capability helps with

power efficiency. Subjective perception of the light intensity differs from the measured light. For example, the light intensity of 10% (with respect to the applied duty cycle) is perceived as 32% of the full light intensity. Deep Dimming Capability helps with energy saving, providing an optimal light output. Deep Dimming down to 0.1% is possible with the AL1782 IC since it can be operated with a pulse width as low as one µS while still providing good linearity. Light Temp click is designed to use an external PSU and an MCU. The full potential of the Light Temp click is achieved when combined with a dedicated light temperature and color sensing Click board™ such as Spectral click. By receiving information about the ambient light color temperature and white balance from the Spectral click, the MCU can generate a PWM signal concerning the required CCT tuning and send it to the Light Temp click to regulate the ambient lighting color. This Click board™ can be operated only with a 3.3V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. Also, it comes equipped with a library containing functions and an example code that can be used as a reference for further development.

Light Temp Click hardware overview image

Features overview

Development board

EasyPIC v8 is a development board specially designed for the needs of rapid development of embedded applications. It supports many high pin count 8-bit PIC microcontrollers from Microchip, regardless of their number of pins, and a broad set of unique functions, such as the first-ever embedded debugger/programmer. The development board is well organized and designed so that the end-user has all the necessary elements, such as switches, buttons, indicators, connectors, and others, in one place. Thanks to innovative manufacturing technology, EasyPIC v8 provides a fluid and immersive working experience, allowing access anywhere and under any

circumstances at any time. Each part of the EasyPIC v8 development board contains the components necessary for the most efficient operation of the same board. In addition to the advanced integrated CODEGRIP programmer/debugger module, which offers many valuable programming/debugging options and seamless integration with the Mikroe software environment, the board also includes a clean and regulated power supply module for the development board. It can use a wide range of external power sources, including a battery, an external 12V power supply, and a power source via the USB Type-C (USB-C) connector.

Communication options such as USB-UART, USB DEVICE, and CAN are also included, including the well-established mikroBUS™ standard, two display options (graphical and character-based LCD), and several different DIP sockets. These sockets cover a wide range of 8-bit PIC MCUs, from the smallest PIC MCU devices with only eight up to forty pins. EasyPIC v8 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.

EasyPIC v8 horizontal image

Microcontroller Overview

MCU Card / MCU

PIC18LF47K42

Architecture

PIC

MCU Memory (KB)

128

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

8192

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
NC
NC
RST
PWM Input 2
RE0
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
PWM Input 1
RC0
PWM
Fault Indicator
RB0
INT
NC
NC
TX
NC
NC
RX
I2C Clock
RC3
SCL
I2C Data
RC4
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Schematic

Light Temp Click Schematic schematic

Step by step

Project assembly

EasyPIC v8 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the EasyPIC v8 as your development board.

EasyPIC v8 front image hardware assembly
GNSS2 Click front image hardware assembly
MCU DIP 40 hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
EasyPIC v8 Access DIPMB 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
Necto image step 8 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

After pressing the "FLASH" button on the left-side panel, it is necessary to open the UART terminal to display the achieved results. By clicking on the Tools icon in the right-hand panel, multiple different functions are displayed, among which is the UART Terminal. Click on the offered "UART Terminal" icon.

UART Application Output Step 1

Once the UART terminal is opened, the window takes on a new form. At the top of the tab are two buttons, one for adjusting the parameters of the UART terminal and the other for connecting the UART terminal. The tab's lower part is reserved for displaying the achieved results. Before connecting, the terminal has a Disconnected status, indicating that the terminal is not yet active. Before connecting, it is necessary to check the set parameters of the UART terminal. Click on the "OPTIONS" button.

UART Application Output Step 2

In the newly opened UART Terminal Options field, we check if the terminal settings are correct, such as the set port and the Baud rate of UART communication. If the data is not displayed properly, it is possible that the Baud rate value is not set correctly and needs to be adjusted to 115200. If all the parameters are set correctly, click on "CONFIGURE".

UART Application Output Step 3

The next step is to click on the "CONNECT" button, after which the terminal status changes from Disconnected to Connected in green, and the data is displayed in the Received data field.

UART Application Output Step 4

Software Support

Library Description

This library contains API for Light Temp Click driver.

Key functions:

  • lighttemp_get_interrupt_state - Get INT pin state

  • lighttemp_get_pg_voltage - Get voltage

  • lighttemp_cs_set_state

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 
 * @brief LightTemp Click example
 * 
 * # Description
 * This application controls light intensity of LEDs.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initialization driver init and pwm init for all LED's
 * 
 * ## Application Task  
 * This is an example that demonstrates the use of the Light Temp Click board.
 * This example shows the automatic control of the LED 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.
 * 
 * ## NOTE
 * In order to control LED2 via PWM, the PWM module should be available at CS pin. 
 * 
 * @author Nikola Peric
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "lighttemp.h"

// ------------------------------------------------------------------ VARIABLES

static lighttemp_t lighttemp;
static log_t logger;

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    lighttemp_cfg_t cfg;

    /** 
     * 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 ----" );
    Delay_ms( 100 );
    
    //  Click initialization.

    lighttemp_cfg_setup( &cfg );
    LIGHTTEMP_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    lighttemp_init( &lighttemp, &cfg );
    
    lighttemp_led1_set_duty_cycle ( &lighttemp, 0.0 );
    lighttemp_led2_set_duty_cycle ( &lighttemp, 0.0 );
    
    log_info( &logger, "---- Application Task ----" );

    Delay_ms( 500 );
}

void application_task ( void )
{
    static int8_t duty_cnt = 1;
    static int8_t duty_inc = 1;
    float duty = duty_cnt / 10.0;

    lighttemp_led1_set_duty_cycle ( &lighttemp, duty );
    lighttemp_led2_set_duty_cycle ( &lighttemp, duty );
    
    lighttemp_led1_pwm_start( &lighttemp );
    lighttemp_led2_pwm_start( &lighttemp );

    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 main ( void )
{
    application_init( );

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

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

Additional Support

Resources