ESP32 maximum PWM frequency

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
loboris
Posts: 344
Joined: Fri Oct 02, 2015 6:19 pm

Re: ESP32 maximum PWM frequency

Post by loboris » Wed Jan 10, 2018 8:46 am

OutoftheBOTS_ wrote:
Tue Jan 09, 2018 10:40 pm
@laboris can you post a link to the docs please :)
Sorry, I was quite bussy, I'll try to finish the documentation later today. I will apear on Wiki pages.

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

Re: ESP32 maximum PWM frequency

Post by mattyt » Tue Jan 30, 2018 10:13 am

Just to close the loop, I just noticed that the PWM wiki page is online. Thanks @loboris!

User avatar
rdagger
Posts: 143
Joined: Tue Feb 28, 2017 6:16 pm
Contact:

Re: ESP32 maximum PWM frequency

Post by rdagger » Tue Jan 30, 2018 6:39 pm

@laboris Would it be possible to add a feature so you could programmatically invert or offset the duty cycle of some of the channels on a timer?
PWM inverted.png
PWM inverted.png (4.61 KiB) Viewed 10425 times

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

Re: ESP32 maximum PWM frequency

Post by loboris » Tue Jan 30, 2018 7:34 pm

rdagger wrote:
Tue Jan 30, 2018 6:39 pm
@laboris Would it be possible to add a feature so you could programmatically invert or offset the duty cycle of some of the channels on a timer?PWM inverted.png
All PWM channels using the same timer have the same frequency and phase.
PWM channel started with different timer will have some random offset depending on time when the timer was started.
It could be possible to synchronize two PWMs, each using a different timer, in such way that one is started at the known time after the other.
That time would be the phase offset between channels.
If that time is half the timer period and the channels period and duty cycles are the same, the PWM's outputs would be inverted.

I'll test it and add that option if it works as expected.

User avatar
rdagger
Posts: 143
Joined: Tue Feb 28, 2017 6:16 pm
Contact:

Re: ESP32 maximum PWM frequency

Post by rdagger » Tue Jan 30, 2018 10:19 pm

loboris wrote:
Tue Jan 30, 2018 7:34 pm
All PWM channels using the same timer have the same frequency and phase.
PWM channel started with different timer will have some random offset depending on time when the timer was started.
It could be possible to synchronize two PWMs, each using a different timer, in such way that one is started at the known time after the other.
That time would be the phase offset between channels.
If that time is half the timer period and the channels period and duty cycles are the same, the PWM's outputs would be inverted.

I'll test it and add that option if it works as expected.
Thanks, that would be very helpful.

mosi
Posts: 28
Joined: Tue Oct 07, 2014 12:07 am

Re: ESP32 maximum PWM frequency

Post by mosi » Thu Mar 15, 2018 8:52 am

loboris wrote:
Tue Jan 30, 2018 7:34 pm
All PWM channels using the same timer have the same frequency and phase.
PWM channel started with different timer will have some random offset depending on time when the timer was started.
It could be possible to synchronize two PWMs, each using a different timer, in such way that one is started at the known time after the other.
That time would be the phase offset between channels.
If that time is half the timer period and the channels period and duty cycles are the same, the PWM's outputs would be inverted.

I'll test it and add that option if it works as expected.
Hi, lobo, tremendous work!

Any ideas on how to synchronize two PWMs?
I have seen an option:

#define MCPWM_EN_SYNC 0 //Make this 1 to test sync submodule of mcpwm, sync timer signals

in ESP32-IDF
examples/peripherals/mcpwm/mcpwm_basic_config/main/mcpwm_basic_config_example.c

Idea 1) STM32 module in micropython exposes underlying hardware registers. Reading and writing those registers allows for pretty comfortable control of timers/PWM pins. However, the only option to start two PWM pins with predefined phase shift is through @asm_thumb code. This seems not to be available in ESP32 micropython. Is inline C code possible?

Idea 2) writing my own C code for starting two PWM channels on two given Pins and exposing the function to micropython

Which do you think leads to faster results?

Tried to implement @micropython.asm_xtensa decorator for ESP32, but it fails with CPU crash.
What is the status of the inline assembler for the new ESP32 dual core processors?
Roberthh wrote:
Mon Jan 15, 2018 9:13 pm
...
https://github.com/micropython/micropyt ... d2db3ff4a3

Code: Select all

@micropython.asm_xtensa
def do_loop():
    movi(a2, 0x60000300) # GPIO Base address
    movi(a5, 0x10) # set/clear bit 4
    movi(a3, 10) # loop
    ...

thalesmaoa
Posts: 35
Joined: Thu Feb 13, 2020 10:10 pm

Re: ESP32 maximum PWM frequency

Post by thalesmaoa » Sun Mar 29, 2020 8:44 pm

I know that this is an old post, but I want to know if there are any news. I mean, I'm trying to generate Three-phase PWM with complementary and dead time. Can't find a way to do that with Micropython.

User avatar
OlivierLenoir
Posts: 126
Joined: Fri Dec 13, 2019 7:10 pm
Location: Picardie, FR

Re: ESP32 maximum PWM frequency

Post by OlivierLenoir » Tue Mar 31, 2020 5:38 am

Have a look at post viewtopic.php?f=2&t=7774&start=10 about MicroPython and Power Electronics - Electrical machine control. It may answer part of your questions.

Post Reply