Chapter 2. API Reference
Change PWM Signal
Once the channel starts operating and generating the PWM signal with the constant duty
cycle and frequency, there are a couple of ways to change this signal. When driving LEDs, primarily the duty cycle
is changed to vary the light intensity.
The following two sections describe how to change the duty cycle using software and hardware fading. If required,
the signal's frequency can also be changed; it is covered in Section
Note: All the timers and channels in the ESP32-S2's LED PWM Controller only support low speed mode. Any
change of PWM settings must be explicitly triggered by software (see below).
Change PWM Duty Cycle Using Software
ledc_set_duty().
currently set value, use the corresponding _get_ function ledc_get_duty().
Another way to set the duty cycle, as well as some other channel parameters, is by calling
ledc_channel_config()
The range of the duty cycle values passed to functions depends on selected duty_resolution and should be
from 0 to (2 ** duty_resolution) - 1. For example, if the selected duty resolution is 10, then the duty
cycle values can range from 0 to 1023. This provides the resolution of ~0.1%.
Change PWM Duty Cycle using Hardware
one duty cycle value to another. To use this functionality, enable fading with
and then configure it by calling one of the available fading functions:
•
ledc_set_fade_with_time()
•
ledc_set_fade_with_step()
•
ledc_set_fade()
Finally start fading with ledc_fade_start().
If
not
required
anymore,
ledc_fade_func_uninstall().
Change PWM Frequency
• Set the frequency by calling ledc_set_freq(). There is a corresponding function
to check the current frequency.
• Change the frequency and the duty resolution by calling
other timer to the channel.
• Change the channel's timer by calling ledc_channel_config().
More Control Over PWM
settings:
•
ledc_timer_set()
•
ledc_timer_rst()
•
ledc_timer_pause()
•
ledc_timer_resume()
The first two functions are called "behind the scenes"by
timer after it is configured.
Use Interrupts
When configuring an LEDC channel,
ledc_channel_config_t
For registration of a handler to address this interrupt, call ledc_isr_register().
Espressif Systems
After that, call
ledc_update_duty()
covered in Section
Channel
The LEDC hardware provides the means to gradually transition from
fading
and
The LEDC API provides several ways to change the PWM frequency "on the fly":
There are several lower level timer-specific functions that can be used to change PWM
is
ledc_intr_type_t
Submit Document Feedback
Change PWM
To set the duty cycle, use the dedicated function
to activate the changes.
Configuration.
ledc_fade_func_install()
an
associated
interrupt
ledc_bind_channel_timer()
ledc_channel_config()
one of the parameters selected within
which triggers an interrupt on fade completion.
317
Frequency.
To check the
can
be
disabled
ledc_get_freq()
to bind some
to provide a startup of a
Release v4.4
with
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?