Sunteți pe pagina 1din 5

9/27/2020 Time&Step.

html

//David Rak ME460 Design Project 1


//Stepper Motor Displacement and Time Steps Main funciton

//Define pin names for clarity


#define A_DIR 12
#define A 3
#define B_DIR 13
#define B 11
#define NORTH 1
#define SOUTH 2
#define OFF 0

void setup() {
//tell which pins we'll use

pinMode(A_DIR,OUTPUT); //Coil A
pinMode(A,OUTPUT);

pinMode(B_DIR,OUTPUT); //Coil B
pinMode(B,OUTPUT);

shutdown(); //Turn off all coils

Serial.begin(9600); //Start Serial Monitor


}

int d=5; //Sets the motor speed.


int T0=0; //time 0 variable
void loop(){

T0=micros(); //T0 is the start time of the motion

//This is 2 rotations of a
for (int ct=1; ct<=100; ct++){ //50 loops is one rotation since we have 200 full steps in 365 degrees
fullstepCCW(d); //Four steps CW
Serial.print(ct); //Print Count
Serial.print(" "); //Space
Serial.println(String(micros()-T0)); //Print elapsed time & newline
}
delay(1000);

//This is 2 rotations of a
for (int ct=1; ct<=100; ct++){ //50 loops is one rotation since we have 200 full steps in 365 degrees
fullstepCW(d); //Four steps CCW
Serial.print(ct); //Print Count
Serial.print(" "); //Space
Serial.println(String(micros()-T0)); //Print elapsed time & newline
}
delay(1000);

//This is 2 rotations of a
for (int ct=1; ct<=100; ct++){ //50 loops is one rotation since we have 400 half-steps in 365 degrees
halfstepCCW(d); //Eight half steps CCW
Serial.print(ct); //Print Count
Serial.print(" "); //Space
Serial.println(String(micros()-T0)); //Print elapsed time & newline
}
delay(1000);

//This is 2 rotations of a
for (int ct=1; ct<=100; ct++){ //50 loops is one rotation since we have 400 half-steps in 365 degrees
halfstepCW(d); //Eight half steps CW
Serial.print(ct); //Print Count
Serial.print(" "); //Space
Serial.println(String(micros()-T0)); //Print elapsed time & newline
}

file:///C:/Users/david/Documents/Señor/ME460- Senior Design/Homeworks/Design HW01- Project 01 - Open Loop/Time&Step.html 1/2


9/27/2020 Time&Step.html
shutdown(); //make sure it turns off when program finishes
while(1);
}

file:///C:/Users/david/Documents/Señor/ME460- Senior Design/Homeworks/Design HW01- Project 01 - Open Loop/Time&Step.html 2/2


9/27/2020 Time&StepFunctions.html

//David Rak ME460 Design Project 1


//Stepper Motor Displacement and Time Steps intermediate funcitons

//emergency shutdown function


void shutdown() {
//apply LOW V to everything
digitalWrite(12,LOW);
digitalWrite(3,LOW);
digitalWrite(13,LOW);
digitalWrite(11,LOW);
}

//Function to control Termainal A


void termA(int polarity){
if (polarity==NORTH){
digitalWrite(A_DIR, HIGH);
digitalWrite(A, HIGH);
}

if (polarity==SOUTH){
digitalWrite(A_DIR, LOW);
digitalWrite(A, HIGH);
}

if (polarity==OFF){
digitalWrite(A_DIR, LOW);
digitalWrite(A, LOW);
}
}

//Function to control Termainal B


void termB(int polarity){
if (polarity==NORTH){
digitalWrite(B_DIR, HIGH);
digitalWrite(B, HIGH);
}

if (polarity==SOUTH){
digitalWrite(B_DIR, LOW);
digitalWrite(B, HIGH);
}

if (polarity==OFF){
digitalWrite(B_DIR, LOW);
digitalWrite(B, LOW);
}
}

//Full Step Function: Use the table we made in class!


void fullstepCCW(int d) {
termA(SOUTH);
termB(OFF);
delay(d);

termA(OFF);
termB(SOUTH);
delay(d);

termA(NORTH);
termB(OFF);
delay(d);

file:///C:/Users/david/Documents/Señor/ME460- Senior Design/Homeworks/Design HW01- Project 01 - Open Loop/Time&StepFunctions.html 1/3


9/27/2020 Time&StepFunctions.html

termA(OFF);
termB(NORTH);
delay(d);
}

//Full Step Function


void fullstepCW(int d) {
termA(SOUTH);
termB(OFF);
delay(d);

termA(OFF);
termB(NORTH); //to change direction change B values
delay(d);

termA(NORTH);
termB(OFF);
delay(d);

termA(OFF);
termB(SOUTH); //to change direction changeB values
delay(d);
}

//Half Step Function


void halfstepCW(int d) {
termA(SOUTH);
termB(OFF);
delay(d);

termA(SOUTH);
termB(NORTH);
delay(d);

termA(OFF);
termB(NORTH);
delay(d);

termA(NORTH);
termB(NORTH);
delay(d);

termA(NORTH);
termB(OFF);
delay(d);

termA(SOUTH);
termB(SOUTH);
delay(d);

termA(OFF);
termB(SOUTH);
delay(d);

termA(NORTH);
termB(SOUTH);
delay(d);
}

//Half Step Function


void halfstepCCW(int d) {
termA(SOUTH);
termB(OFF);
delay(d);
file:///C:/Users/david/Documents/Señor/ME460- Senior Design/Homeworks/Design HW01- Project 01 - Open Loop/Time&StepFunctions.html 2/3
9/27/2020 Time&StepFunctions.html

termA(SOUTH);
termB(SOUTH);
delay(d);

termA(OFF);
termB(SOUTH);
delay(d);

termA(NORTH);
termB(SOUTH);
delay(d);

termA(NORTH);
termB(OFF);
delay(d);

termA(SOUTH);
termB(NORTH);
delay(d);

termA(OFF);
termB(NORTH);
delay(d);

termA(NORTH);
termB(NORTH);
delay(d);
}

file:///C:/Users/david/Documents/Señor/ME460- Senior Design/Homeworks/Design HW01- Project 01 - Open Loop/Time&StepFunctions.html 3/3

S-ar putea să vă placă și