Page 1 of 1

Controlling brushed motors with PWM

Posted: Tue Jul 18, 2017 7:59 am
by sergeyzwezdin
Hello!

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:

Code: Select all

from pyb import Pin, Timer

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

m1_tm = Timer(4, freq=488.28)
m1_pwm = m1_tm.channel(1, m1_tm.PWM, pin=Pin.board.P7, pulse_width_percent=50)
With this code I getting this result: https://youtu.be/w19WEoutPcw

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

Re: Controlling brushed motors with PWM

Posted: Tue Jul 18, 2017 12:27 pm
by kwagyeman
Ibrahim, can you help out on this?

Re: Controlling brushed motors with PWM

Posted: Tue Jul 18, 2017 1:10 pm
by iabdalkader
Hi, yes I'll debug this and get back to you.

Re: Controlling brushed motors with PWM

Posted: Wed Jul 19, 2017 2:33 am
by sergeyzwezdin
Hi!
Any luck with it yet?

Re: Controlling brushed motors with PWM

Posted: Wed Jul 19, 2017 3:46 am
by melofon
I would suggest using machine module in micropython - https://docs.micropython.org/en/latest/ ... l/pwm.html. 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).

Re: Controlling brushed motors with PWM

Posted: Wed Jul 19, 2017 9:52 am
by iabdalkader
Hi,

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:
wave.png
wave.png (88.96 KiB) Viewed 6809 times
I don't have a motor to test, but it seems the cam is doing exactly what you want.

Re: Controlling brushed motors with PWM

Posted: Wed Jul 19, 2017 11:34 am
by sergeyzwezdin
iabdalkader wrote:
Wed Jul 19, 2017 9:52 am
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.

Re: Controlling brushed motors with PWM

Posted: Wed Jul 19, 2017 11:34 am
by sergeyzwezdin
melofon wrote:
Wed Jul 19, 2017 3:46 am
I would suggest using machine module in micropython - https://docs.micropython.org/en/latest/ ... l/pwm.html. 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).
"machine.PWM" is not available on OpenMV, so no way to use it directly.

Re: Controlling brushed motors with PWM

Posted: Thu Jul 27, 2017 5:11 pm
by deshipu
One possible difference is that Arduino UNO is 5V, whicle OpenMV is 3.3V — perhaps your motor driver expects 5V signal?

Re: Controlling brushed motors with PWM

Posted: Fri Aug 11, 2017 1:55 am
by sergeyzwezdin
deshipu wrote:
Thu Jul 27, 2017 5:11 pm
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.