Supported ICs

Introduction

LEDC (LED Controller) is a highly efficient embedded solution that supports the control of smart LED lights (such as WS2812B) and is compatible with the DSHOT protocol to drive brushless motors.

Features

  • Configurable data transmission pulse time and non-data period

  • Configurable RGB888 display mode and LED refresh time

  • Supports up to 8192 data sequence entries

  • Supports up to 1024 LEDs

  • Supports DMA transmission

Working Principle

Logical 0/1 Encoding and Configuration Guide

  • Logical “0” and “1” Encoding

    Logical “0” (referred to as “Code 0”) and logical “1” (referred to as “Code 1”) are composed of high and low levels, as shown in the figure.

    ../../../_images/ledc_code0_code1.svg

    Input Code Timing

  • Logic Level Timing

    The high and low level duration of Code 0 and Code 1 varies among different devices.

    Taking the WS2812B-2020 smart LED as an example:

    code0_code1_timing

    Code

    Description

    Time Range

    Unit

    T0H

    Code 0, High Level Time

    220 ~ 380

    ns

    T0L

    Code 0, Low Level Time

    580 ~ 1000

    ns

    T1H

    Code 1, High Level Time

    580 ~ 1000

    ns

    T1L

    Code 1, Low Level Time

    220 ~ 420

    ns

    RESET

    Frame reset, Low Level time

    > 280

    μs

    Encoding total time:

    • Code 0: 800ns ~ 1380ns

    • Code 1: 800ns ~ 1420ns

  • Encoding Time Configuration

    By adjusting the TxH_CNT and TxL_CNT parameters in the register, you can flexibly set the clock cycle number for the high and low levels of Code 0 and Code 1.

    • x: Refers to 0 or 1

    • Count clock: XTAL40MHz

Data Transmission Timing

LED Communication Mode

Taking WS2812B LED as an example, it uses the single-wire non-return-to-zero (NRZ) communication protocol and adopts a cascade method for data transmission:

  • Power-on reset: After power-on, the LED receives data from the controller through the DI port. The first LED will capture and latch the first 24-bit data.

  • Data passing: The remaining data is transmitted to the next LED through the internal reshaping circuit from the DO port.

  • Signal decrement: With each LED, the signal will be reduced by 24 bits of data.

LEDC Transmission Timing

The data timing sent by LEDC to the first LED is as follows:

../../../_images/ledc_packet_timing.svg

LEDC Data Transmission Timing

Reset Signal: Configurable period used to refresh the LED.

Interval Adjustment:

  • Supports insertion of low-level intervals between adjacent pixels

  • Supports insertion of low-level intervals between adjacent frames

Number of LEDs

The formula to calculate the number of supported LEDs is:

\begin{gather*} LED\_NUM = \frac{\frac{1}{LED\,fresh\,rate(\frac{frame}{s})} - 280μs}{(logical\,0\,or\,1\,coding\,time) * 24} \end{gather*}

Using the timing of Code 0 and Code 1 from table code0_code1_timing as an example, the number of supported LEDs is calculated as follows:

  • When the LED refresh rate is 30 frames per second, the number of supported LEDs is 681 ~ 1023.

  • When the LED refresh rate is 60 frames per second, the number of supported LEDs is 337 ~ 853.

Application Example

raw_ledc_ws2812 demonstrates how to configure and control multiple LED lights using the LEDC module.

Note

To see the chips supported by the example, check the README.md file in the example path.

API Reference

For detailed understanding and use of relevant APIs, please refer to {SDK}\component\soc\amebaxxxx\fwlib\include\ameba_ledc.h.