examples/peripherals/ledc/ledc_dimmer/README.md
| Supported Targets | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H21 | ESP32-H4 | ESP32-P4 |
|---|
This example demonstrates how to generate TRIAC gate trigger pulses that are synchronized to the mains zero‑cross using LEDC and ETM. As a simplified demonstration, it simulates the 50 Hz zero‑cross AC mains detector input using a GPIO that toggles at 50 Hz, and uses ETM to reset the LEDC timer on each edge (every half-cycle) for synchronization. By shifting the LEDC hpoint (phase angle) after each reset, the gate pulse moves within the half‑cycle, achieving dimming.
| Signal | GPIO |
|---|---|
| Reference wave (50 Hz square from a AC mains detection circuit) | GPIO3 (configured as input/output in this demo to simulate the square wave) |
| Gate trigger pulse (LEDC output) | GPIO2 |
Expected observation if connect an oscilloscope or logic analyzer:
GPIO3.GPIO2 that occur once each half‑cycle, moving left/right (earlier/later) every 2 seconds as the brightness ramps down and up.Build the project and flash it to the board, then run monitor tool to view serial output:
idf.py build
idf.py -p PORT flash monitor
(Replace PORT with the name of the serial port to use.)
(To exit the serial monitor, type Ctrl-].)
See the ESP‑IDF Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
If you want to control a real TRIAC load (lamp):
REFERENCE_WAVE_IO as input only, remove the toggling task, and ensure ETM still triggers on both edges. Or to normalize the AC mains to some analog signal, and use analog comparator to trigger a ETM event.Here shows a simplified schematic for reference:
And here is an actual timing diagrams (AC mains + dimmer output waveforms with phase angle):
For any technical queries, please open an issue on GitHub. We will get back to you soon.