Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set PWM frequency and duty cycle in microseconds #85

Closed
deshipu opened this issue Jan 23, 2017 · 6 comments
Closed

Set PWM frequency and duty cycle in microseconds #85

deshipu opened this issue Jan 23, 2017 · 6 comments

Comments

@deshipu
Copy link

deshipu commented Jan 23, 2017

The current nativeio.PWMOut is pretty nice for things like controlling LED dimming or motor speed. However it's hopelessly inadequate for controlling hobby servos or BLDC ESCs.

For controlling hobby servos I need to be able to specify the frequency (for instance, most analog servos expect 50Hz, digital servos and ESCs may go up to 300Hz or maybe even higher).

Setting the duty cycle as percentage of the total period (converted to 0-255) is also fine for LEDs, but for servos, which typically expect duty cycles between 1000µs and 2000µs with period of 20000µs that gives very poor resolution, makes it harder to calculate the right value, and gives an opportunity for rounding errors. It would be much nicer to be able to set the duty cycle in terms of absolute time units, like microseconds.

@tannewt
Copy link
Member

tannewt commented Jan 23, 2017

Frequency already is covered in #13 . Handling microseconds is a good point and I'll leave this open for that.

@tannewt
Copy link
Member

tannewt commented Feb 1, 2017

After implementing frequency and switching duty_cycle to 16 bit I think setting these based on milliseconds is best done in a library. Adding it the core will take extra space even when its not needed. You shouldn't have any trouble with resolution now that its 16 bit.

@bart
Copy link

bart commented Jan 31, 2019

@deshipu and @dhalbert How did you solve it? Could you please give an example? Having the same issue now and want to control an ESC with a pulse width between 1000 and 2000 µs

@tannewt
Copy link
Member

tannewt commented Jan 31, 2019

While it's for Servos you should be able to use this for ESCs as well: https://github.com/adafruit/Adafruit_CircuitPython_Motor/blob/master/adafruit_motor/servo.py

@bart
Copy link

bart commented Jan 31, 2019

Thank you sir, I'm already using this library. But which method would you suggest? angle() doesn't sound correct to me for an ESC.

@chrisalbertson

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants