Rpi Pico PWM to Motor driver DRV8835

Thought I would post this here as it caused me some confusion and shows a quirk in the Pico PWM. Hopefully someone may benefit from this information.

I was using a Raspberry Pi Pico to drive a couple of motors through a DRV8835 Motor Driver using Micropython PWM. It all worked ok, speed and direction etc. At the end of the program I wanted to stop the PWM. Micropython PWM sets up the hardware which continues to run until the Pico is powered off or PWM is uninstalled.

The following are the PWM functions available in Micropython:

pwm0 = PWM(Pin(0)) *# create PWM object from a pin* 
pwm0.freq() *# get current frequency* 
pwm0.freq(1000) *# set frequency* 
pwm0.duty_u16() *# get current duty cycle, range 0-65535* 
pwm0.duty_u16(200) *# set duty cycle, range 0-65535* 
pwm0.deinit() *# turn off PWM on the pin*

Also has *pwm0.duty_ns()* which specifies the pulse width in nanoseconds, but is not listed in the documentation.

When I used pwm0.deinit() to stop the PWM on a pin, the motor would sometimes continue to run at full speed. I first thought the DRV8835 was faulty. Using an Oscilloscope to see what was happening on the pin; I observed the level would sometimes be low (0V), but more often it would be (3V3). This is what the DRV8835 needed to keep the motor running. Before issuing pwm0.deinit() I set the PWM to 0% pwm0.duty_u16(0), it should have stayed low after pwm0.deinit() but it did not.

To solve the problem, after pwm0.deinit(), I redefined the pin as Input / Output and wrote a low to it.

Have not looked into the Micropython PWM code to see why this is happening.
Just was strange in my opinion for this to occur.

Apart from that the Pico works very well and the DRV8835 is doing what it should.


Hi Jim,

I’m just back from some extended leave. Great to see you’re still at the projects and I assume keeping your grandkids entertained :slight_smile:

I’ll have to have a look and see if I can figure out the cause if I get a moment, but at least you’ve got it working for now.