步驟6:利用現(xiàn)有的程序來旋轉(zhuǎn)無刷電機
現(xiàn)在回到我的項目中阳距,本步驟中將會第一次涉及“如何來做”的內(nèi)容哦吆你。
在上個步驟中提到的文章幻林,作者利用Arduino來驅(qū)動了無刷電機讓其旋轉(zhuǎn)愚墓。他們參考了
一篇早期由eLABZ撰寫的文章杠氢。并且他們利用程序驗證了它摘能。在這面文章里作者eLABZ解釋了如何利用舊的DVD光驅(qū)的無刷電機來制作一個頻閃觀測器续崖。
據(jù)我所知,這是僅僅唯一的一篇關(guān)于利用Arduino來驅(qū)動無刷電機旋轉(zhuǎn)的团搞,并包含了全部細節(jié)的文章严望。這篇文章包含了3個部分。
1.Learning fundamental knowledge of (3-phase) Brushless Motor
2.Rotating Brushless Motor by using Arduino
3.Putting materials together to get Stroboscope
:
在第二個部分里提供了驅(qū)動無刷電機的程序逻恐。我讀完之后并做了相關(guān)的注釋像吻。然后我明白了我應(yīng)該需要給電機的三項通上三項交流電,并且每一項之間的相位相差120°(項與項之間無特殊順序)复隆。我模仿這個程序來驅(qū)動電機果然輕松地就讓我買的這個電機轉(zhuǎn)了起來拨匆。?DOCUMENTARY (5)?這個視頻展示了效果。
:
[DOCUMENTARY (5)] Rotating 3-Phase Brushless Motor with Arduino and AC Square Wave
視頻地址:https://www.youtube.com/embed/rzWfxoOVmjU
:
這里我解釋一下如何利用Arduino UNO來旋轉(zhuǎn)無刷電機挽拂。你需要一個三項無刷電機惭每,它有三條引出線。
1.把電機的這三根引出線分別與UNO的9,10,11引腳相連亏栈,沒有連接順序的要求台腥。
2.下載我這個步驟最后提供的兩個PDF文檔到你的電腦中
3.利用PDF閱讀器打開他們。
4.把任意其中一個文檔中的全部文字拷貝
5.把拷貝內(nèi)容粘貼到Arduino的開發(fā)環(huán)境中并且更正一些小錯誤绒北。
6.上載檢查無誤后的程序到Arduino中
這兩程序都是基于eLABz的原始程序修改而來黎侈。高轉(zhuǎn)矩的云臺電機會在程序上載完成后立刻開始旋轉(zhuǎn),而有些模型上用高速型的電機僅用Arduino提供的電力可能不會旋轉(zhuǎn)闷游。這時候就需要外部電源和電機驅(qū)動芯片了峻汉。在DOCUMENTARY (6)中的展示中就利用里外部電源和驅(qū)動芯片贴汪。在這個視頻的前半部分是展示的高扭矩型電機,在后半部分是展示的高速型電機休吠。
:
[DOCUMENTARY (6)] Rotating Two Types of Brushless Motor with Arduino, Outer Batteries and Sine Wave AC
視頻地址: https://www.youtube.com/embed/55_e6MnpI88
PDF1:
// Driving 3-phase Brushless DC Motor with Square-wave
// This sketch is based on the code for the stroboscope project by eLABZ.
// (http://elabz.com/bldc-motor-with-arduino-circuit-and-software/)
// Copyright (C) 2015 ArduinoDeXXX All Rights Reserved.
const int motorDelayActual = 150;
const int motorPin1 =9;
const int motorPin2 =10;
const int motorPin3 =11;
const int motorPinState[]={1,1,1,0,0,0};
int currentStepA=0;
int currentStepB=2;
int currentStepC=4;
long lastMotorDelayTime = 0;
void setup () {
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
}
void loop () {
if((millis() - lastMotorDelayTime) > motorDelayActual){
currentStepA = currentStepA ++;
if(currentStepA > 5) currentStepA = 0;
if(currentStepA < 0) currentStepA = 5;
currentStepB = currentStepB ++;
if(currentStepB > 5) currentStepB = 0;
if(currentStepB < 0) currentStepB = 5;
currentStepC = currentStepC ++;
if(currentStepC > 5) currentStepC = 0;
if(currentStepC < 0) currentStepC = 5;
lastMotorDelayTime = millis();
analogWrite(motorPin1, 254 * motorPinState[currentStepA]);
analogWrite(motorPin2, 254 * motorPinState[currentStepB]);
analogWrite(motorPin3, 254 * motorPinState[currentStepC]);
}
}
// Copyright (C) 2015 ArduinoDeXXX All Rights Reserved.
PDF2:
// Driving 3-phase Brushless DC Motor with Sinusoidal Wave
// This sketch is based on the code for the stroboscope project by eLABZ.
// (http://elabz.com/bldc-motor-with-arduino-circuit-and-software/)
// Copyright (C) 2015 ArduinoDeXXX All Rights Reserved.
const int motorDelayActual = 20;
const int motorPin1 =9;
const int motorPin2 =10;
const int motorPin3 =11;
const int motorPinState[]={127,111,94,78,64,50,37,26,17,9,4,1,0,1,4,9,17,26,37,50,64,78,
94,111,127,144,160,176,191,205,218,229,238,245,251,254,255,
254,251,245,238,229,218,205,191,176,160,144,127};
int currentStepA = 0;
int currentStepB = 16;
int currentStepC = 32;
long lastMotorDelayTime = 0;
void setup () {
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
}
void loop () {
if((millis() - lastMotorDelayTime) > motorDelayActual){
currentStepA = currentStepA ++;
if(currentStepA > 47) currentStepA = 0;
if(currentStepA < 0) currentStepA = 47;
currentStepB = currentStepB ++;
if(currentStepB > 47) currentStepB = 0;
if(currentStepB < 0) currentStepB = 47;
currentStepC = currentStepC ++;
if(currentStepC > 47) currentStepC = 0;
if(currentStepC < 0) currentStepC = 47;
lastMotorDelayTime = millis();
analogWrite(motorPin1, motorPinState[currentStepA]);
analogWrite(motorPin2, motorPinState[currentStepB]);
analogWrite(motorPin3, motorPinState[currentStepC]);
}
}
// Copyright (C) 2015 ArduinoDeXXX All Rights Reserved.