Hello everyone! I wanna get my NEMA17 stepper motor to 1000RPM or higher with DRV8825 module. I read this tutorial Stepper Motor with DRV8825 and Arduino Tutorial (4 Examples) , but i don't know if i understand very good the code there. I use a 12V with 3A adapter for the driver power supply. I change the delay in that for statement to change the speed and try a code showed below to measure the RPM. I use an IR speed sensor based on LM393 ( A22 module) to read the number of interruptions. When i try to change delay at 300us it stucks.
ARDUINO CODE:
// CODE EXAMPLE TO HANDLE NEMA17 AND A22 SPEED SENSOR(BASED ON LM393) AT THE SAME TIME - SERIAL MONITOR
const int dirPin = 2;
const int stepPin = 3;
const int stepsPerRevolution = 200;
const int speedsensor = 11;
int value = 0;
int last_value = 0;
unsigned long start_time = 0;
unsigned long end_time =0;
void setup()
{
// Declare pins as Outputs
Serial.begin(9600);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(speedsensor,INPUT);
digitalWrite(dirPin, HIGH);
}
void loop()
{
start_time = millis();
end_time = start_time+60000; // 60 sec
while(millis() < end_time) //do this untill end_time = 60 sec
{
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(400);
digitalWrite(stepPin, LOW);
delayMicroseconds(400);
if(digitalRead(speedsensor)&& value == last_value)
{
value++;
}
}
Serial.print("Value is: ");
Serial.println(value);
last_value = value;
}
Serial.println();
Serial.println("Turation is :");
Serial.print(value);
Serial.print(" RPM");
delay(10000); // delay for next measurement
}
The circuit is in the link. Thanks for help!