Page 1 of 2

ESP32 maximum PWM frequency

Posted: Sat Aug 26, 2017 6:49 pm
by rdagger
The ESP8266 docs shows a 1kHz maximum frequency for PWM on a GPIO pin. Does anyone know the maximum PWM frequency for the ESP32?
Would it be possible to generate a 1.6MHz pulse on ESP32 GPIO pin?

Re: ESP32 maximum PWM frequency

Posted: Mon Aug 28, 2017 7:49 am
by mattyt
So I was hoping this was an easy question to answer. Alas, it's more complex...I thought I'd share what little I do know in the hope that someone else knows more!

There are three parts to this: 1) What can the ESP32 hardware actually do? 2) What does the Expressif IDF provide? 3) What capabilities do the ESP32 MicroPython port currently expose?

1: You'd think that the first part would be spelled out in the detailed ESP32 Technical Reference Manual. But it's not so clear. The PWM capabilities of the ESP32 are well described but fairly complex - they appear to be very flexible. There are two modules dedicated to generating PWM signals - one for LED's and another for motors, intended to be driven through an H-Bridge. Both are built on a series of flexible timers. If I'm interpreting the documentation right a 40MHz frequency may be able to be generated (1/4 of the clock rate? Maybe?) but I might be way off - I haven't figured out if the counters used in the timers are large enough.

2: The IDF is the SDK that the ESP32 port of MicroPython is based on - in other words ESP32 MicroPython uses the IDF to control the hardware. Currently, as far as I'm aware, the ESP32 port never delves below the IDF - if a feature is not available in the IDF it isn't available in MicroPython. I haven't yet figured out how much of the PWM subsystem is exposed through the IDF but it seems quite complete if not thoroughly documented.

3: The ESP32 MicroPython port's implementation of PWM is based on ESP8266. It looks like it will simply scale up to whatever frequency is selected. Haven't tried it yet. It's worth looking at PR79 for some of the implementation details.

In short, I don't know :) but it looks like you ought to be able to generate frequencies in the MHz range. Hopefully someone can shed more light!

Re: ESP32 maximum PWM frequency

Posted: Fri Jan 05, 2018 7:05 am
by devnull
I need to generate a 25khz PWM signal, the 8266 appears to be limited to 1khz, but will the ESP32 support a 25khz signal ??

The observations in the posts above seem to be inconclusive, I realise that I could hook one up and try it but just wondering if anyone has the confirmed answer before I start ?

Re: ESP32 maximum PWM frequency

Posted: Fri Jan 05, 2018 4:20 pm
by loboris
The maximum PWM frequency with the currently used ledc duty resolution of 10 bits in PWM module is 78.125KHz.

The duty resolution can be lowered down to 1 bit in which case the maximum frequency is 40 MHz, but only the duty of 50% is available.
For duty resolution of 8 buts, the maximal frequency is 312.5 kHz.
  • The available duty levels are (2^bit_num)-1, where bit_num can be 1-15.
  • The maximal frequency is 80000000 / 2^bit_num
In my MicroPython implementation, I'm currently working on enabling user selectable and/or automatic duty resolution and higher maxumum frequencies.

Re: ESP32 maximum PWM frequency

Posted: Fri Jan 05, 2018 7:59 pm
by OutoftheBOTS_
Is there any docs on how to go about changing duty resolution because sometimes I want to create a high freq clock signal at 50% duty.

Re: ESP32 maximum PWM frequency

Posted: Fri Jan 05, 2018 8:02 pm
by loboris
OutoftheBOTS_ wrote:
Fri Jan 05, 2018 7:59 pm
Is there any docs on how to go about changing duty resolution because sometimes I want to create a high freq clock signal at 50% duty.
It will be added to the PWM module in my MicroPython port probably tomorrow.

Re: ESP32 maximum PWM frequency

Posted: Sun Jan 07, 2018 6:23 pm
by OutoftheBOTS_
@loboris please let me know when you have added this to your firmware and how I would use it :)

Re: ESP32 maximum PWM frequency

Posted: Sun Jan 07, 2018 7:12 pm
by loboris
OutoftheBOTS_ wrote:
Sun Jan 07, 2018 6:23 pm
@loboris please let me know when you have added this to your firmware and how I would use it :)
The refactored module was commited today, full documentation will be available tomorrow...

Re: ESP32 maximum PWM frequency

Posted: Sun Jan 07, 2018 11:38 pm
by OutoftheBOTS_
@laboris Thanks!!

Your a machine, I don't know where you find the time to get all this done :)

Re: ESP32 maximum PWM frequency

Posted: Tue Jan 09, 2018 10:40 pm
by OutoftheBOTS_
@laboris can you post a link to the docs please :)