i have the following problem:
when using accelsteper to move the steppers at higher speeds (e.g. 2 steppers at 500 steps / second) i experience a delayed reaction to the commands stop(), moveTo() and setMaxSpeed().
usually stop() is called by an external interrupt, but this also happens if stop() is called directly in the loop() (the same with moveTo() and setMaxSpeed() ). I2C communication speed is set to 400kHz.
the longer the steppers move, the longer the delay becomes (10s movement - 1s delay, 30s movement - 4s delay, ...) . there is no noticable delay when moving at low speeds (~100steps / second).
i can reproduce the behaviour with this code:
#include <AccelStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
Adafruit_MotorShield AFMStop(0x60); // Default address, no jumpers
// Connect two steppers with 200 steps per revolution (1.8 degree)
// to the top shield
Adafruit_StepperMotor *myStepper1 = AFMStop.getStepper(200, 1);
Adafruit_StepperMotor *myStepper2 = AFMStop.getStepper(200, 2);
// you can change these to DOUBLE or INTERLEAVE or MICROSTEP!
// wrappers for the first motor!
void forwardstep1() {
myStepper1->onestep(FORWARD, SINGLE);
}
void backwardstep1() {
myStepper1->onestep(BACKWARD, SINGLE);
}
// wrappers for the second motor!
void forwardstep2() {
myStepper2->onestep(FORWARD, DOUBLE);
}
void backwardstep2() {
myStepper2->onestep(BACKWARD, DOUBLE);
}
// Now we'll wrap the 2 steppers in an AccelStepper object
AccelStepper stepper1(forwardstep1, backwardstep1);
AccelStepper stepper2(forwardstep2, backwardstep2);
void setup()
{
AFMStop.begin(); // Start the top shield
Serial.begin(9600);
stepper1.setMaxSpeed(500.0);
stepper1.setAcceleration(100.0);
stepper1.moveTo(5000000);
stepper2.setMaxSpeed(500.0);
stepper2.setAcceleration(100.0);
stepper2.moveTo(5000000);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH); //switch led on
pinMode(2, INPUT_PULLUP);
attachInterrupt(0, interrupt, FALLING);
TWBR = ((F_CPU / 400000l) - 16) / 2; //set I2C communication speed to 400kHz
}
void loop()
{
stepper1.run();
stepper2.run();
}
void interrupt()
{
stepper1.stop();
stepper2.stop();
digitalWrite(13, LOW);
}
when i let the steppers run for ~30s, i push the button, the led turns off, after ~4s the motors start spinning down.
when i let the steppers run for ~6s only, the delay about 1s.