TB6612FNG from SparkFun ... Can't get it to drive a small 5V DC Motor ???

SolidWorksMagi

Senior Member
Hi,

My motor runs fine plugged directly into the 5V power source, but the motor doesn't run connected to the SparkFun TB6612FNG Motor Driver board.

I've tried this with and without the STBY connected to a PICAXE PIN ... trying to run it high and low.

Here is my program so far ... as you can see it is talking to me as it moves through the program so I know exactly what should be happening at each event.

Code:
#picaxe 28X2   ; Define the µProcessor a PICAXE 28X2 module

symbol PWMA = B.0  ; Right Motor Speed Control
symbol PWMB = B.1  ; Left  Motor Speed Control

symbol AIN1 = A.0  ; Forward Direction Control
symbol AIN2 = A.1  ; Reverse Direction Control

symbol BIN1 = A.2  ; Forward Direction Control
symbol BIN2 = A.3  ; Reverse Direction Control

symbol STBY = B.3  ; HIGH Allows the H-Bridge to Operate
;                    w/a 1K? Ohm PullDown Resistor 

symbol BLED = B.5  ; Red   LED
symbol GLED = B.6  ; Green LED
symbol RLED = B.7  ; Blue  LED

init: servo PWMA,50
      servo PWMB,50

; hserout PIN 11 = C.6
hsersetup B9600_8, %00000	; 9600 baud, non-inverted polarity

symbol i = b0

; BEGIN Main Body * * * * * * * * * * * * * * *
;high AIN1
;low  AIN2
;high BIN1
;low  BIN2
;pulsout PWMA, 500
;pulsout PWMB, 500

do

; Testing Motor A Forward
; Testing , Motor , A , Forward 
hserout 0,(20, 96, 21, 114, 22, 88, 23, 5, 191, 131, 8, 187, 191, 129, 143, 2, 140, 137, 191, 7, 151, 2, 154, 128, 2, 186, 7, 153, 7, 147, 151, 176)

;high STBY
high AIN1
low  AIN2
; high PWMA

pause 5000

for i = 0 to 50
servopos PWMA, 150
pause 20
next i

; Testing Motor A Reverse
; Testing , Motor , A , \RR \IY \VV \RR \Slow \Slow \SE 
hserout 0,(20, 96, 21, 114, 22, 88, 23, 5, 191, 131, 8, 187, 191, 129, 143, 2, 140, 137, 191, 7, 151, 2, 154, 128, 2, 148, 128, 166, 148, 8, 8, 187)

;high STBY
low AIN1
high  AIN2
; high PWMA

for i = 0 to 50
servopos PWMA, 150
pause 20
next i

pause 5000

; Testing Motor B Forward
; Testing , Motor , B , Forward 
hserout 0,(20, 96, 21, 114, 22, 88, 23, 5, 191, 131, 8, 187, 191, 129, 143, 2, 140, 137, 191, 7, 151, 2, 170, 128, 128, 2, 186, 7, 153, 7, 147, 151, 176)

;high STBY
high BIN1
low  BIN2
; high PWMB

for i = 0 to 50
servopos PWMB, 150
pause 20
next i

pause 5000

; Testing Motor B Reverse
; Testing , Motor , B , \RR \IY \VV \RR \Slow \Slow \SE 
hserout 0,(20, 96, 21, 114, 22, 88, 23, 5, 191, 131, 8, 187, 191, 129, 143, 2, 140, 137, 191, 7, 151, 2, 170, 128, 128, 2, 148, 128, 166, 148, 8, 8, 187)

;high STBY
high AIN1
low  AIN2
; high PWMB

for i = 0 to 50
servopos PWMB, 150
pause 20
next i

pause 5000

loop
; END Main Body * * * * * * * * * * * * * * * *
end


The logic table for the Motor Driver Board;


;  In1  In2  PWM  Out1  Out2  Mode
;  H     H    H/L     L       L       Short brake
;  L     H     H       L       H       CCW
;  L     H     L        L       L       Short brake
;  H     L     H       H       L       CW
;  H     L     L       L        L       Short brake
;  L     L     H       OFF   OFF    Stop


I even got this help from another post that say's this setup works ... but it's not working for me.
;high AIN1
;low  AIN2
;high BIN1
;low  BIN2
;pulsout PWMA, 500
;pulsout PWMB, 500
I've double checked the wiring a couple of times now and disconnected the STBY jumper wire for the last failing tests.

The only connections on the SparkFun TB6612FNG Motor Driver board not being used are the three BO2, B0! and GND on that half of the board and GND on the other half of the board.

In the program you can see the commented out high PWMA etc... as I did try that too.

I am planning to run two motors later once I have a good working setup so the B motor wiring is in place from the PICAXE 28X2 module.
 
Last edited by a moderator:

stan74

Senior Member
looks like a h-bridge with pwm enable thingy from your info. Try just connecting the inputs to 5V and ground with probably enable to 5v and test out put first so you know device is ok maybe.
 

AllyCat

Senior Member
Hi,

Code:
symbol STBY = B.3  ; HIGH Allows the H-Bridge to Operate

; high STBY
; high PWMA

servopos PWMA, 150

hserout 0,(20, 96, 21, 114, 22, 88, 23, 5, 191, 131, 8, 187, 191, 129, 143, 2, 140, 137, 191, 7, 151, 2, 154, 128, 2, 148, 128, 166, 148, 8, 8, 187)
It's difficult to see what your program is supposed to do, with so much "commented out". The parts quoted above confuse me:

If "STBY High" does enable the chip, why are the High STBYs commented out?

Why do the HSEROUT commands include non-printable "ASCII" codes?

But in particular, you appear to be using "Servo" commands to drive the PWM inputs. However, servo pulses are only around 7% duty cycle, probably far too short to drive a 5 volt motor from 5v.

Cheers, Alan.
 

SolidWorksMagi

Senior Member
Okay, here's the meat of the program I have;
Code:
symbol PWMA = B.0  ; Right Motor Speed Control

symbol AIN1 = A.0  ; Forward Direction Control
symbol AIN2 = A.1  ; Reverse Direction Control

init: servo PWMA,50

symbol i = b0

do
high AIN1
low  AIN2
for i = 0 to 50
pulsout PWMA, 50
;servopos PWMA, 150
pause 20
next i
loop
I get no motor movement using servopos or pulsout commands ...
 
Last edited by a moderator:

premelec

Senior Member
Servo command seems inappropriate - use PWMOUT. Also just test the setup with DC signals in. Review Alan's post above...

FROM SPARKFUN:
"The TB6612FNG Motor Driver can control up to two DC motors at a constant current of 1.2A (3.2A peak). Two input signals (IN1 and IN2) can be used to control the motor in one of four function modes: CW, CCW, short-brake, and stop. The two motor outputs (A and B) can be separately controlled, and the speed of each motor is controlled via a PWM input signal with a frequency up to 100kHz. "
 
Last edited:

hippy

Technical Support
Staff member
A link to the datasheet always helps. It seems to be this for Googling ...

https://www.pololu.com/file/0J86/TB6612FNG.pdf

That appears to be a Dual H-Bridge, and from Page 4 ...

IN1=H, IN2=L, PWM=H, STBY=H : Counter-clockwise
IN1=L, IN2=H, PWM=H, STBY=H : Clockwise
IN1=L, IN2=L, PWM=H, STBY=H : Stopped

So, first thing to try is ...

Code:
Do
  Gosub CounterClockwise : Pause 1000
  Gosub Stopped          : Pause 1000
  Gosub Clockwise        : Pause 1000
  Gosub Stopped          : Pause 3000
Loop

CounterClockwise:
  ; IN1=H, IN2=L, PWM=H, STBY=H : Clockwise
  High AIN1
  Low  AIN2
  High PWMA
  High STBY
  Return

Clockwise:
  ; IN1=L, IN2=H, PWM=H, STBY=H : Clockwise
  Low  AIN1
  High AIN2
  High PWMA
  High STBY
  Return

Stopped:
  ; IN1=L, IN2=L, PWM=H, STBY=H : Stopped
  Low  AIN1
  Low  AIN2
  High PWMA
  High STBY
  Return
If that doesn't work then there is some wiring or connection issue, or the driver board is faulty.

Perhaps detail all the connections made to the TB6612FNG board. Posting a photo may help.
 

AllyCat

Senior Member
Hi,

Okay, here's the meat of the program I have;
I don't see a High STBY in that code. The Sparkfun data seems quite specific that STBY should be High. [ To be fair, STandBY seems a poor name for that pin; signals are normally considered to specify the Active (High) condition (e.g. Standby = "Save Power"), so it would be better named as ENABLE, or similar. ]

Also, your PULSOUT 50 will give a pulse of 500 us (i.e. 0.5 ms), then you have a 20 ms gap (i.e. a 2.5% duty cycle), which is even less likely to drive the motor at any speed than the servo pulse.

What happens if you set STBY and PWMA both to High?

Cheers, Alan.
 

stan74

Senior Member
https://www.sparkfun.com/products/9457 Motor and the controller need separate supplies.
As Alan says tie pwm and stby high so it's on.
If input a is hi and b low, motor clockwise
if input a is low and b high, motor anti clockwise
a and b low motor off
a and b high motor brake
just connect inputs to 5v and 0v to test first.
 

erco

Senior Member
Per others, don't even try PWM until you get the motors working with simple highs and low commands. I've used this chip previously without incident using a single supply. Single supply shown in app notes at https://learn.sparkfun.com/tutorials/tb6612fng-hookup-guide Look at at that guide and double check all wiring, then accept the possibility that the H bridge is damaged, either from the manufacturer or being hooked up wrong. One brief wrong connection can blow the chip, either polarity or overvoltage.
 

SolidWorksMagi

Senior Member
Hi,

Gave it another try ... I moved each section into its own subroutine ... but STBY HIGH and PWMA HIGH doesn't spin the motor.

AFWD:
; Testing Motor A Forward
; Testing , Motor , A , Forward
hserout 0,(20, 96, 21, 114, 22, 88, 23, 5, 191, 131, 8, 187, 191, 129, 143, 2, 140, 137, 191, 7, 151, 2, 154, 128, 2, 186, 7, 153, 7, 147, 151, 176)

high STBY
high AIN1
low AIN2
high PWMA

pause 5000

;for i = 0 to 50
;pulsout PWMA, 50
;servopos PWMA, 150
;pause 20
;next i
return
 

SolidWorksMagi

Senior Member
Hi,

I recreated the logic table as quotes in the program for reference, but I'm not getting any motor spin unless I just connect to motor to 5V & GND. I do have 5V going to the VM PIN on the motor driver. I have the two wires from the 5V DC motor going to the A01 and A02 pins on the motor driver.

I've tried HIGH PWMA to turn the motor ON and I've tried pulsout PWMA, 50 to 50000 still no motor spin ???

AFWD:
; Testing Motor A Forward

high STBY
high AIN1
low AIN2

pause 5000

for i = 0 to 50
pulsout PWMA, 50000
next i
return
 

SolidWorksMagi

Senior Member
Hi,

I don't think the chip has blown. I triple check wiring all the time before adding power to a circuit, and nothing has even gotten warm yet.

The +5V power to the board is on the Vcc pin and the Vm pin so the motor has power.
 

premelec

Senior Member
And hopefully the V- pins are tied together ;-0 You may have to post a picture of your actual setup for further input here...
 

hippy

Technical Support
Staff member
You may have to post a picture of your actual setup for further input here...
There doesn't seem many other options apart from connecting the inputs to the driver board direct to 0V and 5V as already suggested. If you can't make it work hard-wired it isn't going to work when connected to a PICAXE.
 

SolidWorksMagi

Senior Member
This does not work ... I am beginning to think the board does not work. I bought two boards, I guess I need to solder the jumper wires onto the other board for testing too.

high STBY
; Logic from the SparkFun Connect webpage
; In1 In2 PWM Out1 Out2 Mode
; H L H H L CW
high AIN1
low AIN2
high PWMA
high BIN1
low BIN2

Bottom of the driver board: http://brainless.org/OtherStuff/TB6612FNG-MotorDriver-WIN_20170930_06_33_42_Pro.jpg

Top of the driver board: http://brainless.org/OtherStuff/TB6612FNG-MotorDriver-WIN_20170930_06_34_28_Pro.jpg

Most of the connections to the PICAXE 28X2 module on a RoboGuts circuit board: http://brainless.org/OtherStuff/TB6612FNG-MotorDriver-WIN_20170930_06_34_54_Pro.jpg

Red Power and Black Ground connections on a RoboGuts circuit board: http://brainless.org/OtherStuff/TB6612FNG-MotorDriver-WIN_20170930_06_36_50_Pro.jpg
 

Attachments

Last edited:

AllyCat

Senior Member
Hi,

One brief wrong connection can blow the chip, either polarity or overvoltage.
Bear in mind that it's very easy to create "overvoltage", simply by breaking the current flow in an inductor (such as a motor). Also, we haven't been told anything about the motor (except that it's 5v), what are its specified "running" and "stall" currents (the latter can be estimated from its dc resistance).

Do you have a multimeter? If not, a simple "Logic Level Tester" could be made from a LED and a resistor. But there's really not much more help we can give when (on the information given) it should now be working.

Cheers, Alan.
 

newplumber

Senior Member
Hi solidworksmagi
Its probably something simple :) when I tried running electric motors my power supply would drop Volts causing the picaxe to restart
so I made a simple code before running "main" code like

Code:
for b3 = 0 to 4 
high B.7 ; b.7 would have a led with a resistor to ground 
pause 500
low B.7 
pause 500 
next 
; then it run the main program like etc 
Main:
it would show me if the picaxe would restart while running the main code
of course its probably not your problem here...just my two cents

EDIT: Opps i missed the first post of talking back thru code so my two cents dropped to .5 cents :)
 

SolidWorksMagi

Senior Member
Hi,

There is a good solder joint on all connections. I've tested with a DMM from board to end of cables.

The power supply is the 7V ac wallwart/adapter regulated down to 5V by the PICAXE 28X2. IF I move the motor wires to the +5 and GND from that point the motor spins fast.

I'm not losing power from the small current draw of this circuit.
 

RexLan

Senior Member
Hi,

There is a good solder joint on all connections. I've tested with a DMM from board to end of cables.

The power supply is the 7V ac wallwart/adapter regulated down to 5V by the PICAXE 28X2. IF I move the motor wires to the +5 and GND from that point the motor spins fast.

I'm not losing power from the small current draw of this circuit.
How does the Picaxe "regulate down" the supply voltage???

The plot thickens ....
 

hippy

Technical Support
Staff member
Most of the connections to the PICAXE 28X2 module on a RoboGuts circuit board: http://brainless.org/OtherStuff/TB6612FNG-MotorDriver-WIN_20170930_06_34_54_Pro.jpg

Red Power and Black Ground connections on a RoboGuts circuit board: http://brainless.org/OtherStuff/TB6612FNG-MotorDriver-WIN_20170930_06_36_50_Pro.jpg
Neither of those photos are particularly useful seeing as it's not easy to see where the wires connect to and between, or immediately know what the pins are on your board.

It really would be best to put the PICAXE board to one side, hard-wire the motor driver board inputs and try and get it to work that way. It shouldn't be too hard seeing as it's all connected by jumper leads.

If you are absolutely convinced it is all wired correctly, are convinced the code you have will work and should work, then the logical conclusion would be that it's a dead or damaged board.
 

SolidWorksMagi

Senior Member
Hi,

Soldering wires to the 2nd board and making all the connections to the RoboGuts circuit board and motor the program works. It seems may have gotten a dead driver board. I'm going to look into it a little more.
 

SolidWorksMagi

Senior Member
Hi,

Current problem now is getting the PWMA to control the motor. I've tried pulsout PWMA, 50 and that didn't work, then 150, then I stepped from 0 to 250 still the motor doesn't turn.

The motor I'm using is one of those small $3 eBay hand held drills; WIN_20170930_13_11_35_Pro.jpg = 23mm diameter and 115mm base to tip ...

Later this will move to a Gakken Centipede and another to a 2' long (originally an R/C army tank) with bigger motors.
 

SolidWorksMagi

Senior Member
Hi,

Found a cold-solder joint on A01 ... the solder joint looks good, when I tested it with the meter the connection was there, but I went through the pins again and found it open, I re-soldered the wire and the driver is working.

pulsout PWMA, 2000 or more spins the motor from slow to faster ... Now I have a solution. When I clean up the program I'll post the full solution here and on my website in the PICAXE 28X2 lessons; http://www.r2pv1.com/


Thanks for the help people!
 
Last edited:

SolidWorksMagi

Senior Member
Okay, final tests work great ...
Code:
#picaxe 28X2   ; Define the µProcessor IC Type

;         PICAXE 28X2 Module            |  TB6612FNG 1A Dual Motor Driver
; PIN                PIN                |
;  1  = A4             28 = Vin (7-12V) |        PWMA     VM
;  2  = Serial IN      27 = 0v          |
;  3  = LED            26 = Reset       |        AIN2     Vcc
;  4  = 0V             25 = +5V         |        AIN1     GND
;  5  = C.0            24 = B.7         |
;  6  = C.1            23 = B.6         |        STBY     A01    
;  7  = C.2            22 = B.5         |
;  8  = C.3            21 = B.4         |        BIN1     A02    
;  9  = C.4            20 = B.3         |        BIN2     B02    
;  10 = C.5            19 = B.2         |
;  11 = C.6 hserout    18 = B.1         |        PWMB     B01    
;  12 = C.7            17 = B.0         |
;  13 = A.0            16 = A.2         |        GND      GND    
;  14 = A.1            15 = A.3         |



;  In1  In2  PWM  Out1  Out2  Mode
;  H    H    H/L  L     L     Short brake
;  L    H    H    L     H     CCW
;  L    H    L    L     L     Short brake
;  H    L    H    H     L     CW
;  H    L    L    L     L     Short brake
;  L    L    H    OFF   OFF   Stop

symbol PWMA = B.0  ; Right Motor Speed Control
symbol PWMB = B.1  ; Left  Motor Speed Control

symbol AIN1 = A.0  ; Forward Direction Control
symbol AIN2 = A.1  ; Reverse Direction Control

symbol BIN1 = A.2  ; Forward Direction Control
symbol BIN2 = A.3  ; Reverse Direction Control

symbol STBY = B.3  ; HIGH Allows the H-Bridge to Operate

symbol BLED = B.5  ; Red   LED
symbol GLED = B.6  ; Green LED
symbol RLED = B.7  ; Blue  LED

init: servo PWMA,50
      servo PWMB,50

; hserout PIN 11 = C.6 tied to a SpeakJet chip
hsersetup B9600_8, %00000    ; 9600 baud, non-inverted polarity

symbol i = b0

; BEGIN Main Body * * * * * * * * * * * * * * *
do
gosub AFWD
pause 2000
gosub ABAK
pause 2000
loop
; END Main Body * * * * * * * * * * * * * * * *
end

; BEGIN MOTOR Subroutines * * * * * * * * * * * * * * *
AFWD:
; Testing Motor A Forward 
; Testing , Motor , A , Forward 
hserout 0,(20, 96, 21, 114, 22, 88, 23, 5, 191, 131, 8, 187, 191, 129, 143, 2, 140, 137, 191, 7, 151, 2, 154, 128, 2, 186, 7, 153, 7, 147, 151, 176)
pause 3000

for i = 0 to 14
high STBY
high AIN1
low  AIN2
pause 100
pulsout PWMA, 10000
next i
low STBY
return

ABAK:
; Testing Motor A Reverse
; Testing , Motor , A , \RR \IY \VV \RR \Slow \Slow \SE 
hserout 0,(20, 96, 21, 114, 22, 88, 23, 5, 191, 131, 8, 187, 191, 129, 143, 2, 140, 137, 191, 7, 151, 2, 154, 128, 2, 148, 128, 166, 148, 8, 8, 187)
pause 3000

for i = 0 to 14
high STBY
low AIN1
high  AIN2
pause 100
pulsout PWMA, 10000
next i
low STBY
return
; END MOTOR Subroutines * * * * * * * * * * * * * * *
; END Subroutines * * * * * * * * * * * * * * * *
end
 
Last edited by a moderator:

stan74

Senior Member
You need this sort of code for pwm to 2 motors
set up pwm-
pwmout pwmdiv16, C.1,124,0 ; 1000Hz @ 8MHz left motor
pwmout pwmdiv16, C.2,124,0 ; 1000Hz @ 8MHz right motor
and this to control h-bridge, port c1,c2 are pwm enable to enable pins on h bridge
motors_fullspeed:
pwmout pwmdiv16, C.1,124,499
pwmout pwmdiv16, C.2,124,499
pwmduty C.1,499 ; motors
pwmduty C.2,499 ; full
return
motors_slow:
pwmduty C.1,299 ; motors
pwmduty C.2,299 ; 60%
pwmout pwmdiv16, C.1,124,299
pwmout pwmdiv16, C.2,124,299
return
rotate_clockwise:
high lmotordir ; left motor forward
low rmotordir ; right motor reverse
pwmout pwmdiv16, C.1,124,229
pwmout pwmdiv16, C.2,124,229
pwmduty C.2,299 ; right motor 60%
pwmduty C.1,299 ; left motor 60%
return
rotate_anticlockwise:
low lmotordir ; left motor reverse
high rmotordir ; right motor forward
pwmout pwmdiv16, C.1,124,299
pwmout pwmdiv16, C.2,124,299
pwmduty C.1,299 ; left motor 60%
pwmduty C.2,299 ; right motor 60%
return
 

SolidWorksMagi

Senior Member
Hi,

In your listing everything is tied to C.1 and C.2 ???

What are the connections?
PWMA to 28X2 C.1?
AIN2 to 28X2 ???
AIN1 to 28X2 ???
STBY to 28X2 ???
BIN1 to 28X2 ???
BIN2 to 28X2 ???
PWMB to 28X2 C.2?




You need this sort of code for pwm to 2 motors
set up pwm-
pwmout pwmdiv16, C.1,124,0 ; 1000Hz @ 8MHz left motor
pwmout pwmdiv16, C.2,124,0 ; 1000Hz @ 8MHz right motor
and this to control h-bridge, port c1,c2 are pwm enable to enable pins on h bridge
motors_fullspeed:
pwmout pwmdiv16, C.1,124,499
pwmout pwmdiv16, C.2,124,499
pwmduty C.1,499 ; motors
pwmduty C.2,499 ; full
return
motors_slow:
pwmduty C.1,299 ; motors
pwmduty C.2,299 ; 60%
pwmout pwmdiv16, C.1,124,299
pwmout pwmdiv16, C.2,124,299
return
rotate_clockwise:
high lmotordir ; left motor forward
low rmotordir ; right motor reverse
pwmout pwmdiv16, C.1,124,229
pwmout pwmdiv16, C.2,124,229
pwmduty C.2,299 ; right motor 60%
pwmduty C.1,299 ; left motor 60%
return
rotate_anticlockwise:
low lmotordir ; left motor reverse
high rmotordir ; right motor forward
pwmout pwmdiv16, C.1,124,299
pwmout pwmdiv16, C.2,124,299
pwmduty C.1,299 ; left motor 60%
pwmduty C.2,299 ; right motor 60%
return
 

inglewoodpete

Senior Member
Hi,

In your listing everything is tied to C.1 and C.2 ???

What are the connections?
PWMA to 28X2 C.1?
AIN2 to 28X2 ???
AIN1 to 28X2 ???
STBY to 28X2 ???
BIN1 to 28X2 ???
BIN2 to 28X2 ???
PWMB to 28X2 C.2?
Stan74 has posted (9 months ago!) some code snippets that could be used to control two robot traction motors. The snippets could be inserted or substituted into an existing program or be used as the basis of a new program. C.1 and C.2 are just the PWM (speed) outputs to the motor controller.

The other control pins need to be connected and codes to suit the motor controller interface.
 
Top