Chapter 2. API Reference
Functionality Overview
Setting up a channel of the LEDC is done in three steps. Note that unlike ESP32, ESP32-S2 only supports configuring
channels in “low speed”mode.
1. Timer Configuration by specifying the PWM signal’s frequency and duty cycle resolution.
2. Channel Configuration by associating it with the timer and GPIO to output the PWM signal.
3. Change PWM Signal that drives the output in order to change LED’s intensity. This can be done under the
full control of software or with hardware fading functions.
As an optional step, it is also possible to set up an interrupt on fade end.
Fig. 7: Key Settings of LED PWM Controller’s API
Timer Configuration Setting the timer is done by calling the function ledc_timer_config() and passing
the data structure ledc_timer_config_t that contains the following configuration settings:
• Speed mode (value must be LEDC_LOW_SPEED_MODE)
• Timer number ledc_timer_t
• PWM signal frequency
• Resolution of PWM duty
The frequency and the duty resolution are interdependent. The higher the PWM frequency, the lower the duty
resolution which is available, and vice versa. This relationship might be important if you are planning to use this API
for purposes other than changing the intensity of LEDs. For more details, see Section Supported Range of Frequency
and Duty Resolutions.
Channel Configuration When the timer is set up, configure the desired channel (one out of ledc_channel_t).
This is done by calling the function ledc_channel_config().
Similar to the timer configuration, the channel setup function should be passed a structure
ledc_channel_config_t that contains the channel’s configuration parameters.
At this point, the channel should start operating and generating the PWM signal on the selected GPIO, as configured
in ledc_channel_config_t, with the frequency specified in the timer settings and the given duty cycle. The
channel operation (signal generation) can be suspended at any time by calling the function ledc_stop().
Espressif Systems 316
Submit Document Feedback
Release v4.4