ESP32 maximum PWM frequency

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
User avatar
rdagger
Posts: 87
Joined: Tue Feb 28, 2017 6:16 pm
Contact:

ESP32 maximum PWM frequency

Post by rdagger » Sat Aug 26, 2017 6:49 pm

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?

User avatar
mattyt
Posts: 224
Joined: Mon Jan 23, 2017 6:39 am

Re: ESP32 maximum PWM frequency

Post by mattyt » Mon Aug 28, 2017 7:49 am

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!

User avatar
devnull
Posts: 344
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall
Contact:

Re: ESP32 maximum PWM frequency

Post by devnull » Fri Jan 05, 2018 7:05 am

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 ?

loboris
Posts: 317
Joined: Fri Oct 02, 2015 6:19 pm

Re: ESP32 maximum PWM frequency

Post by loboris » Fri Jan 05, 2018 4:20 pm

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.
Last edited by loboris on Fri Jan 05, 2018 8:06 pm, edited 1 time in total.

OutoftheBOTS_
Posts: 606
Joined: Mon Nov 20, 2017 10:18 am

Re: ESP32 maximum PWM frequency

Post by OutoftheBOTS_ » 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.

loboris
Posts: 317
Joined: Fri Oct 02, 2015 6:19 pm

Re: ESP32 maximum PWM frequency

Post by loboris » Fri Jan 05, 2018 8:02 pm

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.

OutoftheBOTS_
Posts: 606
Joined: Mon Nov 20, 2017 10:18 am

Re: ESP32 maximum PWM frequency

Post by OutoftheBOTS_ » 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 :)

loboris
Posts: 317
Joined: Fri Oct 02, 2015 6:19 pm

Re: ESP32 maximum PWM frequency

Post by loboris » Sun Jan 07, 2018 7:12 pm

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...

OutoftheBOTS_
Posts: 606
Joined: Mon Nov 20, 2017 10:18 am

Re: ESP32 maximum PWM frequency

Post by OutoftheBOTS_ » Sun Jan 07, 2018 11:38 pm

@laboris Thanks!!

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

OutoftheBOTS_
Posts: 606
Joined: Mon Nov 20, 2017 10:18 am

Re: ESP32 maximum PWM frequency

Post by OutoftheBOTS_ » Tue Jan 09, 2018 10:40 pm

@laboris can you post a link to the docs please :)

Post Reply