28BYJ-48 步進馬達實驗 (一相激磁)
步進馬達依照靜子線圈的相數多寡可分為單相、雙相、三相、四相和五相等。一般小型的步進馬達以四相式為準,這類的馬達在定字上有四組相對應的線圈,分別提供相差90度相位的電力。當馬達單相激磁時,這四組線圈可在各相的對應處停住轉子,當下一個脈衝來到時,轉子轉動一個角度,這種角度稱為步進角。步進角的計算公式如下:
步進角=360度/ 寸動數
= 360度 / (相數 X 轉子齒數)
寸動數:步進馬達每週所轉動的步數,就是相數和轉子齒數的乘積。
//程式
int Pin0 = 6;
int Pin1 = 7;
int Pin2 = 8;
int Pin3 = 9;
int _step = 0;
int count=0 ;
boolean dir = true;
// gre
void setup()
{
pinMode(Pin0, OUTPUT);
pinMode(Pin1, OUTPUT);
pinMode(Pin2, OUTPUT);
pinMode(Pin3, OUTPUT);
}
void loop()
{
switch(_step){
case 0:
digitalWrite(Pin0, HIGH);
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
break;
case 1:
digitalWrite(Pin0, LOW);
digitalWrite(Pin1, HIGH);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
break;
case 2:
digitalWrite(Pin0, LOW);
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, HIGH);
digitalWrite(Pin3, LOW);
break;
case 3:
digitalWrite(Pin0, LOW);
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, HIGH);
break;
default:
digitalWrite(Pin0, LOW);
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
break;
}
count++;
if (count>4096) { // 28BYJ-48 5V DC 360 / (5.625 / 64) = 4096 step
count=0;
dir=!dir;
delay(1000);
}
if(dir){
_step++;
}else{
_step--;
}
if(_step>7){
_step=0;
}
if(_step<0){
_step=7;
}
delay(4);
}
沒有留言:
張貼留言