Controlling LEDC timers of the ESP32 microcontroller using registers

  • Daniiel Horenko V.N. Karazin Kharkiv National University, Svobody Square, 4, Kharkiv, Ukraine, 61022 https://orcid.org/0009-0004-6910-4622
  • Albert Kotvytskiy V. N. Karazin Kharkiv National University 4, Svobody Sq., Kharkiv, 61022, Ukraine; Pavol Jozef Šafárik University in Košice, 2, Šrobárova, Kosice, 041 80, Slovak Republic https://orcid.org/0000-0001-8283-505X
Keywords: ATmega, ESP32, LEDC, PWM, register access, logic analyzer

Abstract

Relevance. This paper examines precise generation and control of pulse-width modulation (PWM) signals using the LEDC (LED PWM Controller) subsystem of the ESP32 microcontroller via direct register access. As embedded real-time systems increasingly require fine timing control in LED drivers, motor control and power electronics, standard high-level driver APIs can be insufficient. Direct register manipulation of LEDC enables more precise tuning of frequency, resolution and pulse timing, which is critical for synchronization-sensitive applications.

Objective. To analyze the capabilities of ESP32 LEDC timers when configured through direct register writes, to experimentally evaluate the accuracy and stability of generated PWM signals across representative configurations, and to provide practical recommendations for optimizing LEDC parameters in applied embedded projects.

Methods. The investigation employed low-level register programming under Espressif’s ESP-IDF on an ESP32-DevKitC V4 (WROOM-32D). Time-domain characteristics of the PWM outputs were measured with a Logic Analyzer (24 MHz sampling, 8 channels). The study combined theoretical derivations of PWM frequency and period based on clock source, divider (DIV) and counter resolution (RES) with implementation of direct register sequences to configure HSTIMER0 and HS channel 0, and comparative measurements for eighteen distinct configurations covering multiple RES, DIV and DUTY values.

Results. The register-based control method enabled generation of high-frequency PWM in the MHz range with close agreement between calculated and measured values. Across tested configurations the maximum relative deviation did not exceed ±0.03% for frequency and period, and ±0.6% for pulse high-time (duty width). Increasing counter resolution improved duty-cycle granularity, while the prescaler DIV produced a linear change in PWM frequency. The experimental limitations observed at the highest frequencies are attributable to the finite sampling capability of the measurement equipment.

Conclusions. Direct register access to the LEDC allows for obtaining deterministic, high-precision PWM signals with minimal parameter update latency, making them suitable for applications in robotics, power electronics, and other systems with high synchronization requirements. Further research is recommended on the influence of alternative clock sources, low-speed LEDC modes, integration with ISR/FreeRTOS, and extending the approach to other timers and channels.

Downloads

Download data is not yet available.

Author Biographies

Daniiel Horenko, V.N. Karazin Kharkiv National University, Svobody Square, 4, Kharkiv, Ukraine, 61022

Master student of the Institute of Computer Science and Artificial Intelligence

Albert Kotvytskiy, V. N. Karazin Kharkiv National University 4, Svobody Sq., Kharkiv, 61022, Ukraine; Pavol Jozef Šafárik University in Košice, 2, Šrobárova, Kosice, 041 80, Slovak Republic

Candidate of Physical and Mathematical Sciences, Associate Professor

References

/

References

Published
2025-10-27
How to Cite
Horenko, D., & Kotvytskiy, A. (2025). Controlling LEDC timers of the ESP32 microcontroller using registers. Bulletin of V.N. Karazin Kharkiv National University, Series «Mathematical Modeling. Information Technology. Automated Control Systems», 67, 45-55. https://doi.org/10.26565/2304-6201-2025-67-04
Section
Статті