Thank Robin2
SpeedyStepper library is here: GitHub - Stan-Reifel/SpeedyStepper: Stepper motor control library for Arduino
About my sketch, this is an example that gets the motor to rotate 100k steps at 2500 steps per second, accelerating and decelerating at 500 step/s2.
the loop() continuously calls the .processMovement() function. Arduino Mega is able to handle this speed.
Example1:
#include <SpeedyStepper.h>
SpeedyStepper stepper1;
#define STEPPER1_EN 23
#define STEPPER1_DIR 25
#define STEPPER1_STEP 27
#define STEPPER1_M1 29
#define STEPPER1_M2 31
#define STEPPER1_M3 33
void setup() {
pinMode(STEPPER1_EN, OUTPUT); // Big Easy Driver Enable pin motor#1
pinMode(STEPPER1_DIR, OUTPUT); // Big Easy Driver Dir pin motor#1
pinMode(STEPPER1_STEP, OUTPUT); // Big Easy Driver Step pin motor#1
pinMode(STEPPER1_M1, OUTPUT); // Big Easy Driver M1 pin motor#1
pinMode(STEPPER1_M2, OUTPUT); // Big Easy Driver M2 pin motor#1
pinMode(STEPPER1_M3, OUTPUT); // Big Easy Driver M3 pin motor#1
digitalWrite(STEPPER1_M1, LOW); // Set M1,M2,M3 to LOW for FULL STEP
digitalWrite(STEPPER1_M2, LOW);
digitalWrite(STEPPER1_M3, LOW);
digitalWrite(STEPPER1_EN, LOW); // LOW=Enable motor
stepper1.connectToPins(STEPPER1_STEP, STEPPER1_DIR);
stepper1.setSpeedInStepsPerSecond(2500);
stepper1.setAccelerationInStepsPerSecondPerSecond(500);
stepper1.setupMoveInSteps(100000); // Set a 100k steps rotation
}
void loop() {
stepper1.processMovement();
}
Problems arrive when you write more functions in the loop(), because of time the MPU takes to run instructions SETS could be too long for the motor to have a smooth rotation, as every time the MPU calls stepper1.processMovement(); there could be some "missed" steps.
Obviously, this problem depends on motor speed/acceleration and time consumption of the different instructions.
In these cases I chop my instructions in short sets, and every time I call the same function stepper1.processMovement();
Example2:
#include <SpeedyStepper.h>
SpeedyStepper stepper1;
#define STEPPER1_EN 23
#define STEPPER1_DIR 25
#define STEPPER1_STEP 27
#define STEPPER1_M1 29
#define STEPPER1_M2 31
#define STEPPER1_M3 33
void setup() {
pinMode(STEPPER1_EN, OUTPUT); // Big Easy Driver Enable pin motor#1
pinMode(STEPPER1_DIR, OUTPUT); // Big Easy Driver Dir pin motor#1
pinMode(STEPPER1_STEP, OUTPUT); // Big Easy Driver Step pin motor#1
pinMode(STEPPER1_M1, OUTPUT); // Big Easy Driver M1 pin motor#1
pinMode(STEPPER1_M2, OUTPUT); // Big Easy Driver M2 pin motor#1
pinMode(STEPPER1_M3, OUTPUT); // Big Easy Driver M3 pin motor#1
digitalWrite(STEPPER1_M1, LOW); // Set M1,M2,M3 to LOW for FULL STEP
digitalWrite(STEPPER1_M2, LOW);
digitalWrite(STEPPER1_M3, LOW);
digitalWrite(STEPPER1_EN, LOW); // LOW=Enable motor
stepper1.connectToPins(STEPPER1_STEP, STEPPER1_DIR);
stepper1.setSpeedInStepsPerSecond(2500);
stepper1.setAccelerationInStepsPerSecondPerSecond(500);
stepper1.setupMoveInSteps(100000); // Set a 100k steps rotation
}
void loop() {
//
// .... ISTRUCTIONS SET 1
//
stepper1.processMovement();
//
// .... ISTRUCTIONS SET 2
//
stepper1.processMovement();
//
// .... ISTRUCTIONS SET 3
//
stepper1.processMovement();
//
// .... ISTRUCTIONS SET 4
//
stepper1.processMovement();
}
This is not a solution as it cannot consider exactly how much time passes between .processMovement(); calls.
This is reason I'm looking for a timed automatic call of .processMovement();
What do you think about?
Thanks
Raf