Motor Not Going Defined Speed

#include <AccelStepper.h>

#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1
#define stepsPerRev 1600 // defined via driver
#define motorSpeed 3200 // steps/sec (3200 steps/sec = 120 rpm)


long rotations;
long target;
String motorDirection; // direction

AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);


void setup() {
  // put your setup code here, to run once:

  // Start serial communication:
  Serial.begin(9600);

  // Declare pins as output:
//  pinMode(dirPin,INPUT);
  pinMode(stepPin,OUTPUT);

  // Set max speed and acceleration/deceleration:
  stepper.setMaxSpeed(motorSpeed); // steps/sec
  stepper.setAcceleration(motorSpeed); // steps/sec^2
}

void loop() {
  // put your main code here, to run repeatedly:

//  // Select direction:
  Serial.println("Select direction. Enter CW or CCW.");
  while (Serial.available()==0) {
    // exits loop once input is made
  }
  // Read direction:
  motorDirection=Serial.readString();
  motorDirection.trim();
  if (motorDirection=="CW" || motorDirection=="cw") {
    pinMode(dirPin,OUTPUT);
//    digitalWrite(dirPin,HIGH);
   }
  else if (motorDirection=="CCW" || motorDirection=="ccw") {
    pinMode(dirPin,INPUT);
//    digitalWrite(dirPin,LOW);
   }
  else {
    Serial.println("Error: enter valid direction");
    return; // returns to beginning of if statement
   }
  Serial.print("The motor will turn ");
  Serial.println(motorDirection);

   

  // Display rotations message:
  Serial.println("How many rotations would you like to turn?");
  while (Serial.available()==0) {
    // exits loop once input is made
  }
  // read rotations message:
  rotations=Serial.parseInt();
  Serial.print("The motor will turn: ");
  Serial.print(rotations);
  Serial.println(" rotations");

  delay(1000); // wait 1 sec

  // move to target
  target = stepsPerRev * rotations;
  stepper.moveTo(target);
  stepper.runToPosition();
  

  exit(0); // exits the loop

}

I can't get my motor to rotate at high speeds. I tried adjusting the voltage on the power supply but that didn't do anything. I used StepperOnline's internal motor control program and I can get the motor to turn at high speeds that way but not when running my Arduino code. I did some trial and error and figured that while running my Arduino code, I can only go about 6000 steps/sec. When using StepperOnline's internal program, I can go like 1000 rpm (around 26,667 steps/sec for a 1600 steps/rev resolution). Anyone know why this would be?

Edit:
For those wondering what I my setup is:

StepperOnline, the company whom I get my equipment from, has their own software that can be used to manually control/monitor the motor. You use it by connecting the driver to a computer via a RS232 cable (I have a RS232 to USB adapter).

About 6000 steps for a Arduino Uno sounds about right. That is what I would expect.
The AccelStepper is very basic, it is not optimized with interrupts or so.

What is StepperOnline ?

i've found that i can't step a motor faster that ~1msec/step

What is StepperOnline's internal program? Does it run on an arduino? Is it built into the controller? Which controller do you have?

Inquiring minds want to know...

he's using AccelStepper

The maximum speed depends on the motor, the motor power supply voltage and current characteristics, the motor driver and whether you have set the current limit on the motor driver correctly.

None of which you mentioned.

1 Like

In this code, yes, but he mentioned it ran faster using their internal test program. Since he doesn't say which controller, I have no idea what that means.

StepperOnline is the company I got my equipment from. See my edited post for more details.

Please do not edit your original post. Add new information to a new post.

I agree. Don't have specific numbers, but the last time I ran a test, I was getting around 4-6,000 steps/second from an arduino with AccelStepper. In fact, on their home page, there used to be a section that discussed this. Much faster step pulse rates if you go to the 32-bit arduino versions.

It's still there:

AccelStepper: AccelStepper Class Reference. --

Performance

The fastest motor speed that can be reliably supported is about 4000 steps per second at a clock frequency of 16 MHz on Arduino such as Uno etc. Faster processors can support faster stepping speeds. However, any speed less than that down to very slow speeds (much less than one per second) are also supported, provided the run() function is called frequently enough to step the motor whenever required for the speed set. Calling setAcceleration() is expensive, since it requires a square root to be calculated.

There's a FastAccelStepper that uses a hardware timer for driving the stepper fast: GitHub - gin66/FastAccelStepper: A high speed stepper library for Atmega 168/328p (nano), Atmega32u4, Atmega 2560, ESP32, ESP32S2, ESP32S3, ESP32C3 and Atmel SAM Due

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.