Author Topic: how to control 2 dc motor using TB6612FNG motor driver  (Read 2700 times)

0 Members and 1 Guest are viewing this topic.

Offline aaa3aTopic starter

  • Full Member
  • ***
  • Posts: 53
  • Helpful? 1
    • Skype - CharlesgrareOB
how to control 2 dc motor using TB6612FNG motor driver
« on: May 12, 2012, 09:47:55 AM »
i'm using TB6612FNG driver to drive 2 DC motors with 2 pin configuration i've used the webbotlib example but i'm confused and can't understand the PWM function well and i want to use INA1,INA2 and IB1,IB2 instead of pwm so i can write my function with the truth table of the 4 pins or even some one explain the function in details as i'm new to programing with c++ also i want to make function called RobotMove defined as below

RobotMove (action , direction , distance , speed)

action: move,turn,stop,dance

direction: forward, backward, left, right

distance: in centimeter


when i've tried to make function go_forward()

the compiler makes error due to the isolation of drive_speed from the function and said unused funtion speed something like that

so if anyone can help me writing the code and if there is a way to write to those 4 pins directly using logic table instead of pwm
« Last Edit: May 13, 2012, 11:50:41 AM by aaa3a »

Offline mstacho

  • Supreme Robot
  • *****
  • Posts: 376
  • Helpful? 10
Re: how to control 2 dc motor using TB6612FNG motor driver
« Reply #1 on: May 14, 2012, 06:56:50 AM »
I don't really understand what you're asking about the RobotMove function.  Maybe post some code?

As for the motor driver: the beauty of PWM is that it IS digital logic, so you can use INA1 and INA2 hooked up to two PWM pins.  But you have to be a bit clever.  Here is some pseudo-code that works:

Let's say I have two PWM pins, PIN_A and PIN_B, and I set them like this: SET_PWM(PIN_A, PERCENT)

int DIRECTION = 1;

     DIRECTION = 0;

//then, just set both like this:


See what that does?  If I want to go one way, then DIRECTION = 1, 1-DIRECTION = 0, so PIN_A is set to zero and PIN_B is set to whatever I want.  If I want to go the other way, DIRECTION = 0, 1-DIRECTION = 1, so PIN_A is set to whatever and PIN_B is set to zero.

PWM is a bit hard to understand at first if you want to learn all the details, but the simple fact is: just set the PWM frequency to about 1000 and set the percentage to any value between 0 and 100 (or 0 and 1, depending on how the function works) and you're off to the races!

Current project: tactile sensing systems for multifingered robot hands


Get Your Ad Here