Page 1 of 1

How to synchronize PWM timers

Posted: Fri Mar 16, 2018 9:52 am
by andymosi
Need to generate 1) fast clock on PinX and 2) slow clock on PinY,
but the phase needs to be synchronized.

How do you synchronize two PWM channels?

I have found the MCPWM module, but do not understand how to use it in an example.
Anyone did something similar?


int mcpwm_sync0_in_num; /*!<SYNC0 in pin*/
https://github.com/espressif/arduino-es ... er/mcpwm.h

Code: Select all

/**
 * @brief Initialize sync submodule
 *
 * @param mcpwm_num set MCPWM unit(0-1)
 * @param timer_num set timer number(0-2) of MCPWM, each MCPWM unit has 3 timers
 * @param sync_sig set the fault Pin, which needs to be enabled
 * @param phase_val phase value in 1/1000(for 86.7%, phase_val = 867) which timer moves to on sync signal
 *
 * @return
 *     - ESP_OK Success
 *     - ESP_ERR_INVALID_ARG Parameter error
 */
esp_err_t mcpwm_sync_enable(mcpwm_unit_t mcpwm_num, mcpwm_timer_t timer_num, mcpwm_sync_signal_t sync_sig,
uint32_t phase_val);