(Re-posted to correct small compile issue)
Jim,
This worked for me when I needed it but I haven't looked at it for a long time so it's offered 'as is'. Feel free to play with it as you want.
As you would know, because we are only inrterested in the MCU's stepping rate, no drivers or motors need to be connected, just enter your own parameters, open the serial monitor and run the program.
Geoff
/* Stepper Motor Performance Test
* Created by Geoff Smith 2019
* No Copyright
*
* Performance data only recorded for stepper1.
* Other steppers are included to load up the mcu stepping rate. REM out as required.
* ----------------------------------------------------------------------------------- */
#include <Arduino.h>
#include <AccelStepper.h>
int S1_dir1 = 18;
int S1_pul1 = 19;
int S2_dir1 = 32;
int S2_pul1 = 33;
int S3_dir1 = 25;
int S3_pul1 = 26;
int S4_dir1 = 16;
int S4_pul1 = 17;
AccelStepper stepper1(AccelStepper::DRIVER, S1_pul1, S1_dir1);
AccelStepper stepper2(AccelStepper::DRIVER, S2_pul1, S2_dir1);
AccelStepper stepper3(AccelStepper::DRIVER, S3_pul1, S3_dir1);
AccelStepper stepper4(AccelStepper::DRIVER, S4_pul1, S4_dir1);
uint32_t start_time = 0;
uint32_t accel_time = 0;
long i = 0;
long spd1 = 0;
long spd1Max = 0;
long nomSpeed = 0; // Speed recorded at the nominated step position.
long maxSpeedPosition = 0;
long finishPosition = 0;
long pulsesPerRevolution = 400; // User to set according to: motor_steps + gearing + microstepping.
// Enter your stepper variables here. ---------------------
long nomPosition; // nominated position at which the speed is recorded.
long targetPosition1 = 32000;
long acceleration1 = 20000; // Big number to get the stepper1 recorded 'spd1Max'
long maxSpeed1 = 20000; // Big number to get the stepper1 recorded 'spd1Max'
int travel_time = 0;
long targetPosition2 = 18000;
long acceleration2 = 24000;
long maxSpeed2 = 24000;
long targetPosition3 = 2000;
long acceleration3 = 8000;
long maxSpeed3 = 8000;
long targetPosition4 = 4000;
long acceleration4 = 8000;
long maxSpeed4 = 8000;
int button = 10; // Not used. Optional.
void setup()
{
pinMode(button, INPUT_PULLUP);
pinMode(S1_dir1, OUTPUT);
pinMode(S1_pul1, OUTPUT);
pinMode(S2_dir1, OUTPUT);
pinMode(S2_pul1, OUTPUT);
pinMode(S3_dir1, OUTPUT);
pinMode(S3_pul1, OUTPUT);
pinMode(S4_dir1, OUTPUT);
pinMode(S4_pul1, OUTPUT);
stepper1.setMinPulseWidth(20); // This is required for high speed MCU's. It's OK for all MCU's.
stepper2.setMinPulseWidth(20);
stepper3.setMinPulseWidth(20);
stepper4.setMinPulseWidth(20);
Serial.begin(9600);
Serial.println();
Serial.println();
Serial.println("starting test");
Serial.println();
stepper1.setAcceleration(acceleration1);
stepper1.setMaxSpeed(maxSpeed1);
stepper1.moveTo(targetPosition1);
stepper2.setAcceleration(acceleration2);
stepper2.setMaxSpeed(maxSpeed2);
stepper2.moveTo(targetPosition2);
stepper3.setAcceleration(acceleration3);
stepper3.setMaxSpeed(maxSpeed3);
stepper3.moveTo(targetPosition3);
stepper4.setAcceleration(acceleration4);
stepper4.setMaxSpeed(maxSpeed4);
stepper4.moveTo(targetPosition4);
nomPosition = targetPosition1/2; // Halfway travel point, or modify as required.
start_time = millis();
}
void loop()
{
i = 0;
spd1Max = 0;
nomSpeed = 0;
maxSpeedPosition = 0;
finishPosition = 0;
travel_time = 0;
start_time = millis();
while (stepper1.isRunning() || stepper2.isRunning() || stepper3.isRunning() || stepper4.isRunning()) // || stepper2.isRunning() || stepper3.isRunning() || stepper4.isRunning()
{
i++;
stepper1.run(); // User to modify if testing for 'runSpeed()'
stepper2.run();
stepper3.run();
stepper4.run();
if (stepper1.distanceToGo() == nomPosition)
nomSpeed = stepper1.speed();
if (stepper1.speed() > spd1Max)
spd1Max = stepper1.speed();
if (stepper1.speed() < maxSpeed1 && stepper1.currentPosition() < targetPosition1/2)
{
maxSpeedPosition = stepper1.currentPosition();
accel_time = millis() - start_time;
}
if (stepper1.distanceToGo() == 0) travel_time = millis() - start_time;
}
finishPosition = stepper1.currentPosition();
Serial.print("Set Acceleration:\t");
Serial.println(acceleration1);
Serial.print("Set Max_Speed:\t\t");
Serial.println(maxSpeed1);
Serial.print("Stepper Pulses/REV:\t");
Serial.println(pulsesPerRevolution);
Serial.println();
Serial.print("Target Position:\t");
Serial.println(targetPosition1);
Serial.print("Travel time:\t\t");
Serial.println(travel_time);
Serial.print("Main Loop count:\t");
Serial.println(i);
Serial.print("Max speed - Returned:\t");
Serial.println(spd1Max);
Serial.println();
Serial.print("Nom Position:\t\t");
Serial.println(nomPosition);
Serial.print("Speed at Nom Position:\t");
Serial.println(nomSpeed);
Serial.print("Stepper rpm at Nom Pos:\t");
Serial.println((nomSpeed*60.0/pulsesPerRevolution),0);
Serial.println();
Serial.print("Position: Max Speed:\t");
Serial.println(maxSpeedPosition);
Serial.print("Time to Max Speed:\t");
Serial.println(accel_time);
Serial.print("Finish Position: :\t");
Serial.println(finishPosition);
Serial.println();
Serial.println();
while(1);
}