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

Unable to use PWM1A and PWM1B at the same time #101

Open
raunaqbhirangi opened this issue Jun 19, 2016 · 2 comments
Open

Unable to use PWM1A and PWM1B at the same time #101

raunaqbhirangi opened this issue Jun 19, 2016 · 2 comments

Comments

@raunaqbhirangi
Copy link

raunaqbhirangi commented Jun 19, 2016

I'm trying to use both PWM1A and PWM1B. I am not changing the frequency.
I just use

analogWrite(PWM1A,200,RES_8BIT)
analogWrite(PWM1B,200,RES_8BIT)

I am able to digitalWrite to both pins when I use them as GPIO1_18 and GPIO1_19. But the analogWrite doesn't work for one of them.
When I run my code for the first time on startup, whichever pin, 1A or 1B is used with analogWrite first, works with PWM for that session and the other one simply won't work.

@alexanderhiam
Copy link
Member

Right, at some point I think the PWM driver changed a little bit, so the way PyBBIO currently does PWM became a little bit wrong 😒

I'm planning to completely rewrite the PWM code as a C extension (issue #62), and I've been reluctant (and busy) to try and debug it before then...

I think you can get around it by first explicitly setting both channels to a 0% duty cycle before using them, i.e.:

analogWrite(PWM1A, 0)
analogWrite(PWM1B, 0)

analogWrite(PWM1A,200,RES_8BIT)
analogWrite(PWM1B,200,RES_8BIT)

Give that a try and let me know what happens...

@MatthewWest
Copy link

@alexanderhiam I just wrote an update for Adafruit's BBIO library in C, parts of which may be instructive. The relevant file is this one

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

3 participants