it seems to be a problem of the CPU-speed
I took your code-example and just added serial-debug-output to see the real numbers
even with a medium acceleration of 4000
With a Teensy 4.1
with using stepper.run() which does use acceleration
I get this snapshots of current-position and speed
Setup-Start bt_tama
"2:" stepper.currentPosition()=1
"3:" stepper.speed()=110.26
"2:" stepper.currentPosition()=546
"3:" stepper.speed()=2090.87
"2:" stepper.currentPosition()=2095
"3:" stepper.speed()=4094.26
"2:" stepper.currentPosition()=4650
"3:" stepper.speed()=6099.31
"2:" stepper.currentPosition()=7845
"3:" stepper.speed()=6400.00
"2:" stepper.currentPosition()=11050
"3:" stepper.speed()=6400.00
"2:" stepper.currentPosition()=14255
"3:" stepper.speed()=6400.00
"2:" stepper.currentPosition()=17460
"3:" stepper.speed()=6400.00
"2:" stepper.currentPosition()=20665
"3:" stepper.speed()=6400.00
"2:" stepper.currentPosition()=23871
"3:" stepper.speed()=6400.00
"2:" stepper.currentPosition()=27076
"3:" stepper.speed()=6400.00
"2:" stepper.currentPosition()=30281
"3:" stepper.speed()=6400.00
"2:" stepper.currentPosition()=33484
"3:" stepper.speed()=6270.58
"2:" stepper.currentPosition()=36125
"3:" stepper.speed()=4265.47
"2:" stepper.currentPosition()=37760
"3:" stepper.speed()=2261.75
"2:" stepper.currentPosition()=38391
"3:" stepper.speed()=260.81
"2:" stepper.currentPosition()=38400
"3:" stepper.speed()=0.00
"2:" stepper.currentPosition()=38400
"3:" stepper.speed()=0.00
using stepper.runSpeed() does not accelerate but uses the speed specified with stepper.setSpeed() immidiately from the first step on
Setup-Start bt_tama
"2:" stepper.currentPosition()=1
"3:" stepper.speed()=6400.00
"2:" stepper.currentPosition()=3206
"3:" stepper.speed()=6400.00
"2:" stepper.currentPosition()=6411
"3:" stepper.speed()=6400.00
"2:" stepper.currentPosition()=9616
"3:" stepper.speed()=6400.00
"2:" stepper.currentPosition()=12821
"3:" stepper.speed()=6400.00
"2:" stepper.currentPosition()=16026
"3:" stepper.speed()=6400.00
"2:" stepper.currentPosition()=19231
"3:" stepper.speed()=6400.00
"2:" stepper.currentPosition()=22436
"3:" stepper.speed()=6400.00
"2:" stepper.currentPosition()=25642
"3:" stepper.speed()=6400.00
"2:" stepper.currentPosition()=28847
"3:" stepper.speed()=6400.00
"2:" stepper.currentPosition()=32052
This is the code I used on the Teensy 4.1
// MACRO-START * MACRO-START * MACRO-START * MACRO-START * MACRO-START * MACRO-START *
https://forum.arduino.cc/t/comfortable-serial-debug-output-short-to-write-fixed-text-name-and-content-of-any-variable-code-example/888298
#define dbg(myFixedText, variableName) \
Serial.print( F(#myFixedText " " #variableName"=") ); \
Serial.println(variableName);
// usage: dbg("1:my fixed text",myVariable);
// myVariable can be any variable or expression that is defined in scope
#define dbgi(myFixedText, variableName,timeInterval) \
do { \
static unsigned long intervalStartTime; \
if ( millis() - intervalStartTime >= timeInterval ){ \
intervalStartTime = millis(); \
Serial.print( F(#myFixedText " " #variableName"=") ); \
Serial.println(variableName); \
} \
} while (false);
// usage: dbgi("2:my fixed text",myVariable,1000);
// myVariable can be any variable or expression that is defined in scope
// third parameter is the time in milliseconds that must pass by until the next time a
// Serial.print is executed
// end of macros dbg and dbgi
// MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END *
#include <AccelStepper.h>
#define X_STEP_PIN 2
#define X_DIR_PIN 3
#define X_ENABLE_PIN 4
int rev = 32 * 200UL; //single revolution for 1/32 microstepping
AccelStepper stepper = AccelStepper(1, X_STEP_PIN, X_DIR_PIN);
void setup() {
Serial.begin(115200);
Serial.println("Setup-Start bt_tama");
stepper.setMaxSpeed(rev); //One revolution per second
stepper.setAcceleration(4000);
stepper.moveTo(6 * rev);
stepper.setSpeed(rev);
}
unsigned long myCounter = 0;
void loop () {
myCounter++;
//stepper.setSpeed(rev);
stepper.runSpeed();
//stepper.run();
dbgi("2:", stepper.currentPosition(), 500);
dbgi("3:", stepper.speed(), 500);
//dbgi("4:", myCounter, 500);
}
additionally I tested an Arduino Uno ang got the same results as you
with stepper.run() the speed was below the set maximum
then I tested your code with an Seeeduino XIAO
which did not reach the required speed of 6400 steps per second with stepper.run()
measured with my oscilloscope the Seeediuno XIAO reached only 6290 steps per second
best regards Stefan