中级
30 分钟

使用TLC5947和PIC18F27K42实现惊艳的色彩混合

点亮您的生活,照亮您的世界

LED Driver 18 Click with EasyPIC v8

已发布 6月 25, 2024

点击板

LED Driver 18 Click

开发板

EasyPIC v8

编译器

NECTO Studio

微控制器单元

PIC18F27K42

相信我们可靠且创新的 LED 驱动解决方案,它能为您的照明项目注入活力,为您的所有 LED 照明需求提供无与伦比的性能和效率。

A

A

硬件概览

它是如何工作的?

LED Driver 18 Click 基于 TLC5947,这是来自德州仪器的 24 通道 12 位 PWM LED 驱动器。每个通道支持多个串联连接到 LED 端子的 LED,并通过串行接口端口具有可单独调节的 4096 步 PWM 灰度亮度控制。所有 24 个通道的可编程电流值通过 AD5171(一种 I2C 可配置的数字电位器)实现,每个通道的最大 LED 电流为 30mA。TLC5947 还具有内置的热关断功能,在过温条件下关闭所有输出驱动

器。当温度恢复正常时,所有通道自动重新启动。LED Driver 18 Click 通过寄存器可选择的标准 SPI 接口与 MCU 通信,支持高达 30MHz 的高时钟速度以获得最佳性能。除了接口信号外,TLC5947 还使用 mikroBUS™ 插座的另一个信号。路由到 mikroBUS™ 插座的 EN 引脚的使能信号提供关闭所有恒流输出的能力。当 EN 引脚处于高电平状态时,所有通道(0-23)被强制关闭,灰度 PWM 计时控

制器初始化,灰度计数器复位为 0。当 EN 引脚处于低电平状态时,灰度 PWM 计时控制器控制所有 LED 通道。此 Click board™ 可以在 3.3V 或 5V 逻辑电压水平下运行,通过 VCC SEL 跳线选择。这样,3.3V 和 5V 的 MCU 都可以正确使用通信线路。此外,该 Click board™ 配备了包含易于使用的函数和示例代码的库,可作为进一步开发的参考。

LED Driver 18 Click top side image
LED Driver 18 Click bottom side image

功能概述

开发板

EasyPIC v8 是一款专为快速开发嵌入式应用的需求而特别设计的开发板。它支持许多高引脚计数的8位PIC微控制器,来自Microchip,无论它们的引脚数量如何,并且具有一系列独特功能,例如首次集成的调试器/程序员。开发板布局合理,设计周到,使得最终用户可以在一个地方找到所有必要的元素,如开关、按钮、指示灯、连接器等。得益于创新的制造技术,EasyPIC v8 提供了流畅而沉浸式的工作体验,允许在任何情况下、任何地方、任何时候都能访问。

EasyPIC v8 开发板的每个部分都包含了使同一板块运行最高效的必要组件。除了先进的集成CODEGRIP程 序/调试模块,该模块提供许多有价值的编程/调试选项和与Mikroe软件环境的无缝集成外,该板还包括一个干净且调节过的开发板电源供应模块。它可以使用广泛的外部电源,包括电池、外部12V电源供应和通过USB Type-C(USB-C)连接器的电源。通信选项如USB-UART、USB DEVICE和CAN也包括在内,包括 广受好评的mikroBUS™标准、两种显示选项(图形和

基于字符的LCD)和几种不同的DIP插座。这些插座覆盖了从最小的只有八个至四十个引脚的8位PIC MCU的广泛范围。EasyPIC v8 是Mikroe快速开发生态系统的一个组成部分。它由Mikroe软件工具原生支持,得益于大量不同的Click板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作和开发的许多方面。

EasyPIC v8 horizontal image

微控制器概述 

MCU卡片 / MCU

default

建筑

PIC

MCU 内存 (KB)

128

硅供应商

Microchip

引脚数

28

RAM (字节)

8192

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
NC
NC
RST
SPI Chip Select
RA5
CS
SPI Clock
RC3
SCK
SPI Data OUT
RC4
MISO
SPI Data IN
RC5
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Channels Enable
RC1
PWM
NC
NC
INT
NC
NC
TX
NC
NC
RX
I2C Clock
RC3
SCL
I2C Data
RC4
SDA
Power Supply
5V
5V
Ground
GND
GND
2

“仔细看看!”

Click board™ 原理图

LED Driver 18 Click Schematic schematic

一步一步来

项目组装

EasyPIC v8 front image hardware assembly

从选择您的开发板和Click板™开始。以EasyPIC v8作为您的开发板开始。

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

实时跟踪您的结果

应用程序输出

此款Click板可通过两种方式进行接口连接和监控:

  • Application Output - 在调试模式下,使用“Application Output”窗口进行实时数据监控。按照本教程正确设置它。

软件支持

库描述

该库包含 LED Driver 18 Click 驱动程序的 API。

关键功能:

  • leddriver18_set_output_pwm - LED Driver 18 设置输出通道 PWM 值功能

  • leddriver18_write_config - LED Driver 18 写入配置功能

  • leddriver18_set_cc_output - LED Driver 18 设置恒流输出功能

开源

代码示例

完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio 应用程序代码也可以在MIKROE的GitHub账户中找到。

/*!
 * @file main.c
 * @brief LED Driver 18 Click example
 *
 * # Description
 * This library contains API for LED Driver 18 Click driver. 
 * The library initializes and defines the I2C bus drivers to 
 * write and read data for setting constant current output, 
 * as well as the default configuration for a PWM output value 
 * of the OUT pins.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs default configuration and sets 
 * the device in output enabled mode.
 *
 * ## Application Task
 * This example demonstrates the use of the LED Driver 18 Click board by 
 * changing PWM values for all output from a minimum value to 
 * maximum value and back to minimum controlling the brightness of the 
 * LEDs in the process.
 *
 * @author Stefan Ilic
 *
 */

#include "board.h"
#include "log.h"
#include "leddriver18.h"

static leddriver18_t leddriver18;
static log_t logger;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    leddriver18_cfg_t leddriver18_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.
    leddriver18_cfg_setup( &leddriver18_cfg );
    LEDDRIVER18_MAP_MIKROBUS( leddriver18_cfg, MIKROBUS_1 );
    if ( I2C_MASTER_ERROR == leddriver18_init( &leddriver18, &leddriver18_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( LEDDRIVER18_ERROR == leddriver18_default_cfg ( &leddriver18 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    float pwm_val;

    for ( int8_t  n_cnt = 0; n_cnt <= 100; n_cnt += 10 )
    {
        for ( uint8_t out_cnt = 0; out_cnt < LEDDRIVER18_MAX_OUTPUT_NUM; out_cnt++ )
        {
            leddriver18_set_output_pwm( out_cnt, n_cnt );
        }
        pwm_val = leddriver18_get_output_pwm( 0 );
        log_printf( &logger, " PWM value: %.2f \r\n", pwm_val );
        leddriver18_write_config( &leddriver18 );
        Delay_ms( 200 );
    }
    for ( int8_t  n_cnt = 100; n_cnt >= 10; n_cnt -= 10 )
    {
        for ( uint8_t out_cnt = 0; out_cnt < LEDDRIVER18_MAX_OUTPUT_NUM; out_cnt++ )
        {
            leddriver18_set_output_pwm( out_cnt, n_cnt );
        }
        pwm_val = leddriver18_get_output_pwm( 0 );
        log_printf( &logger, " PWM value: %.2f \r\n", pwm_val );
        leddriver18_write_config( &leddriver18 );
        Delay_ms( 200 );
    }
}

void main ( void ) 
{
    application_init( );

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

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

额外支持

资源

喜欢这个项目吗?

'购买此套件' 按钮会直接带您进入购物车,您可以在购物车中轻松添加或移除产品。