ESP32 maximum PWM frequency
ESP32 maximum PWM frequency
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?
Would it be possible to generate a 1.6MHz pulse on ESP32 GPIO pin?
Re: ESP32 maximum PWM frequency
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!
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

Re: ESP32 maximum PWM frequency
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 ?
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
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 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
Last edited by loboris on Fri Jan 05, 2018 8:06 pm, edited 1 time in total.
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: ESP32 maximum PWM frequency
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
It will be added to the PWM module in my MicroPython port probably tomorrow.OutoftheBOTS_ wrote: ↑Fri Jan 05, 2018 7:59 pmIs 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.
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: ESP32 maximum PWM frequency
@loboris please let me know when you have added this to your firmware and how I would use it 

Re: ESP32 maximum PWM frequency
The refactored module was commited today, full documentation will be available tomorrow...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![]()
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: ESP32 maximum PWM frequency
@laboris Thanks!!
Your a machine, I don't know where you find the time to get all this done
Your a machine, I don't know where you find the time to get all this done

-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: ESP32 maximum PWM frequency
@laboris can you post a link to the docs please 
