graycatlabs / PyBBIO

A Python library for Arduino-style hardware IO support on the Beaglebone
https://github.com/graycatlabs/PyBBIO/wiki
MIT License
251 stars 87 forks source link

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

Open raunaqbhirangi opened 8 years ago

raunaqbhirangi commented 8 years ago

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 commented 8 years ago

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 :unamused:

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 commented 8 years ago

@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