ESP32 PWM: Number of Output Frequencies and Phase between PWM Waves

Hi,

I want to use Arduino IDE to configure PWM channels on an ESP32 chip.

I read that ESP32 has four hardware timers, expect for ESP32-C3 which only has 2 timers. However, all ESP32 chips seem to have 16 PWM channels. So my question is, how many different "frequencies" of PWM wave can an ESP32 output simultaneously? Is it the number of timers or the number of PWM channels?

I would also like to ask how to control the phase between two PWM waves with same frequency. Is it reasonable to use two different timers to generate two PWM waves, and use delay() function to make the waves start at different time? Or, there is already an built-in function in Arduino library that can take care of this?

Thank you for your information!

Generally, across MCU's, multiple PWM outputs are controlled by individual timers. However, there may also be multiple timers.

1 Like

No, these two functions, PWM and delay() calls, happen at different hardware/software abstraction layers.

Timers are synchronized by writing directly to their respective control registers.

Unfortunately, I know next to nothing about ESP internals. Only AVR and STM32.

You didn't describe your need in any detail. Some manufacturers have targeted certain multiphase applications like 3 phase power control, with special PWM controls to facilitate those. So please tell us more.

Your other question has its answer in mathematics. Obviously, a timer is needed for each individual repetition rate (aka frequency).

As far as controling the phase between two PWM channels.
Maybe could you just use one periodic timer and every time it times out the interrupt routine increments a count variable. So you just turn on and off gpio's pins based on the count. With that you can have a bunch of pins doing pwm and they will running off the same timer so they are already synch'd to each other.