Page 1 of 1

min and max pulse widths for machine.PWM?

Posted: Tue Jun 15, 2021 9:52 am
by ghukill
I'm trying to port some Arduino code to micropython that drives a brushless motor using an ESC module. Using an esp8266mod board.

The arduino code sets up the pin that writes to ESC like this:

Code: Select all

#include <Servo.h>
...
ESC.attach(9,1000,2000); // (pin, min pulse width, max pulse width in microseconds) 
Then writes like this:

Code: Select all

potValue = analogRead(A0);   // reads the value of the potentiometer (value between 0 and 1023)
potValue = map(potValue, 0, 1023, 0, 180);   // scale it to use it with the servo library (value between 0 and 180)    
Use a 10k pot, I can twist from full open to full close, and power the motor. But with micropython, I'm seeing a much more delicate range, which leads to problems calibrating.

I've got some micropython code that gets me very close, but I'm feeling like those "min pulse width" and "max pulse width" parameters in the Arduino code help smoothing things out.

I'm setting up the pin this way in Micropython:

Code: Select all

p = machine.Pin(14)
pwm_p = machine.PWM(machine.Pin(14), freq=500, duty=0)
Apologies for burying the lead, but am I missing something fundamental about the machine.PWM (https://docs.micropython.org/en/latest/ ... e.PWM.html) class that might allow these kind of min/max values?

Re: min and max pulse widths for machine.PWM?

Posted: Tue Jun 15, 2021 11:01 am
by ghukill
Stumbled on this forum post that may have some details/approaches that could be helpful:
viewtopic.php?f=2&t=10494&p=57979&hilit ... tio#p57980

Re: min and max pulse widths for machine.PWM?

Posted: Wed Jun 16, 2021 7:12 am
by ghukill
This post also has some helpful / relevant information:
viewtopic.php?t=1920