Hardware PWM on RP2040 ignores cycle_time setting

klippy.log (330.2 KB)

Basic Information:

Printer Model: Self-built (once an Ender 3 Pro)
MCU / Printerboard: SKR 3 Mini / Mellow Fly SB2040 V1
klippy.log

Describe your issue:

I currently attempt to get my BL-Touch operating on a Mellow Fly SB2040 V1 board using the RP2040. I am using GPIO28. While debugging the system using an oscilloscope I found that the PWM signals where not correct. I started looking into those by configuring the pin as outpit_pin, controlling the servo manually using the SET_PIN command . I found that the pulses are not correct when hardware PWM is used. In this case the cycle time appears to be always 500us (at least when I set it to 0.2 or 0.02 (seconds)). With that low cycle time no observable pulse is generated at all when using low PWM factors required for the Servo control of the BL-Touch (e.g. 0.0325 for pin down).

Can someone point me how to best debug this issue. I found the corresponding code in src/rp2040/hard_pwm.c, but I don’t see anything obviously wrong with it. But I also don’t have any experience with the RP2040 so far.

For future reference (possibly me): This is independent from the BL-Touch operation which requires hardware modification on this board: BL-Touch requires removal of series resistance · Issue #9 · Mellow-3D/Fly-SB2040 · GitHub

From the documentation:

#hardware_pwm: False
#   Enable this to use hardware PWM instead of software PWM. When
#   using hardware PWM the actual cycle time is constrained by the
#   implementation and may be significantly different than the
#   requested cycle_time. The default is False.

I’m not sure why you would want to use hardware pwm for this application. Just use software pwm.

1 Like