|
|
hace 2 años | |
|---|---|---|
| .. | ||
| main | hace 2 años | |
| CMakeLists.txt | hace 3 años | |
| README.md | hace 2 años | |
| pytest_mcpwm_sync.py | hace 3 años | |
| sdkconfig.ci.gpio | hace 3 años | |
| sdkconfig.ci.soft | hace 3 años | |
| sdkconfig.ci.tez | hace 3 años | |
| Supported Targets | ESP32 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S3 |
|---|
(See the README.md file in the upper level 'examples' directory for more information about examples.)
MCPWM timers can't be started together because you have to call mcpwm_timer_start_stop function timer by timer, so the generators driven by them are not in sync with each other. But there're several ways to force these timers jump to the same point by setting sync phase for timers and then wait for a proper sync event to happen.
This example illustrates how to generate three PWMs that are in perfect synchronization.
It is recommended to have an oscilloscope or logic analyzer to view the generated PWM waveforms.
Connection :
ESP Board oscilloscope / logic analyzer
+--------------------------+ +----------------------------+
| | | |
| EXAMPLE_GEN_GPIO0 +-----------------+ channelA |
| | | |
| EXAMPLE_GEN_GPIO1 +-----------------+ channelB |
| | | |
| EXAMPLE_GEN_GPIO2 +-----------------+ channelC |
| | | |
| GND +-----------------+ GND |
| | | |
+--------------------------+ +----------------------------+
Above used GPIO numbers (e.g. EXAMPLE_GEN_GPIO0) can be changed in the source file.
idf.py menuconfig
You can select the way to synchronize the MCPWM timers in the menu: Example Configuration -> Where the sync event is generated from.
Timer TEZ approach. The main timer is sync by software, and it will propagate the sync event to other timers.Run idf.py -p PORT flash monitor to build, flash and monitor the project.
(To exit the serial monitor, type Ctrl-].)
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
I (0) cpu_start: Starting scheduler on APP CPU.
I (305) example: Create timers
I (305) example: Create operators
I (305) example: Connect timers and operators with each other
I (315) example: Create comparators
I (315) example: Create generators
I (325) gpio: GPIO[0]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (335) gpio: GPIO[2]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (345) gpio: GPIO[4]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (355) example: Set generator actions on timer and compare event
I (355) example: Start timers one by one, so they are not synced
I (495) example: Force the output level to low, timer still running
I (495) example: Setup sync strategy
I (495) example: Create GPIO sync source
I (495) gpio: GPIO[5]| InputEn: 1| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 1| Intr:0
I (505) example: Set timers to sync on the GPIO
I (505) example: Trigger a pulse on the GPIO as a sync event
I (515) example: Now the output PWMs should in sync
For any technical queries, please open an issue on GitHub. We will get back to you soon.