实验2:ardunio spwm驱动电机
之前在我的第一篇文章里有提到利用三路正弦波驱动无刷电机的技术,这个技术也是很多开源无刷自稳云台所采用的电机驱动技术。那么今天这个实验就是来测试这个技术。
这个技术的源头出自哪里我并不知道,但是在网上流传最广泛的两篇文章对许多创客们了解这个驱动技术有着很重要的帮助。
1.1Driving a three-phase brushless DC motor with Arduino – Part 1. Theory
1.2Brushless DC (BLDC) motor with Arduino – Part 2. Circuit and Software
2.Spining BLDC(Gimbal) motors at super slooooooow speeds with Arduino and L6234
贴上我的简单测试程序,主要抄自第二篇文章里面的代码,电机驱动芯片我是用的TI DRV8313,
DRV8313而没有用L6324,不过大同小异,DRV8313需要根据官方的datasheet搭建好外围电路(需要几种不同容量的电容),然后连接剩下三个通道的EN和IN和OUT,将其中EN1~3与ardunio的22、23、24相连,IN1~3与第一个试验中用来生成三路PWM波的6、7、8引脚相连。OUT1~3与电机三相输入相连。这里我还用到了25口,它与DRV8313的sleep和reset引脚(17、18引脚)相连,因为只有当这两个引脚为逻辑高电平时,DRV8313才会有输出。
const int pwmSin[] = {128, 132, 136, 140, 143, 147, 151, 155, 159, 162, 166, 170, 174, 178, 181, 185, 189, 192, 196, 200, 203, 207, 211, 214, 218, 221, 225, 228, 232, 235, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 249, 250, 250, 251, 252, 252, 253, 253, 253, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 254, 254, 253, 253, 253, 252, 252, 251, 250, 250, 249, 248, 248, 247, 246, 245, 244, 243, 242, 241, 240, 239, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 249, 250, 250, 251, 252, 252, 253, 253, 253, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 254, 254, 253, 253, 253, 252, 252, 251, 250, 250, 249, 248, 248, 247, 246, 245, 244, 243, 242, 241, 240, 239, 238, 235, 232, 228, 225, 221, 218, 214, 211, 207, 203, 200, 196, 192, 189, 185, 181, 178, 174, 170, 166, 162, 159, 155, 151, 147, 143, 140, 136, 132, 128, 124, 120, 116, 113, 109, 105, 101, 97, 94, 90, 86, 82, 78, 75, 71, 67, 64, 60, 56, 53, 49, 45, 42, 38, 35, 31, 28, 24, 21, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 8, 7, 6, 6, 5, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 8, 7, 6, 6, 5, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 21, 24, 28, 31, 35, 38, 42, 45, 49, 53, 56, 60, 64, 67, 71, 75, 78, 82, 86, 90, 94, 97, 101, 105, 109, 113, 116, 120, 124};
int currentStepA;
int currentStepB;
int currentStepC;
int sineArraySize;
int increment = 0;
boolean direct = 1;
void setup() {
TCCR4B = (TCCR4B & 0xF8)|0x01;
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(22,OUTPUT);//
pinMode(23,OUTPUT);
pinMode(24,OUTPUT);
pinMode(25,OUTPUT);
digitalWrite(22,HIGH);
digitalWrite(23,HIGH);
digitalWrite(24,HIGH);
digitalWrite(25,HIGH);
sineArraySize = sizeof(pwmSin)/sizeof(int); // Find lookup table size
int phaseShift = sineArraySize / 3; // Find phase shift and initial A, B C phase values
currentStepA = 0;
currentStepB = currentStepA + phaseShift;
currentStepC = currentStepB + phaseShift;
sineArraySize--;
}
void loop() {
analogWrite(6,pwmSin[currentStepA]);
analogWrite(7, pwmSin[currentStepB]);
analogWrite(8,pwmSin[currentStepC]);
if (direct==true) increment = 1;
else increment = -1;
currentStepA = currentStepA + increment;
currentStepB = currentStepB + increment;
currentStepC = currentStepC + increment;
//Check for lookup table overflow and return to opposite end if necessary
if(currentStepA > sineArraySize) currentStepA = 0;
if(currentStepA < 0) currentStepA = sineArraySize;
if(currentStepB > sineArraySize) currentStepB = 0;
if(currentStepB < 0) currentStepB = sineArraySize;
if(currentStepC > sineArraySize) currentStepC = 0;
if(currentStepC < 0) currentStepC = sineArraySize;
/// Control speed by this delay
delay(10);
}
最终效果
存在问题:1.电机运行不到一分钟就已经烫的没法拿了 2依旧还有一些细小的噪音3.还不够匀速
初步分析,1.电机电流过大,需要给PWM占空比设置一个输出百分比,当低转速时整体降低占空比来降低电压,从而降低电流减少发热。2,这是一个典型的开环控制,没有转速的任何反馈,各种干扰都会影响电机的匀速运动。
让我们继续学习开源,看德国人是怎么解决这些问题的。