WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

Toshiba/TB6612FNG.h

Controls two DC motors connected to the TB6612FNG motor driver using pulse width modulation (PWM).
The device requires two power supplies:
Vcc powers the 'on-board' logic and should be in the range 2.7v to 5.5v
VM is used to drive the motors and should be in the range 4.5v to 13.5v (check what voltage your motors need) and can supply 1.2 amps per motor.
The device is a 'surface mount' device so I have used the breakout board available from Pololu:
http://www.pololu.com/catalog/product/713/resources
This device is also sold by outlets such as SparkFun and ActiveRobots.
PololuTB6612FNG.jpg
The breakout board comes with header pins for use with a bread board and must be soldered on. Alternatively: for use in a finished robot you can just solder your wires directly to the board. The board also comes with some capacitors and reverse voltage protection for the motor supply.
I have supplied two different software drivers for this board:
TB6612FNG_2pin.h requires two PWM signals per motor. On microprocessors such as the ATMega168 this will mean that the driver will use up Timer 0 and Timer 2. So it really eats into your available timers.
TB6612FNG_3pin.h only requires one PWM signal per motor but requires two digital output pins per motor as well.
TB6612FNG.jpg
The 'STBY' pin can be connected to a digital output pin to put the device into 'stand by' mode. I don't support this directly in the library but if you wish to add to utilise this feature then connect it to any output pin and pull the pin low to put the device into standby or high to enable the device.
NB If you don't want to make use of the standby feature then you must connect the STBY pin to Vcc.
3 Pin
To use the 3 pin driver then you will need to connect the device as follows:
Connect the 5v regulated supply from your micro controller to the Vcc pin
Connect the ground from your micro controller to the GND pin
Connect your motor supply (+ve) to VMOT and the ground wire to GND.
Connect the STBY pin to Vcc if you are not using an output pin to set the controller to standby mode.
DC Motor 1 should be connected to the AO1 and AO2 pins and DC Motor 2 should be connected to the BO1 and BO2 pins.
AIN1 and AIN2 should be connected to +5v digital output pins on your micro controller and PWMA should be connected to one of the PWM output pins on your micro controller. These three pins will be used to control motor 1.
BIN1 and BIN2 should be connected to +5v digital output pins on your micro controller and PWMB should be connected to one of the PWM output pins on your micro controller. These three pins will be used to control motor 2.
Here is an example of how you could define two motors on the Axon:-
#include <Motors/Toshiba/TB6612FNG.h>
TOSHIBA_TB6612FNG_3pin_MOTOR left = MAKE_TOSHIBA_TB6612FNG_MOTOR_3pin(FALSE,E3,F0,F1);
TOSHIBA_TB6612FNG_3pin_MOTOR right = MAKE_TOSHIBA_TB6612FNG_MOTOR_3pin(TRUE,E4,F2,F3);
TOSHIBA_TB6612FNG_3pin_MOTOR_LIST PROGMEM motors[] = {&left, &right};
TOSHIBA_TB6612FNG_3pin_MOTOR_DRIVER driver = MAKE_TOSHIBA_TB6612FNG_3pin_MOTOR_DRIVER(motors);
void appInitHardware(void){
    // Init driver to use a 5kHz PWM signal
    toshibaTB6612FNG_3pin_Init(&driver, 5000);
}
2 Pin
To use the 2 pin driver then you will need to connect the device as follows:
Connect the 5v regulated supply from your micro controller to the Vcc pin
Connect the ground from your micro controller to the GND pin
Connect your motor supply (+ve) to VMOT and the ground wire to GND.
Connect the STBY pin to Vcc if you are not using an output pin to set the controller to standby mode.
DC Motor 1 should be connected to the AO1 and AO2 pins and DC Motor 2 should be connected to the BO1 and BO2 pins.
Connect PWMA to Vcc. AIN1 and AIN2 should be connected to two PWM output pins on your micro controller and these two pins will be used to control motor 1.
Connect PWMB to Vcc. BIN1 and BIN2 should be connected to two PWM output pins on your micro controller and these two pins will be used to control motor 2.
Here is an example of how you could define one motor on the Axon:-
#include <Motors/Toshiba/TB6612FNG.h>
TOSHIBA_TB6612FNG_2pin_MOTOR left = MAKE_TOSHIBA_TB6612FNG_MOTOR_2pin(FALSE,E3,E4);
TOSHIBA_TB6612FNG_2pin_MOTOR_LIST PROGMEM motors[] = {&left};
TOSHIBA_TB6612FNG_2pin_MOTOR_DRIVER driver = MAKE_TOSHIBA_TB6612FNG_2pin_MOTOR_DRIVER(motors);
void appInitHardware(void){
    // Init driver to use a 5kHz PWM signal
    toshibaTB6612FNG_2pin_Init(&driver,5000);
}
Common
Whether you are using the 2pin or 3pin the remaining code remains the same. You can use act_SetSpeed to set the speed of the motor.

 

Function

 


MAKE_TOSHIBA_TB6612FNG_MOTOR_3pin(inverted, pwm, enable1, enable2)

Create a motor using the 3 pin connection method.
The first pin must be a PWM output pin, whereas the remaining two pins can be any output pins.
Example on the Axon:
TOSHIBA_TB6612FNG_3pin_MOTOR motor = MAKE_TOSHIBA_TB6612FNG_MOTOR_3pin(FALSE, E3, F0, F1);
If this is being used to control motor 1 then E3 is connected to PWMA, F0 is connected to AIN1, F1 is connected to AIN2. For motor2 then E3 is connected to PWMB, F0 is connected to BIN1, F1 is connected to BIN2.

MAKE_TOSHIBA_TB6612FNG_3pin_MOTOR_DRIVER(motorlst)

Create the driver to control a list of 3 pin motors.
TOSHIBA_TB6612FNG_3pin_MOTOR_LIST PROGMEM motors[] = { &motor1, &motor2 }; // as many as you like
TOSHIBA_TB6612FNG_3pin_MOTOR_DRIVER driver = MAKE_TOSHIBA_TB6612FNG_3pin_MOTOR_DRIVER(motors);

toshibaTB6612FNG_3pin_Init( TOSHIBA_TB6612FNG_3pin_MOTOR_DRIVER* driver, uint32_t freq )

Initialise the 3 pin driver to use the given PWM frequency.
This should be called in appInitHardware.

MAKE_TOSHIBA_TB6612FNG_MOTOR_2pin(inverted, pwm1, pwm2)

Create a motor using the 2 pin connection method.
Both pins must be PWM output pins or else the library will generate a runtime error.
Example on the Axon:
TOSHIBA_TB6612FNG_2pin_MOTOR motor = MAKE_TOSHIBA_TB6612FNG_MOTOR_2pin(FALSE, E3, E4);

MAKE_TOSHIBA_TB6612FNG_2pin_MOTOR_DRIVER(motorlst)

Create the driver to control a list of 2 pin motors.
TOSHIBA_TB6612FNG_2pin_MOTOR_LIST PROGMEM motors[] = { &motor1, &motor2 }; // as many as you like
TOSHIBA_TB6612FNG_2pin_MOTOR_DRIVER driver = MAKE_TOSHIBA_TB6612FNG_2pin_MOTOR_DRIVER(motors);

toshibaTB6612FNG_2pin_Init( TOSHIBA_TB6612FNG_2pin_MOTOR_DRIVER* driver,uint32_ t freq)

Initialise the 2 pin driver to use the specified PWM frequency.
This should be called in appInitHardware.

Valid XHTML 1.0 Transitional