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

Fix second shared PWM #4253

Merged
merged 2 commits into from
Feb 26, 2021
Merged

Fix second shared PWM #4253

merged 2 commits into from
Feb 26, 2021

Conversation

tannewt
Copy link
Member

@tannewt tannewt commented Feb 24, 2021

Fixes #4210

@tannewt tannewt added bug rp2040 Raspberry Pi RP2040 labels Feb 24, 2021
@tannewt tannewt added this to the 6.2.0 milestone Feb 24, 2021
@dhalbert
Copy link
Collaborator

I am going to test this with hardware.

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original problem appears to be fixed, but accidentally while trying things from the REPL I found this. Notice that at first try I can't set the shared PWM to different frequencies, but if I deinit() one and then reinitialize it again with a different frequency. It does not complain. The actual frequency sent to both pins is the second frequency (200 in this case).

>>> import pwmio, board
>>> p0 = pwmio.PWMOut(board.GP0, frequency=2, duty_cycle=32768)
>>> p1 = pwmio.PWMOut(board.GP1, frequency=20, duty_cycle=32768)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: All timers for this pin are in use
>>> p1 = pwmio.PWMOut(board.GP1, frequency=2, duty_cycle=32768)
>>> p1.deinit()
>>> p1 = pwmio.PWMOut(board.GP1, frequency=200, duty_cycle=32768)
>>> 

@tannewt tannewt force-pushed the rp2040_fix_pwm_reuse branch from 7d6db34 to 2b163cc Compare February 25, 2021 22:58
@tannewt
Copy link
Member Author

tannewt commented Feb 25, 2021

Ok, I fixed the mask we use to see if both channels are free. (It was incorrectly shifted by the channel.) The example code now correctly errors the second time.

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. Thanks for the fix!

@tannewt tannewt merged commit 2e6e91d into adafruit:main Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug rp2040 Raspberry Pi RP2040
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Raspberry Pi Pico PWM only works for 8 pins on 6.2.0-beta.2 absolute latest
2 participants