| |

Above Figure: ATmega88,168,328 Stepping Motor interface Circuit.

0. Learning Basic Program from ETT.
/*
* Examples : Arduino Experiment Examples By....ETT CO.,LTD
* Program : Hardware LAB5.1
* Hardware : ET-BASE AVR EASY MEGA88/168(Arduino)
* : ET-MINI SMCC-547(Unipolar : 18-Degree / Step)
* : -> INA = Digital-4
* : -> INB = Digital-5
* : -> INC = Digital-6
* : -> IND = Digital-7
* Function : Stepping Motor Control
* : 1-Phase Drive(Wave Drive)
*/
#define StepRate 10 //10mS Delay Step Drive
int INA = 4; //Phase-A Signal Drive
int INB = 5; //Phase-B Signal Drive
int INC = 6; //Phase-C Signal Drive
int IND = 7; //Phase-D Signal Drive
static byte Step = 0; //Position Step Buffer
static byte *pStep;
/*
* 1 Phase Drive : Half Drive
* : Wave Drive
* : 1 Excitation Drive
*/
void WaveStepDrive(byte *Step)
{
byte MyStep = *Step; //Get Step Position
switch (MyStep)
{
case 0: digitalWrite(INA, HIGH);
digitalWrite(INB, LOW);
digitalWrite(INC, LOW);
digitalWrite(IND, LOW);
break;
case 1: digitalWrite(INA, LOW);
digitalWrite(INB, HIGH);
digitalWrite(INC, LOW);
digitalWrite(IND, LOW);
break;
case 2: digitalWrite(INA, LOW);
digitalWrite(INB, LOW);
digitalWrite(INC, HIGH);
digitalWrite(IND, LOW);
break;
case 3: digitalWrite(INA, LOW);
digitalWrite(INB, LOW);
digitalWrite(INC, LOW);
digitalWrite(IND, HIGH);
break;
}
}
void setup()
{
pinMode(INA, OUTPUT);
pinMode(INB, OUTPUT);
pinMode(INC, OUTPUT);
pinMode(IND, OUTPUT);
digitalWrite(INA, LOW);
digitalWrite(INB, LOW);
digitalWrite(INC, LOW);
digitalWrite(IND, LOW);
}
void loop()
{
for (int i=0; i<20; i++) //20 Step / 1 Round
{
pStep = &Step; //1-Stop Forward
*pStep += 1; //0,1,2,3,0,1,2,3,...,0,1,2,3
*pStep &= 0x03; //Step=0..3
WaveStepDrive(&Step);
delay(StepRate);
}
delay(500);
for (int i=20; i>0; i--) //20 Step / 1-Round
{
pStep = &Step; //1-Stop Reverse
*pStep -= 1; //3,2,1,0,3,2,1,0,...,3,2,1,0
*pStep &= 0x03; //Step=0..3
WaveStepDrive(&Step);
delay(StepRate);
}
delay(500);
}
|
1. Program to drive a stepper motor by David Cuartielles
/* Stepper Copal
* -------------
*
* Program to drive a stepper motor coming from a 5'25 disk drive
* according to the documentation I found, this stepper: "[...] motor
* made by Copal Electronics, with 1.8 degrees per step and 96 ohms
* per winding, with center taps brought out to separate leads [...]"
* [http://www.cs.uiowa.edu/~jones/step/example.html]
*
* It is a unipolar stepper motor with 5 wires:
*
* - red: power connector, I have it at 5V and works fine
* - orange and black: coil 1
* - brown and yellow: coil 2
*
* (cleft) 2005 DojoDave for K3
* http://www.0j0.org | http://arduino.berlios.de
*
* @author: David Cuartielles
* @date: 20 Oct. 2005
*/
int motorPin1 = 4; //Digital pin 4
int motorPin2 = 5; //Digital pin 5
int motorPin3 = 6; //Digital pin 6
int motorPin4 = 7; //Digital pin 7
int delayTime = 500;
void setup() {
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
}
void loop() {
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(delayTime);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(delayTime);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
delay(delayTime);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
delay(delayTime);
}
|
referent website: http://www.arduino.cc/en/Tutorial/StepperUnipolar
ไทย
ทดลองเปลี่ยน delayTime ดู พบว่า
delay(0) ไม่สามารถหมุนได้ สั่น
delay(2) ไม่สามารถหมุนได้ สั่น
delay(4) หมุนได้ แต่สั่น
delay(5) สามารถหมุนได้ ราบลื่น เร็วที่สุด
English:
What happen ? when you change delay time funtion ?
answer:
delay(0) no move and
shake.
delay(2) no move and shake.
delay(4) move around but a little shake.
delay(5) move around smoothly and fastest.
2. Control speed for Stepping Motor (Normal Power)
int motorPin1 = 4; //Digital pin 4
int motorPin2 = 5; //Digital pin 5
int motorPin3 = 6; //Digital pin 6
int motorPin4 = 7; //Digital pin 7
int analogPin0=0;
int val=0;
int delayTime = 0;
void setup() {
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
pinMode(analogPin0,INPUT); // get input from variable Resister.
}
void loop() {
int val=analogRead(analogPin0);
val=map(val,0,1023,0,500); // set delayTime value between 0-500
delayTime=val;
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(delayTime);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(delayTime);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
delay(delayTime);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
delay(delayTime);
}
|
3. Double wire stepping motor with control speed. (High Power)
int motorPin1 = 4; //Digital pin 4
int motorPin2 = 5; //Digital pin 5
int motorPin3 = 6; //Digital pin 6
int motorPin4 = 7; //Digital pin 7
int analogPin0=0;
int val=0;
int delayTime = 0;
void setup() {
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
pinMode(analogPin0,INPUT); // get input from variable Resister.
}
void loop() {
int val=analogRead(analogPin0);
val=map(val,0,1023,0,500); // set delayTime value between 0-500
delayTime=val;
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(delayTime);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
delay(delayTime);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, HIGH);
delay(delayTime);
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
delay(delayTime);
}
|
|
|