PWM - different frequences.

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
prem111
Posts: 111
Joined: Sun Feb 23, 2020 3:18 pm

PWM - different frequences.

Post by prem111 » Sat Nov 14, 2020 5:24 pm

Hi, im using esp32 for control servos and esc.

Due to the standard machine_pwm not supporting different frequencies on different PWM channels, I modified machine_pwm according to the following:
https://github.com/micropython/micropyt ... 280d6731a2

Unfortunately, when I try to set the freq to 50HZ I have an error:
ValueError: Bad frequency 50

Most of the standard serv runs at 50hz.
What can I do ? I am using micropython 1.12 on esp32.

Thanks for help!

User avatar
jimmo
Posts: 2236
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: PWM - different frequences.

Post by jimmo » Sun Nov 15, 2020 4:14 am

prem111 wrote:
Sat Nov 14, 2020 5:24 pm
What can I do ? I am using micropython 1.12 on esp32.
I don't know much about ESP32, but one of the key things is that the PWM controller is actually based on their LED driver peripheral. This is designed for doing PWM at much higher frequencies (to avoid flicker).

I noticed that the PR you copied the changes from introduces a "low speed" and "high speed" mode. Which one are you using?

Also it might be worth reading https://docs.espressif.com/projects/esp ... esolutions and https://www.espressif.com/sites/default ... ual_en.pdf (chapter 15) for more details on how this works.

Also you said you're controlling ESC and servos, why do you need a different PWM frequency for each? And many servos don't actually need 50Hz, they really just need a specific pulse time.

prem111
Posts: 111
Joined: Sun Feb 23, 2020 3:18 pm

Re: PWM - different frequences.

Post by prem111 » Sun Nov 15, 2020 8:07 am

I used HIGH for esc and LOW for servos. What do you mean by avoid flicker ?, that at e.g. 50hz it can cause more servo vibration than at e.g. 100hz?

User avatar
jimmo
Posts: 2236
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: PWM - different frequences.

Post by jimmo » Sun Nov 15, 2020 11:12 am

prem111 wrote:
Sun Nov 15, 2020 8:07 am
I used HIGH for esc and LOW for servos. What do you mean by avoid flicker ?, that at e.g. 50hz it can cause more servo vibration than at e.g. 100hz?
I mean it's designed for driving dimmable LEDs, where you want to PWM in the hundreds of kilohertz.

Why do you need different frequency for ESC and servos?

Post Reply