아두이노 - 스테핑 모터 컨트롤러(SLA7062M) 소스
MCU 및 PLD 2010. 8. 2. 19:23
간단하게..
// SLA7260 DATASHEET , 11page 회로도와 동일하게 구성
// 각각의 핀 연결은 다음과 같다.
#define MOPIN (7)
#define M1PIN (6)
#define M2PIN (2)
#define SYNCPIN (8)
#define CWPIN (4)
#define CLKPIN (3)
#define RSTPIN (5)
#define ENPIN (13)
// 4개의 택스위치를 연결한다. 평상시 vdd로 풀업되어 있다.
#define INPUT1 (9) // TACK SWTICH INPUT
#define INPUT2 (10)
#define INPUT3 (11)
#define INPUT4 (12)
void setup()
{
pinMode(MOPIN,INPUT);
pinMode(M1PIN,OUTPUT);
pinMode(M2PIN,OUTPUT);
pinMode(CWPIN,OUTPUT);
pinMode(CLKPIN,OUTPUT);
pinMode(SYNCPIN,OUTPUT);
pinMode(ENPIN,OUTPUT);
pinMode(INPUT1,INPUT);
pinMode(INPUT1,INPUT);
pinMode(INPUT1,INPUT);
pinMode(INPUT1,INPUT);
pinMode(RSTPIN,OUTPUT);
digitalWrite(M1PIN,LOW); // 1/16 step
digitalWrite(M2PIN,LOW);
digitalWrite(SYNCPIN,HIGH); // sync mode
digitalWrite(RSTPIN,LOW);
Serial.begin(9600);
Serial.println("SLA7206M controller start..(made by Kim H)");
}
int steps[] = {
200,190,180,170,160,150,140,130,120,110,
100,90,80,70,60,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,60,70,80,90,100,
110,120,130,140,150,160,170,180,190,200,
};
int steps2[] = {
200,190,180,170,160,150,140,130,120,110,
100,100,100,100,100,100,100,100,100,100,
100,100,100,100,100,100,100,100,100,100,
100,100,100,100,100,100,100,100,100,100,
100,100,100,100,100,100,100,100,100,100,
100,100,100,100,100,100,100,100,100,100,
100,100,100,100,100,100,100,100,100,100,
100,100,100,100,100,100,100,100,100,100,
100,100,100,100,100,100,100,100,100,100,
100,100,100,100,100,100,100,100,100,100,
100,100,100,100,100,100,100,100,100,100,
100,100,100,100,100,100,100,100,100,100,
100,100,100,100,100,100,100,100,100,100,
100,100,100,100,100,100,100,100,100,100,
100,100,100,100,100,100,100,100,100,100,
100,100,100,100,100,100,100,100,100,100,
100,100,100,100,100,100,100,100,100,100,
100,100,100,100,100,100,100,100,100,100,
100,100,100,100,100,100,100,100,100,100,
110,120,130,140,150,160,170,180,190,200,
};
void loop()
{
int i,j;
if(digitalRead(INPUT1) == 0) {
Serial.println("Input1 key..");
digitalWrite(ENPIN,HIGH);
digitalWrite(CWPIN,HIGH);
for(i = 0;i < 200;i++) {
for(j = 0; j < 16;j++) {
digitalWrite(CLKPIN,HIGH);
delayMicroseconds(steps[i]);
digitalWrite(CLKPIN,LOW);
delayMicroseconds(steps[i]);
}
}
} else if(digitalRead(INPUT2) == 0) {
Serial.println("Input2 key..");
digitalWrite(ENPIN,HIGH);
digitalWrite(CWPIN,HIGH);
for(i = 0;i < 200;i++) {
for(j = 0; j < 16;j++) {
digitalWrite(CLKPIN,HIGH);
delayMicroseconds(steps2[i]);
digitalWrite(CLKPIN,LOW);
delayMicroseconds(steps2[i]);
}
}
} else if(digitalRead(INPUT3) == 0) {
Serial.println("Input3 key..");
digitalWrite(ENPIN,HIGH);
digitalWrite(CWPIN,LOW);
for(i = 0;i < 200;i++) {
for(j = 0; j < 16;j++) {
digitalWrite(CLKPIN,HIGH);
delayMicroseconds(steps[i]);
digitalWrite(CLKPIN,LOW);
delayMicroseconds(steps[i]);
}
}
} else if(digitalRead(INPUT4) == 0) {
Serial.println("Input4 key..");
digitalWrite(ENPIN,HIGH);
digitalWrite(CWPIN,LOW);
for(i = 0;i < 200;i++) {
for(j = 0; j < 16;j++) {
digitalWrite(CLKPIN,HIGH);
delayMicroseconds(steps2[i]);
digitalWrite(CLKPIN,LOW);
delayMicroseconds(steps2[i]);
}
}
} else {
digitalWrite(ENPIN,LOW);
}
}