ESP32 maximum PWM frequency

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
loboris
Posts: 317
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: 242
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: 87
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 2690 times

loboris
Posts: 317
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: 87
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: 26
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
    ...

Post Reply