machine.PWM with duty=0 not staying low

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
AwesomeCronk
Posts: 33
Joined: Fri Oct 11, 2019 1:24 am

machine.PWM with duty=0 not staying low

Post by AwesomeCronk » Mon Jul 18, 2022 12:00 pm

I am developing a device that must control a DC motor (must have speed control and be reversible). I am realizing, however, that for some reason machine.PWM isn't letting me stop the motor.

For hardware, I have a motor driver chip with PWM input on IO27 and IO10. Here is the motor driver's datasheet: https://fscdn.rohm.com/en/products/data ... aefj-e.pdf

For some reason, I can initialize both pins and the motor will stay stopped (correctly), but the moment I declare a PWM instance, it takes off moving (NOT desired :( )

Code: Select all

>>> from machine import Pin, PWM
>>> io10 = Pin(10, Pin.OUT, Pin.PULL_DOWN, value=0)
>>> io27 = Pin(27, Pin.OUT, Pin.PULL_DOWN, value=0)
>>> m0 = PWM(io27, duty=0, freq=500)    # The moment this line is entered, the device takes off and I have to power it off to avoid it inplugging itself!
>>> 
Does anyone have any ideas on how to fix this or find the cause? I have an ESP32-MINI-1 on a custom board running a custom build of MicroPython (custom only so it will boot single core, working on making the port official).

User avatar
OlivierLenoir
Posts: 126
Joined: Fri Dec 13, 2019 7:10 pm
Location: Picardie, FR

Re: machine.PWM with duty=0 not staying low

Post by OlivierLenoir » Mon Jul 18, 2022 7:08 pm

IN1 and IN2 need to be both Low for stop or both Hight for STOP. Page 4/15 of the datasheet.

Code: Select all

from machine import Pin, PWM
m0 = PWM(Pin(10))
m1 = PWM(Pin(27))

m0.duty_u16(0)
m1.duty_u16(0)

m0.freq(500)
m1.freq(500)

AwesomeCronk
Posts: 33
Joined: Fri Oct 11, 2019 1:24 am

Re: machine.PWM with duty=0 not staying low

Post by AwesomeCronk » Tue Jul 19, 2022 12:28 pm

So then why, when both pins were initialized to low, does the PWM object, when initialized to duty=0, not go to duty=0?

User avatar
OlivierLenoir
Posts: 126
Joined: Fri Dec 13, 2019 7:10 pm
Location: Picardie, FR

Re: machine.PWM with duty=0 not staying low

Post by OlivierLenoir » Wed Jul 20, 2022 5:41 am

AwesomeCronk wrote:
Tue Jul 19, 2022 12:28 pm
So then why, when both pins were initialized to low, does the PWM object, when initialized to duty=0, not go to duty=0?
In your code, I just see the initialization of m0. It's maybe the reason why the motor were not stop.
Hopping this helps. :D

AwesomeCronk
Posts: 33
Joined: Fri Oct 11, 2019 1:24 am

Re: machine.PWM with duty=0 not staying low

Post by AwesomeCronk » Fri Jul 22, 2022 8:26 pm

I'll be honest I have no idea what happened but it works now. I built a newer version of MicroPython and flashed it, now the original code works. I'm so lost.

Post Reply