Arduino与Proteus仿真实例-TB6612FNG驱动直流电机仿真

TB6612FNG驱动直流电机仿真

1、TB6612FNG介绍

TB6612FNG一款出色的双电机驱动器,非常适合将两个小型直流电机(例如我们的微型金属齿轮电机)连接到微控制器,也可用于控制单个双极步进电机。 基于 MOSFET 的 H 桥比 L298N 和 Sanyo 的 LB1836M 等旧驱动器中使用的基于 BJT 的 H 桥效率高得多,后者允许向电机提供更多电流,而从逻辑电源汲取的电流更少 (对于真正的低电压应用,LB1836 仍然具有 TB6612 的优势)。 我们的小型分线板可让您直接访问 TB6612FNG 的所有功能,并在电机电源上添加电源电容器和电池反向保护(注意:Vcc 连接上没有反向保护)。

在典型应用中,电源连接在电路板的一侧进行,控制连接在另一侧进行。 所有控制输入都在内部被拉低。 两个电机通道中的每一个都有两个方向控制引脚和一个速度控制引脚,该引脚接受频率高达 100 kHz 的 PWM 输入。 必须将 STBY 引脚驱动为高电平才能使驱动器退出待机模式。

在这里插入图片描述

TB6612有如下特性:

  • 双H桥电机驱动器:可驱动两台直流电机或一台双极步进电机
  • 推荐的电机电压 (VMOT):4.5 V 至 13.5 V(可低至 2.5 V 运行并降低性能)
  • 逻辑电压 (VCC):2.7 V 至 5.5 V
  • 最大输出电流:每通道 3 A
  • 输出电流连续:每通道 1 A(可并联以提供 2 A 连续)
  • 最大 PWM 频率:100 kHz
  • 内置热关断电路
  • 两条电源线上的滤波电容器
  • 电机电源的逆功率保护

!TB6612FNG的引脚功能如下:

在这里插入图片描述

TB6612FNG 电机驱动器可以以 1.2A(3.2A 峰值)的恒定电流控制多达两个直流电机。 两个输入信号(IN1 和 IN2)可用于以四种功能模式之一控制电机 - CW、CCW、短路制动和停止。 两个电机输出(A 和 B)可以单独控制,每个电机的速度通过频率高达 100kHz 的 PWM 输入信号控制。 应将 STBY 引脚拉高以使电机退出待机模式。

2、仿真电路原理图

在这里插入图片描述

3、仿真代码实现

本次实例使用到如下开源库:

演示代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
TestRun.ino
TB6612FNG H-Bridge Motor Driver Example code
Michelle @ SparkFun Electronics
8/20/16
https://github.com/sparkfun/SparkFun\_TB6612FNG\_Arduino\_Library

Uses 2 motors to show examples of the functions in the library. This causes
a robot to do a little 'jig'. Each movement has an equal and opposite movement
so assuming your motors are balanced the bot should end up at the same place it
started.

Resources:
TB6612 SparkFun Library

Development environment specifics:
Developed on Arduino 1.6.4
Developed with ROB-9457
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

// This is the library for the TB6612 that contains the class Motor and all the
// functions
#include <SparkFun\_TB6612.h>

// Pins for all inputs, keep in mind the PWM defines must be on PWM pins
// the default pins listed are the ones used on the Redbot (ROB-12097) with
// the exception of STBY which the Redbot controls with a physical switch
#define PWMA 5
#define AIN1 2
#define AIN2 3

#define BIN1 7
#define BIN2 8
#define PWMB 6


#define STBY 5

// these constants are used to allow you to make your motor configuration
// line up with function names like forward. Value can be 1 or -1
const int offsetA = 1;
const int offsetB = 1;

// Initializing motors. The library will allow you to initialize as many
// motors as you have memory for. If you are using functions like forward
// that take 2 motors as arguements you can either write new functions or
// call the function more than once.
Motor motor1 = Motor(AIN1, AIN2, PWMA, offsetA, STBY);
Motor motor2 = Motor(BIN1, BIN2, PWMB, offsetB, STBY);

void setup()
{
//Nothing here
}


void loop()
{
//Use of the drive function which takes as arguements the speed
//and optional duration. A negative speed will cause it to go
//backwards. Speed can be from -255 to 255. Also use of the
//brake function which takes no arguements.
motor1.drive(255,1000);
motor1.drive(-255,1000);
motor1.brake();
delay(1000);

//Use of the drive function which takes as arguements the speed
//and optional duration. A negative speed will cause it to go
//backwards. Speed can be from -255 to 255. Also use of the
//brake function which takes no arguements.
motor2.drive(255,1000);
motor2.drive(-255,1000);
motor2.brake();
delay(1000);

//Use of the forward function, which takes as arguements two motors
//and optionally a speed. If a negative number is used for speed
//it will go backwards
forward(motor1, motor2, 150);
delay(1000);

//Use of the back function, which takes as arguments two motors
//and optionally a speed. Either a positive number or a negative
//number for speed will cause it to go backwards
back(motor1, motor2, -150);
delay(1000);

//Use of the brake function which takes as arguments two motors.
//Note that functions do not stop motors on their own.
brake(motor1, motor2);
delay(1000);

//Use of the left and right functions which take as arguements two
//motors and a speed. This function turns both motors to move in
//the appropriate direction. For turning a single motor use drive.
left(motor1, motor2, 100);
delay(1000);
right(motor1, motor2, 100);
delay(1000);

//Use of brake again.
brake(motor1, motor2);
delay(1000);

}

4、仿真结果

在这里插入图片描述

文章来源: https://iotsmart.blog.csdn.net/article/details/121414256