Skip to content

Fix PWM slice calculation for RP2350 in RP.PWM.To_PWM#76

Merged
JeremyGrosser merged 1 commit into
JeremyGrosser:3.xfrom
krischik:3.x
Apr 9, 2026
Merged

Fix PWM slice calculation for RP2350 in RP.PWM.To_PWM#76
JeremyGrosser merged 1 commit into
JeremyGrosser:3.xfrom
krischik:3.x

Conversation

@krischik

@krischik krischik commented Apr 9, 2026

Copy link
Copy Markdown

The function performed a Shift_Right (Pin, 1) but then ignored the result and overwrote Slice with:

Slice := Pin and 2#111#;

for all pins below 32. The fix uses the already shifted value for the mask operation:

Slice := Slice and 2#111#;

This brings the calculation in line with the RP2350 PWM GPIO mapping table in the datasheet.

Tested on Raspberry Pi Pico 2 (RP2350):

  • GPIO14 now correctly maps to slice 7, channel A
  • GPIO15 now correctly maps to slice 7, channel B

The change eliminates slice misconfiguration when multiple GPIOs share
the same PWM slice, which previously caused missing or flickering PWM
outputs on the Pico 2.

The function performed Shift_Right (Pin, 1) but then ignored the shifted
value and overwrote Slice with "Pin and 2#111#". The fix now correctly
uses the already shifted value for the mask operation (Slice and
2#111#).  This matches the RP2350 datasheet and resolves incorrect slice
assignments (e.g. GPIO14 was mapped to slice 6 instead of 7), which
caused missing or flickering PWM outputs when pins shared a slice on the
Pico 2.
@JeremyGrosser JeremyGrosser merged commit 13719c5 into JeremyGrosser:3.x Apr 9, 2026
1 check failed
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

Successfully merging this pull request may close these issues.

2 participants