Controlling brushed motors with PWM

Discussion related to "under the hood" OpenMV topics.
User avatar
sergeyzwezdin
Posts: 8
Joined: Wed May 24, 2017 11:56 pm
Location: Chelyabinsk, Russia
Contact:

Controlling brushed motors with PWM

Postby sergeyzwezdin » Tue Jul 18, 2017 7:59 am

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?
User avatar
kwagyeman
Posts: 4658
Joined: Sun May 24, 2015 2:10 pm

Re: Controlling brushed motors with PWM

Postby kwagyeman » Tue Jul 18, 2017 12:27 pm

Ibrahim, can you help out on this?
Nyamekye,
User avatar
iabdalkader
Posts: 1245
Joined: Sun May 24, 2015 3:53 pm

Re: Controlling brushed motors with PWM

Postby iabdalkader » Tue Jul 18, 2017 1:10 pm

Hi, yes I'll debug this and get back to you.
User avatar
sergeyzwezdin
Posts: 8
Joined: Wed May 24, 2017 11:56 pm
Location: Chelyabinsk, Russia
Contact:

Re: Controlling brushed motors with PWM

Postby sergeyzwezdin » Wed Jul 19, 2017 2:33 am

Hi!
Any luck with it yet?
melofon
Posts: 5
Joined: Wed May 10, 2017 6:47 am
Location: Moscow, Russia

Re: Controlling brushed motors with PWM

Postby melofon » 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).
User avatar
iabdalkader
Posts: 1245
Joined: Sun May 24, 2015 3:53 pm

Re: Controlling brushed motors with PWM

Postby iabdalkader » Wed Jul 19, 2017 9:52 am

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 6731 times
I don't have a motor to test, but it seems the cam is doing exactly what you want.
User avatar
sergeyzwezdin
Posts: 8
Joined: Wed May 24, 2017 11:56 pm
Location: Chelyabinsk, Russia
Contact:

Re: Controlling brushed motors with PWM

Postby sergeyzwezdin » Wed Jul 19, 2017 11:34 am

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.
User avatar
sergeyzwezdin
Posts: 8
Joined: Wed May 24, 2017 11:56 pm
Location: Chelyabinsk, Russia
Contact:

Re: Controlling brushed motors with PWM

Postby sergeyzwezdin » Wed Jul 19, 2017 11:34 am

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.
User avatar
deshipu
Posts: 74
Joined: Sat Jan 09, 2016 5:36 am
Location: Zürich
Contact:

Re: Controlling brushed motors with PWM

Postby deshipu » 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?
User avatar
sergeyzwezdin
Posts: 8
Joined: Wed May 24, 2017 11:56 pm
Location: Chelyabinsk, Russia
Contact:

Re: Controlling brushed motors with PWM

Postby sergeyzwezdin » Fri Aug 11, 2017 1:55 am

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.

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest