Stepper Motor issues at certain speeds

I'm trying to use the Arduino Uno R3 to drive a Applied Motion PDO2035 stepper drive. This is an older drive that only does 1/2 stepping. It has a built in oscillator which is good for testing. I have a NEMA 17 motor that's good for 1.7Amps/phase. I've worked a lot with industrial applications with stepper motors and never have any issues. With the built in oscillator I can drive this motor up through the entire speed range and reach a max speed of 12,000 steps/sec with a 400 steps/rev motor. I even only set the motor current for 0.5 amps. Of course to reach that speed I must set the acceleration. So I wouldn't think the drive would be the issue.

Now when I go to use the Arduino I have issues. First I tried using accelStepper. I read an analog input pot value and have some logic that uses elapsedMillis to check the pot every 100 msec and some deadband to filter out any noise of the pot, then I use setSpeed to set a new speed. Then I have runSpeed() going all the time. Even if I set the pot down low and slowly increase the speed I seem to hit spots where the speed doesn't appear to be changing (even though I have a println statement showing me what the new value is everytime I adjust the pot. I also hit spots that make the motor "squall or chatter". I'm only trying to get to 1200 steps/sec.

This isn't the entire code, and I know it's not pretty but I've butchered the heck out of it trying to figure out what the problem is. The analog read and calculation could be within the Readjust timer "If" statement but I needed it elsewhere for some other parts of the code thus it ended up outside where it is calculated every scan verses every 100 mSec. Even with the wasted cycle time of the extra code I wouldn't think it would be causing the problem.


elapsedMillis Readjust_Speed_Timer; // somewhere at the beginning of the program
.
.
AI_POT_Val = analogRead(AI_POT_Pin); // set AI_POT_Val to FLOAT so calc below done correctly, needs fixed in future
.
.
stepper_Mtr_Spd_Deadband = AI_POT_Fast_Val / 1023 * Stepper_Mtr_Max_Spd * 2 - Stepper_Mtr_Max_Spd;
.
.
if(Readjust_Speed_Timer >= Readjust_Speed_Timer_Setpt){
if(abs(Stepper_Mtr_Spd_Setpt - Stepper_Mtr_Spd_Deadband) > 5){
Stepper_Mtr_Spd_Setpt = Stepper_Mtr_Spd_Deadband;
Stepper_Mtr.setSpeed(Stepper_Mtr_Spd_Setpt);
Serial.println(Stepper_Mtr_Spd_Setpt);
}
Readjust_Speed_Timer = 0; //Initialize Readjust Timer
}
Stepper_Mtr.runSpeed();

I also tried doing my own pulses using elpasedMircos, it has the same problem.

What am I doing wrong? I'm new to this and having programmed in "C" for a long time, so I'm a little rusty. Or does the Arduino just have limitations on the output pins. What duty cycle should one pulse at, I tried 50% with the elapsedMicros, I'm not sure what accelStepper uses.

Well I got the following code to give fair performance. I guess you really can't have any extra code, including the analog read within the every 100mSec timer really helped;

#include <elapsedMillis.h>
 
// assign I/O pins (Traffic Cop)
int DO_Stepper_Dir_Pin = 2;
int DO_Stepper_Step_Pin = 3;
int AI_POT_Pin = A0;

// Initialize I/O values
float AI_POT_Val = 0;

// Initialize other values
unsigned long Stepper_Mtr_Pulse_Timer_Setpt = 0;
boolean Stepper_Mtr_Pulse_State = LOW;

// Initialize Timers
elapsedMillis Readjust_Speed_Timer;
elapsedMicros Stepper_Mtr_Pulse_Timer;

// Initialize Stepper Motor Values
int Stepper_Mtr_Spd_Setpt = 0;                      // Stepper Motor Speed Setpoint in Steps per Second 
int Stepper_Mtr_Spd_Deadband = 0;                   // Used to set a deadband around the setpoint

// Settings that can be modified
int Stepper_Mtr_Max_Spd = 1200;                     // Stepper Motor Max speed in Steps per Second
unsigned long Readjust_Speed_Timer_Setpt = 100;     // In mSec 

void setup() {                
  // initialize the I/O.
  pinMode(DO_Stepper_Dir_Pin, OUTPUT);
  pinMode(DO_Stepper_Step_Pin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
// Stepper Motor logic
  if(Readjust_Speed_Timer >= Readjust_Speed_Timer_Setpt){
    AI_POT_Val = analogRead(AI_POT_Pin);  // Read the Slow Speed Pot
    Stepper_Mtr_Spd_Deadband = AI_POT_Val / 1023 * Stepper_Mtr_Max_Spd * 2 - Stepper_Mtr_Max_Spd;
    if(abs(Stepper_Mtr_Spd_Setpt - Stepper_Mtr_Spd_Deadband) > 5){
        Stepper_Mtr_Spd_Setpt = Stepper_Mtr_Spd_Deadband;
        //Stepper_Mtr_Pulse_Timer_Setpt = abs(500000 / Stepper_Mtr_Spd_Setpt);
        Serial.println(Stepper_Mtr_Spd_Setpt);
    }
      Readjust_Speed_Timer = 0;  //Initialize Readjust Timer
  }
  if(Stepper_Mtr_Spd_Setpt < 0){
    digitalWrite(DO_Stepper_Dir_Pin, HIGH);
  }
  else{
    digitalWrite(DO_Stepper_Dir_Pin, LOW);
  }
  Stepper_Mtr_Pulse_Timer_Setpt = abs(500000 / Stepper_Mtr_Spd_Setpt);    
  if(Stepper_Mtr_Pulse_Timer >= Stepper_Mtr_Pulse_Timer_Setpt){
    Stepper_Mtr_Pulse_State = !Stepper_Mtr_Pulse_State;
    digitalWrite(DO_Stepper_Step_Pin, Stepper_Mtr_Pulse_State);
    Stepper_Mtr_Pulse_Timer = 0;
  }
}

Can you please re-edit that post to use

// code tags please....