赞
踩
VM :一般接12V(4.5v-15v)
VCC:一般接5V
STBY:1----电机工作 (可以直接接3.3V)
0----电机待机
AIN1:
AIN2;控制电机转动方向
AO1:电机M+
AO2:电机M-
注意:电机的两个引脚有顺序,不要接反了
TB6612 是双驱动,可以驱动两个电机
驱动 1 路
- PWMA 接单片机的 PWM 口
- 真值表:
- AIN1 0 0 1
- AIN2 0 1 0
- 停止 正传 反转
- A01
- AO2 接电机 1 的两个脚
驱动 2路
- PWMB 接单片机的 PWM 口
- 真值表:
- BIN1 0 0 1
- BIN2 0 1 0
- 停止 正传 反转
- B01
- BO2 接电机 2 的两个脚
二.控制电机转向
GPIO口配置:
-
- /*
- * 电机控制端GPIO设置
- * AIN1 AIN2
- * 左前 P6.0 P6.1
- * 右前 P6.2 P6.3
- * 左后 P6.4 P7.0
- * 右后 P6.5 P6.6
- */
- void CAR_RUN_Init(void)
- {
- P6DIR |= BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6;
- P6OUT &= ~(BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6);
-
- P7DIR |= BIT0;
- P7OUT &= ~BIT0;
- }
控制小车行进方向:
-
- void CAR_F_R(int mode_1)//控制前后行动,控制IN1,IN2
- {
- switch(mode_1)
- {
- case 0://前行
- P6OUT &= ~(BIT0 + BIT2 + BIT4 + BIT5); //0
- P6OUT |= BIT1 + BIT3 + BIT6; //1
- P7OUT |= BIT0;
- break;
-
- case 1://后退
- P6OUT |= BIT0 + BIT2 + BIT4 + BIT5; //1
- P6OUT &= ~(BIT1 + BIT3 + BIT6); //0
- P7OUT &= ~BIT0; //0
- break;
-
- case 2://左转
- P6OUT &= ~BIT0; //0,P6.0
- P6OUT &= ~BIT1; //0
-
- P6OUT &= ~BIT2; //0,P6.2
- P6OUT |= BIT3; //1
-
- P6OUT &= ~BIT4; //0,P6.4
- P7OUT &= ~BIT0; //0
-
- P6OUT &= ~BIT5; //0
- P6OUT |= BIT6; //1
- break;
-
- case 3://右转
- P6OUT &= ~BIT0; //0
- P6OUT |= BIT1; //1
-
- P6OUT &= ~BIT2; //0
- P6OUT &= ~BIT3; //0
-
- P6OUT &= ~BIT4; //0
- P7OUT |= BIT0; //1
-
- P6OUT &= ~BIT5; //0
- P6OUT &= ~BIT6; //0
- break;
-
- case 4://停止
- P6OUT &= ~(BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6); //0
- P7OUT &= ~BIT0;
- break;
-
- case 5://左旋转
- P6OUT &= ~BIT0; //0
- P6OUT |= BIT1; //1
-
- P6OUT |= BIT2; //1
- P6OUT &= ~BIT3; //0
-
- P6OUT &= ~BIT4; //0
- P7OUT |= BIT0; //1
-
- P6OUT |= BIT5; //1
- P6OUT &= ~BIT6; //0
- break;
-
- case 6://右旋转
- P6OUT |= BIT0; //1
- P6OUT &= ~BIT1; //0
-
- P6OUT &= ~BIT2; //0
- P6OUT |= BIT3; //1
-
- P6OUT |= BIT4; //1
- P7OUT &= ~BIT0; //0
-
- P6OUT &= ~BIT5; //0
- P6OUT |= BIT6; //1
- break;
-
- default:
- break;
- }
- }
以下是我自己的小车和板子的连线图
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。