中级
30 分钟

使用PCA9745B和PIC32MZ1024EFH064实现您的创意愿景

打造多彩时刻:简化RGBA LED控制!

LED Driver 16 Click with PIC32MZ clicker

已发布 6月 24, 2024

点击板

LED Driver 16 Click

开发板

PIC32MZ clicker

编译器

NECTO Studio

微控制器单元

PIC32MZ1024EFH064

我们的尖端 LED 驱动解决方案简化了对 RGBA LED 的调光和闪烁控制,使您能够轻松创建动态灯光效果并定制您的氛围。

A

A

硬件概览

它是如何工作的?

LED Driver 16 Click 基于 PCA9745B,这是来自 NXP Semiconductors 的菊链 SPI 兼容 16 通道恒流 LED 驱动器。PCA9745B 每通道提供最大输出电流 57mA(通过板载 R6 电阻设置),适用于调光和闪烁红/绿/蓝/琥珀 (RGBA) LEDs。每个 16 个 LED 输出都有 8 位分辨率(256 步)的固定频率独立 PWM 控制器,工作频率为 31.25 kHz,具有可调占空比。占空比范围从 0% 到 100%,允许将 LED 设置为特定的亮度值;可以用相同的值调光或闪烁所有 LED。通过串行接口和 8 位 DAC 实现所有电流源的渐变控制,允许用户自动调整电流,无需 MCU 干预,从而调整每

个 LED 电流源的亮度等级。有四个可选择的渐变控制组,每个组有四个独立的寄存器来控制上升和下降速率、步时间、保持开/关时间和最终保持开启输出电流。每个组有两种渐变操作模式:单次模式(输出一次图案)和连续模式(重复输出图案)。LED Driver 16 Click 通过寄存器可选的标准 SPI 接口与 MCU 通信,支持最高 25MHz 的高时钟速度以获得最佳性能,支持最常见的 SPI 模式,SPI 模式 0。除了 SPI 接口信号外,此板还使用了 mikroBUS™ 插座的其他几个信号。复位引脚连接到 mikroBUS™ 插座的 RST 引脚,提供通用复位功能,而 mikroBUS™ 插

座的 OE 引脚则提供启用/禁用操作以打开/关闭对 PCA9745B 的电源供应。OE 引脚也可以用作外部调光控制信号。在这种情况下,外部时钟频率必须非常高,更确切地说是人眼无法察觉的,且占空比值决定了 LED 的亮度。此 Click board™ 可以在 3.3V 或 5V 逻辑电压水平下运行,通过 VCC SEL 跳线选择。这样,3.3V 和 5V 的 MCU 都可以正确使用通信线路。此外,该 Click board™ 配备了包含易于使用的函数和示例代码的库,可作为进一步开发的参考。

LED Driver 16 Click top side image
LED Driver 16 Click bottom side image

功能概述

开发板

PIC32MZ Clicker 是一款紧凑型入门开发板,它将 Click 板™的灵活性带给您喜爱的微控制器,使其成为实现您想法的完美入门套件。它配备了一款板载 32 位带有浮点单元的 Microchip PIC32MZ 微控制器,一个 USB 连接器,LED 指示灯,按钮,一个 mikroProg 连接器,以及一个用于与外部电子设备接口的头部。得益于其紧凑的设计和清晰易识别的丝网标记,它提供了流畅且沉浸式的工作体验,允许在任

何情况下、任何地方都能访问。PIC32MZ Clicker 开 发套件的每个部分都包含了使同一板块运行最高效的必要组件。除了可以选择 PIC32MZ Clicker 的编程方式,使用 USB HID mikroBootloader 或通过外部 mikroProg 连接器为 PIC,dsPIC 或 PIC32 编程外,Clicker 板还包括一个干净且调节过的开发套件电源供应模块。USB Micro-B 连接可以提供多达 500mA 的电流,这足以操作所有板载和附加模块。所有 

mikroBUS™ 本身支持的通信方法都在这块板上,包 括已经建立良好的 mikroBUS™ 插槽、重置按钮以及若干按钮和 LED 指示灯。PIC32MZ Clicker 是 Mikroe 生态系统的一个组成部分,允许您在几分钟内创建新的应用程序。它由 Mikroe 软件工具原生支持,得益于大量不同的 Click 板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作的许多方面。

PIC32MZ clicker double side image

微控制器概述 

MCU卡片 / MCU

default

建筑

PIC32

MCU 内存 (KB)

1024

硅供应商

Microchip

引脚数

64

RAM (字节)

524288

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
Reset
RE5
RST
SPI Chip Select
RG9
CS
SPI Clock
RG6
SCK
SPI Data OUT
RG7
MISO
SPI Data IN
RG8
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Output Enable
RB3
PWM
NC
NC
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

LED Driver 16 Click Schematic schematic

一步一步来

项目组装

PIC32MZ clicker front image hardware assembly

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

PIC32MZ clicker front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
Micro B Connector Clicker Access - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Flip&Click PIC32MZ MCU step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

实时跟踪您的结果

应用程序输出

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

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

软件支持

库描述

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

关键功能:

  • leddriver16_set_led_state - 此功能设置指定 LED 的输出状态

  • leddriver16_set_led_pwm - 此功能设置指定 LED 的 PWM 占空比

  • leddriver16_set_led_iref - 此功能设置指定 LED 输出电流的增益设置

开源

代码示例

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

/*!
 * @file main.c
 * @brief LED Driver 16 Click 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.
 *
 * ## 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.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "leddriver16.h"

static leddriver16_t leddriver16;
static log_t logger;

void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    leddriver16_cfg_t leddriver16_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.
    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 " );
}

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" );
    leddriver16_set_led_state ( &leddriver16, LEDDRIVER16_LED_CHANNEL_ALL, LEDDRIVER16_LEDOUT_PWM_ALL );
    while ( repeat_cnt < example_repeat_num )
    {
        uint8_t pwm_duty = LEDDRIVER16_PWM_DUTY_MIN;
        while ( pwm_duty < LEDDRIVER16_PWM_DUTY_MAX )
        {
            leddriver16_set_led_pwm ( &leddriver16, LEDDRIVER16_LED_CHANNEL_ALL, pwm_duty );
            Delay_ms ( 5 );
            pwm_duty++;
        }
        while ( pwm_duty > LEDDRIVER16_PWM_DUTY_MIN )
        {
            leddriver16_set_led_pwm ( &leddriver16, LEDDRIVER16_LED_CHANNEL_ALL, pwm_duty );
            Delay_ms ( 5 );
            pwm_duty--;
        }
        Delay_ms ( 100 );
        repeat_cnt++;
    }
    
    log_printf( &logger, " LED blinking\r\n\n" );
    repeat_cnt = 0;
    leddriver16_set_led_state ( &leddriver16, LEDDRIVER16_LED_CHANNEL_ALL, LEDDRIVER16_LEDOUT_OFF );
    while ( repeat_cnt < example_repeat_num )
    {
        leddriver16_set_led_state ( &leddriver16, LEDDRIVER16_LED_CHANNEL_ALL, LEDDRIVER16_LEDOUT_ON );
        Delay_ms ( 500 );
        leddriver16_set_led_state ( &leddriver16, LEDDRIVER16_LED_CHANNEL_ALL, LEDDRIVER16_LEDOUT_OFF );
        Delay_ms ( 500 );
        repeat_cnt++;
    }
    
    log_printf( &logger, " LED curtain\r\n\n" );
    repeat_cnt = 0;
    leddriver16_set_led_state ( &leddriver16, LEDDRIVER16_LED_CHANNEL_ALL, LEDDRIVER16_LEDOUT_OFF );
    while ( repeat_cnt < example_repeat_num )
    {
        uint8_t led_cnt = 0;
        while ( led_cnt < 16 )
        {
            leddriver16_set_led_state ( &leddriver16, LEDDRIVER16_LED_CHANNEL_0 << led_cnt, LEDDRIVER16_LEDOUT_ON );
            Delay_ms ( 100 );
            leddriver16_set_led_state ( &leddriver16, LEDDRIVER16_LED_CHANNEL_0 << led_cnt, LEDDRIVER16_LEDOUT_OFF );
            led_cnt++;
        }
        Delay_ms ( 500 );
        repeat_cnt++;
    }
}

void main ( void )
{
    application_init( );

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

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

额外支持

资源

喜欢这个项目吗?

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