PWM on separate timers

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
ignitablemoss
Posts: 2
Joined: Fri Jul 17, 2020 8:45 pm

PWM on separate timers

Post by ignitablemoss » Fri Jul 17, 2020 9:22 pm

Hello,

Forgive me if this is a newbie question. I am fairly new to Micropython and embedded development in general. I am developing for the ESP32-WROOM-32D on a custom PCB.

My project has two stepper motors driven by PWM. These motors needs to be driven at different speeds independently. From what I've read, this is not possible with Micropython as all PWM are using a single timer. I'm currently using the Loboris fork of Micropython to get around this limitation, however I also need BLE which Loboris fork does not support.

I also need the motors to run in a separate "thread", but the experimental thread support is causing out-of-memory with the rest of my application running. I'm using uasyncio for the rest of the application tasks, but it can't sleep microseconds and doesn't seem to do the trick for continuously driving the motors.

So I am stuck.

I've looked at the Timer documentation for Wipy, but I don't seem to have the Timer.PWM in Micropython
https://docs.micropython.org/en/latest/ ... timer.html
I've tried rolling my own code to pulse the motors as in this post, but
viewtopic.php?t=3115

Is there a way to make Micropython use separate timers for two PWM signals?

User avatar
JacquesC
Posts: 16
Joined: Sun Feb 17, 2019 5:04 am

Re: PWM on separate timers

Post by JacquesC » Mon Jul 20, 2020 3:56 am

Hello,
I don't think so.
I can't find the information but I have tried to use separate PWM frequencies for steppers motors and finally I have read somewhere that it was not possible on ESP32 boards.
If you can, I am interested to know how do that ... ;)

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

Re: PWM on separate timers

Post by jimmo » Mon Jul 20, 2020 4:33 am

ignitablemoss wrote:
Fri Jul 17, 2020 9:22 pm
I've looked at the Timer documentation for Wipy, but I don't seem to have the Timer.PWM in Micropython
Short version: there is actually a machine.PWM class in MicroPython, but only on ESP32, and it isn't documented. You can see an example here: http://docs.micropython.org/en/latest/e ... modulation

There are 8 PWM channels, but like you say, they all run at the same frequency (although each may have its own duty cycle).

Longer version: Coming up with a cross-architecture PWM API is very difficult, because every microcontroller has a different way of doing PWM, and the sharing of resources between pins, timers, channels, etc can get complicated. It's in-progress, and was originally being planned for v1.13 but I'm not sure if that's still the case.
The ESP32 port added it's machine.PWM implementation independently, but this is why it's not documented, as the API will likely change before being "standardised" across all the ports.

The ESP32 does have dedicated "Motor Control" PWM hardware. It's not currently exposed in MicroPython, however https://github.com/micropython/micropython/pull/5818 might be of interest to you.

Glass
Posts: 1
Joined: Tue Jun 30, 2020 3:04 pm

Re: PWM on separate timers

Post by Glass » Tue Jul 21, 2020 8:56 am

you could always use two esp32 boards. one for each motor

Post Reply