Controlling brushed motors with PWM


I’m trying to control brushed motor with OpenMV’s PWM and getting wierd result.

Wiring scheme is following:
TB6612FNG dirvier used as a motor driver. There are two pins to define mode and another one for PWM. Mode pins connected to P8 and P9 OpenMV’s pin. P7 pin connected to driver’s PWM pin.

Test program is:

from pyb import Pin, Timer

m1_1 = Pin('P8', Pin.OUT_PP)
m1_2 = Pin('P9', Pin.OUT_PP)

m1_tm = Timer(4, freq=488.28)
m1_pwm =, m1_tm.PWM, pin=Pin.board.P7, pulse_width_percent=50)

With this code I getting this result:

Why it moves intermittently? Same setup with arduino doing slow smooth moving (at exactly same hardware).
Any ideas?

Ibrahim, can you help out on this?

Hi, yes I’ll debug this and get back to you.

Any luck with it yet?

I would suggest using machine module in micropython - Haven’t had such experience yet, hope this thing works well with openMV. The plan is to test it maybe tomorrow (my robot is not ready yet).


I tested your code with no changes (only added a loop after the code) it generates ~488MHz on pin P7 and P8 is high, and P9 is low:
I don’t have a motor to test, but it seems the cam is doing exactly what you want.

Yep, OpenMV works properly here. It seems problem with motor driver. I’ll investigate it a bit more.
Thank you for your help and sorry for bothering.

“machine.PWM” is not available on OpenMV, so no way to use it directly.

One possible difference is that Arduino UNO is 5V, whicle OpenMV is 3.3V — perhaps your motor driver expects 5V signal?

In my case the root casus was broken driver.