​ ​ ​ ​ TB6612 Motor Control
Results 1 to 4 of 4

Thread: TB6612 Motor Control

  1. #1
    Senior Member
    Join Date
    Jul 2014
    Location
    Earth - United States - Nevada - Las Vegas
    Posts
    115

    Default TB6612 Motor Control

    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 by SolidWorksMagi; 31-07-2018 at 19:18.

  2. #2
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    24,438

    Default

    Quote Originally Posted by SolidWorksMagi View Post
    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.

  3. #3
    Senior Member
    Join Date
    Jul 2014
    Location
    Earth - United States - Nevada - Las Vegas
    Posts
    115

    Default

    Quote Originally Posted by hippy View Post
    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

  4. #4
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    24,438

    Default

    Glad it's working. The PWMOUT parameters aren't quite correct the command should be -

    PWMOUT pin, period, duty

    With the duty value varying between 0 and '4 x period' for maximum speed.

    http://www.picaxe.com/BASIC-Commands...tOutput/pwmout
    Last edited by hippy; 01-08-2018 at 12:05.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •