Not getting full rpm out of my stepper motor

The motor you see in this video is controlled by an Arduino nano running GRBL and my PC running universal G-code sender.

video

When I’m using the same Arduino nano with a potentiometer running the sketch below, I get only a fraction of the max rpm.

/*
  Stepper Motor Test
  stepper-test01.ino
  Uses MA860H or similar Stepper Driver Unit
  Has speed control & reverse switch
  
  DroneBot Workshop 2019
  https://dronebotworkshop.com
*/

// Defin pins

int reverseSwitch = 2;  // Push button for reverse
int driverPUL = 7;    // PUL- pin
int driverDIR = 6;    // DIR- pin
int spd = A0;     // Potentiometer

// Variables

int pd = 1000;       // Pulse Delay period
boolean setdir = LOW; // Set Direction

// Interrupt Handler

void revmotor (){

  setdir = !setdir;
  
}


void setup() {
  pinMode (driverPUL, OUTPUT);
  pinMode (driverDIR, OUTPUT);
  attachInterrupt(digitalPinToInterrupt(reverseSwitch), revmotor, FALLING);
  
}

void loop() {
  
    pd = map((analogRead(spd)),0,1023,9000,0);
    digitalWrite(driverDIR,setdir);
    digitalWrite(driverPUL,HIGH);
    delayMicroseconds(pd);
    digitalWrite(driverPUL,LOW);
    delayMicroseconds(pd);
   
 
}

Could someone explain to me what I need to change to get the full rpm from the motor using only the Nano and a potentiometer.

MB

Can't explain it, but if you used serial.Print() to show what actual values you are getting from the code here:

pd = map((analogRead(spd)),0,1023,9000,0);
digitalWrite(driverDIR,setdir);
digitalWrite(driverPUL,HIGH);
delayMicroseconds(pd);
digitalWrite(driverPUL,LOW);
delayMicroseconds(pd);

What value is (pd) after you map the analog read?

Paul

A possible reason is that your code is not accelerating the motor up to speed and back to a stop.

Have a look at the AccelStepper library

...R

Hi Paul,

I’ve checked the map function and pd is giving the value it should (between 9000 and 0).

As Robin states most motors need to ramp up and ramp down.
Grbl uses the parameters you gave it to do those in a seamless manner and is optimised for that aspect.

I noticed you changed a parameter in GRBL but did not take note of what the other parameters were in regards to that axis ?

I dont use accelstepper myself but trust Robins approach.

Do you have a pullup or pulldown resistor on the reverse button pin? If it's floating it may be randomly reversing the motor.

ballscrewbob:
As Robin states most motors need to ramp up and ramp down.
Grbl uses the parameters you gave it to do those in a seamless

The only stepper motor I've seen that can get to top speed without ramping was 6mm in diameter,
so unless your stepper is ultra-compact, you always need ramping to get to top speed. Physical
objects have inertia, and that larger the more inertia (for rotating objects its moment of inertia
which scales with size to the power 5, so the ramping rate is very dependent on motor size)

Robin2:
A possible reason is that your code is not accelerating the motor up to speed and back to a stop.

Have a look at the AccelStepper library

...R

MarkT:
The only stepper motor I've seen that can get to top speed without ramping was 6mm in diameter,
so unless your stepper is ultra-compact, you always need ramping to get to top speed. Physical
objects have inertia, and that larger the more inertia (for rotating objects its moment of inertia
which scales with size to the power 5, so the ramping rate is very dependent on motor size)

Thanks guys. This sounds very logical. I will give the Accelstepper library a try.

JCA34F:
Do you have a pullup or pulldown resistor on the reverse button pin? If it's floating it may be randomly reversing the motor.

Yes