TB6612 drive tutorials

1. Learning objectives

Use TB6612 motor driver module to drive dual-channel motors.

2. Hardware connection

MSPM0G3507 and TB6612 pin connection

image-20241210110931097

A motor:

MSPM0G3507TB6612
PA8PWMA
PA14AIN1
PA15AIN2

B motor:

MSPM0G3507TB6612
PA9PWMB
PA16BIN1
PA17BIN2

TB6612 motor driver module pin description.

2

3

3. Code analysis

The macro definition part defines how to control the direction of the motor. TB6612 controls the direction of the motor through two pins. When one pin is high and the other is low, the motor rotates in one direction; otherwise, it rotates in the opposite direction.

AIN1_OUT and AIN2_OUT control the direction of motor A.

BIN1_OUT and BIN2_OUT control the direction of motor B.

A_control(uint16_t motor_speed, uint8_t dir): This function is used to control motor A and accepts motor speed (motor_speed) and direction (dir) as parameters.

B_control(uint16_t motor_speed, uint8_t dir): This function is used to control motor B and has similar functions to A_control.

Function A_control(uint16_t motor_speed, uint8_t dir) and function B_control(uint16_t motor_speed, uint8_t dir) control motor A and B respectively, determine the rotation direction of the motor according to the dir parameter, and use the motor_speed parameter to set the motor speed.

Note: The project source code must be placed in the SDK path for compilation,

For example, the path: D:\TI\M0_SDK\mspm0_sdk_1_30_00_03\TB6612

4