PWM
Pre-releaseAllows control of the PWM hardware on the Pi Pico. Defaults to 0% duty cycle (controllable 0-1) and 10kHz. On the Pi Pico, only even numbered GPIO are supported. (0, 2, 4, 6, 8, 10, 12, 14). Note that 16+ can also be used but share the same PWM engine as each of the first 8. If you enable PWM on 0 and 16 (or 2 and 18, 4 and 20, etc.) at the same time, changing either of them changes both. The top and divider commands are for manual setting of PWM registers, preference should be given to the duty and frequency commands.
On the Pi Pico the minimum possible frequency is ~7.45Hz all the way up to 12.5Mhz. From minimum up to ~1907Hz, 65536 levels of duty % are available (full 16bit range) and past 1907 the level count is reduced to achieve the desired frequency. At 12.5Mhz only 10 settable levels are available. Here is a table of effective bit-depths with their maximum frequency:
16: 1.907 kHz
15: 3.814 kHz
14: 7.629 kHz
13: 15.2 kHz
12: 30.5 kHz
11: 61 kHz
10: 122 kHz
... and doubling each lower bit.
Commands:
PWM:INIT <GPIO#>[,<0|1|OFF|ON>[,<0|1|OFF|ON>]] // GPIO#, Phase Correct, Enable
PWM:DUTY <GPIO#>,<0-1>
PWM:FREQuency <GPIO#>,
PWM:ENable <GPIO#>
PWM:DUTY? <GPIO#>
PWM:FREQ? <GPIO#>
PWM:TOP <GPIO#>,
PWM:DIVider <GPIO#>,