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

Cannot use two PWM channels at the same time #84

Closed
robreuss opened this issue Mar 1, 2019 · 5 comments
Closed

Cannot use two PWM channels at the same time #84

robreuss opened this issue Mar 1, 2019 · 5 comments

Comments

@robreuss
Copy link

robreuss commented Mar 1, 2019

Board Type

RaspberryPi3

Operating System

Ubuntu Mate 16.04

Swift Version

4.1.3, pre-built

Description

Attempting to drive a motor controller (https://www.pololu.com/product/3754) using PWM. I have one channel each for the right and left sides of my robot vehicle. When I startPWM to one channel, the other channel stops. This occurs even if the period and duty are the same with each startPWM call. Any way to overcome this behavior?

@uraimo
Copy link
Owner

uraimo commented Mar 1, 2019

Yes, because right now the clock that generates the pwm is being killed every time a new pwm is started, see here (I was more interested in building something to easily generate patterns than in the vanilla pwm, so a few basic thing were never implemented).

If the frequency/ns parameter is kept the same (the duty cycle doesn't matter) this should not be needed, so it could be either removed, or better performed only the first time startPWM is called checking a flag.
To try this out you can simply modify the local checkout of this library (under .build/...) in your project.
Let me know if it doesn't work, but I'm somewhat confident it should :)

This was discussed with Kaiede some time ago in #73, and in the end in his improved fork he cleaned up the implementation reducing the number of moving parts and removing the need for the clock reset.

@robreuss
Copy link
Author

robreuss commented Mar 1, 2019

Cool. Swapped in Kaiede's version and it works fine.

I used an online calculator to convert my desired frequency from 20Khz to 50000 nanoseconds but I wanted to confirm with you that that is the correct nanosecond value for that frequency.

@uraimo
Copy link
Owner

uraimo commented Mar 1, 2019

Yep, correct, 1Hz=1/1sec, so 1/20000Hz gives you 50 microseconds or 50000 nanoseconds.

Btw, since this could be a common annoyance for a lot of people I plan to fix this (and a few other things) and make a new release.

@robreuss
Copy link
Author

robreuss commented Mar 1, 2019

I'll watch for the new release! Thanks!

@robreuss robreuss closed this as completed Mar 1, 2019
@robreuss
Copy link
Author

robreuss commented Jan 7, 2022

I was wondering if this improvement was eventually made to SwiftyGPIO. I've run into the same problem using SwiftyGPIO so I'm assuming not, but wanted to confirm before I switch over to SingleBoard.

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

2 participants