TB6612 Motor Control

SolidWorksMagi

Senior Member
Hi,

I can make two motors run, but how do I make the two motors run simultaneously to drive straight forward or backwards?

; 28X2+TB6612FNG+2Motors.bas

#picaxe 28X2

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

symbol STBY = C.0 ; B.2 HIGH Allows the H-Bridge to Operate

symbol AIN1 = C.3 ; B.3 Direction Control
symbol AIN2 = C.4 ; B.4 Direction Control

symbol BIN1 = C.5 ; B.5 Direction Control
symbol BIN2 = C.7 ; B.6 Direction Control

symbol Speed = w2

do
Speed = 65000
gosub FWD
loop
end

FWD:
high STBY ;. . . . . . ; C.0
pulsout PWMA, Speed ;.; 'C.2
pulsout PWMB, Speed ;.; 'C.1
low AIN1 ;. . . . . . .; C.3
high AIN2 ;. . . . . .; C.4
high BIN1 ;. . . . . . ; C.5
low BIN2 ;. . . . . . ; C.7
return
end


I also tried;

#picaxe 28X2

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

symbol STBY = C.0 ; B.2 HIGH Allows the H-Bridge to Operate

symbol AIN1 = C.3 ; B.3 Direction Control
symbol AIN2 = C.4 ; B.4 Direction Control

symbol BIN1 = C.5 ; B.5 Direction Control
symbol BIN2 = C.7 ; B.6 Direction Control

symbol Speed = w2

Speed = 65000
gosub FWD

do
pulsout PWMA, Speed ;.; 'C.2
pulsout PWMB, Speed ;.; 'C.1
loop
end

FWD:
high STBY ;. . . . . . ; C.0
low AIN1 ;. . . . . . .; C.3
high AIN2 ;. . . . . .; C.4
high BIN1 ;. . . . . . ; C.5
low BIN2 ;. . . . . . ; C.7
return
end

Still, only one motor turns ON at a time ???
 
Last edited:

hippy

Technical Support
Staff member
I can make two motors run, but how do I make the two motors run simultaneously to drive straight forward or backwards?
I would have thought it were a simple matter of setting one of AIN1 and AIN2 high and the other low to make one motor turn in the desired direction, and then doing the same for BIN1 and BIN2 for the other motor. As to what settings those would be it would depend on how you have the motors wired and mechanically attached. You would need to experiment but it seems there's only two possibilities.

Then set the speed of each motor the same. I would have expected to see two PWMOUT commands to set the speed rather than PULSOUT.
 

SolidWorksMagi

Senior Member
I would have thought it were a simple matter of setting one of AIN1 and AIN2 high and the other low to make one motor turn in the desired direction, and then doing the same for BIN1 and BIN2 for the other motor. As to what settings those would be it would depend on how you have the motors wired and mechanically attached. You would need to experiment but it seems there's only two possibilities.

Then set the speed of each motor the same. I would have expected to see two PWMOUT commands to set the speed rather than PULSOUT.


Hi, Switching to PWMOUT fixed the problem! Thanks again hippy! You're a project saver!


Here is the code for the tests that is working!

#picaxe 28X2

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

symbol STBY = C.0 ; B.2 HIGH Allows the H-Bridge to Operate

symbol AIN1 = C.3 ; B.3 Direction Control
symbol AIN2 = C.4 ; B.4 Direction Control

symbol BIN1 = C.5 ; B.5 Direction Control
symbol BIN2 = C.7 ; B.6 Direction Control

symbol Speed = w2

Speed = 65000
gosub FWD

do
pwmout PWMA, 100, Speed ;.; 'C.2
pwmout PWMB, 100, Speed ;.; 'C.1
loop
end

FWD:
high STBY ;. . . . . . ; C.0
low AIN1 ;. . . . . . .; C.3
high AIN2 ;. . . . . .; C.4
high BIN1 ;. . . . . . ; C.5
low BIN2 ;. . . . . . ; C.7
return
end
 
Top