• Increase font size
  • Default font size
  • Decrease font size
  • default color
  • cyan color
  • red color

Arduino.TW樂園

Member Area
步進馬達(Stepper Motor) PDF 列印 E-mail
作者是 xlinx   
週日, 04 三月 2007 18:47

http://www.arduino.cc/en/Tutorial/StepperUnipolar
步進馬達應用(2相,4線式)
主角:2相4定子(4線式)、精度0.9DEG、阻抗13歐姆、電壓5V、電流0.34A的步進馬達。
激磁方式(程式的3種寫法):                                                   New Code#update 2007-03-12

  • 1相激磁 每次會1個線圈通過電流,因此轉矩小、振動較大,消耗電力小。(TFFF-FTFF-FFTF-FFFT)
  • 2相激磁 每次使2個線圈激磁,因此轉矩大、振動小,是目前使用最多的方式。(TTFF-FTTF-FFTT-TFFT)
  • 1-2相激磁 又稱為半步激磁,使1相和2相輪流激磁,因此解析度提高一倍,且運轉平順 簡單說即為,在一個時間單位內,2相4定子間同時 OUTPUT==TRUE 的時機。

  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);


圖1圖2依照順序的(X > Y > X-bar > Y-bar),步進馬達的四個定子順序激磁。


                       圖1. 正向激磁                                                                                     圖2. 反相激磁



就會產生如表1的角度變化,利用Arduino產生一脈衝電路為順序以及倒序,便會產生正反轉動作。
圖3實照圖Stepper Motorr接線顏色分別為:(X)、(Y)、(Xbar)、(Ybar)。

表1. 相位激磁角度

角度
0 1 0 1
1 0 0 1 (-)90°
1 0 1 0 (-)180°
0 1 1 0 (-)270°

0:接地。與程式digitalWrite(motorPin1, false)同意。
1:正脈衝。與程式
digitalWrite(motorPin1, true)同意。
(-):紅色負號為反相激磁時的角度變化。

程式中判斷正反轉為參照一個1K的可變電阻做判斷依據,當可變電阻旋轉過半時,馬達將反轉(激磁相位倒轉),反之亦同。



如需扭力較大的馬達,請在加入驅動放大電路。


setpper Moto
                                                                                          圖3. 實照圖


開始程式

int motorPin1 = 9;
int motorPin2 = 10;
int motorPin3 = 11;
int motorPin4 = 12;
int ledPin = 13;
boolean motorX[4]={true,true,true,true};
boolean turn_R_or_L=true;     
boolean tempBool=false;  
int count=0;       
int potPin = 5;  
int val = 0;     
int speed=10;       
int motorStartType=1;              
void setup()
{
  Serial.begin(9600);
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
  pinMode(ledPin, OUTPUT);
}

void loop()
{
  tempBool = !tempBool;
  digitalWrite(ledPin,tempBool); 
  putAnalog();
  oneHIGT();
  motorGo(turn_R_or_L);
 
  delay(speed);  //delyMicroseconds(speed*0.001);
}
void putAnalog()
{
  val = analogRead(potPin);
  if(val>512)  turn_R_or_L=true;
  else  turn_R_or_L=false;
}
void oneHIGT()
{
  for(int x=0;x<=3;x++)
  {
    if(x==count)    motorX[x]=true;
    else     motorX[x]=false;
  }
  if(count==3)   count=0;
  else   count++; 
}
void twoHIGT()
{
  switch (count)
  {
    case 0:
    motorX[0]=true; 
    motorX[1]=true;
    motorX[2]=false; 
    motorX[3]=false;
    break;
        case 1:
    motorX[0]=false;
    motorX[1]=true;
    motorX[2]=true;
    motorX[3]=false;
    break;
        case 2:
    motorX[0]=false;
    motorX[1]=false;
    motorX[2]=true;
    motorX[3]=true;
    break;
        case 3:
    motorX[0]=true;
    motorX[1]=false;
    motorX[2]=false; 
    motorX[3]=true;
    break;
    }  if(count==3)   count=0;
  else   count++; 
}
void bothHIGT(int who)
{}
void motorGo(boolean RL)
{
  if(RL){ 
    digitalWrite(motorPin1, motorX[0]);
    digitalWrite(motorPin2, motorX[1]);
    digitalWrite(motorPin3, motorX[2]);
    digitalWrite(motorPin4, motorX[3]);
  }
  else{
    digitalWrite(motorPin4, motorX[0]);
    digitalWrite(motorPin3, motorX[1]);
    digitalWrite(motorPin2, motorX[2]);
    digitalWrite(motorPin1, motorX[3]);
  }
}



blog comments powered by Disqus
最近更新在 週四, 03 六月 2010 13:11