0% found this document useful (0 votes)
124 views2 pages

Measure Time Steps

This code measures the time steps of a motor moving at full steps and half steps in different directions (clockwise and counterclockwise) at varying speeds. It defines pin assignments for controlling two coils (A and B) of the motor, sets the motor speed, and uses loops to call functions for different step types while printing the elapsed time between each step to the serial monitor.

Uploaded by

api-526076334
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
124 views2 pages

Measure Time Steps

This code measures the time steps of a motor moving at full steps and half steps in different directions (clockwise and counterclockwise) at varying speeds. It defines pin assignments for controlling two coils (A and B) of the motor, sets the motor speed, and uses loops to call functions for different step types while printing the elapsed time between each step to the serial monitor.

Uploaded by

api-526076334
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Code Used to Measure Time Steps of Full and Half Steps at Different Speeds: 

*See "Function" section for all function calls used in this code*  

#define A_DIRECTION 12 


#define A 3 
#define B_DIRECTION 13 
#define B 11 
#define NORTH 1 
#define SOUTH 2 

void setup() { 
pinMode(A_DIRECTION,OUTPUT); //Coil A 
pinMode(A,OUTPUT); 
pinMode(B_DIRECTION,OUTPUT); //Coil B 
pinMode(B,OUTPUT); 
shutdown();   
Serial.begin(9600); //Start Serial Monitor 

int d=10; //Sets the motor speed. Used 3, 5, and 10  


int t0=0; //time variable 
 ​
void loop() { 
t0=micros(); //t0 is the motion start time 
for (int c=1; c<=100; c++) {   
full_step_CCW(d);   
Serial.print(c);   
Serial.print(" ");   
Serial.println(String(micros()-t0)); //Print time  

delay(1500); 
for (int c=1; c<=100; c++) {   
full_step_CW(d);   
Serial.print(c);   
Serial.print(" ");   
Serial.println(String(micros()-t0));   
}   
delay(1500); 
for (int c=1; c<=100; c++) {   
half_step_CCW(d);   
Serial.print(c);   
Serial.print(" ");   
Serial.println(String(micros()-t0));   

delay(1500); 
for (int c=1; c<=100; c++) {   
half_step_CW(d);   
Serial.print(c);   
Serial.print(" ");   
Serial.println(String(micros()-t0));   
}   
shutdown();  
while(1);   
}

You might also like