I’m using the Adafruit 324 stepper (200 steps/rev, 12 V, 0.35 A) on an Adafruit Motor/Stepper/Servo Shield for Arduino v2 Kit - v2.0. The stepper is powered directly via a 12 VDC/1 amp power supply connected to the shield. I’m using the newest version of Adafruit_Motorshield to control the stepper.
For the intended application (movement of a linear stage with a defined speed) I require rather exact speed control of my stepper.
However, I noticed that the actual speed (rpm) of the stepper deviates from the set speed, independent of the operation mode (Double/Interleave/Microstep). With increasing speeds, the discrepancy increases significantly (e.g. in the case of the sample code below, the actual forward speed is around 3.7 rpm, compared to a set speed of 5 rpm; the backward speed is around 6.6 rpm instead of 12 rpm).
In all cases, the total number of steps (= the moving distance of my linear stage) remains correct.
After some tests at various operation parameters and some calculations, I found out that for each step (or in the case of microstepping, microstep), I “lose” about 1.3 ms, independent of the operation mode and the set speed, so I have a cumulative effect - each step takes 1.3 ms longer than it should. Where does this value come from? Is there a possibility to correct for this?
I already increased the i2c bus rate to 400 kHz, as recommended in the FAQ (http://learn.adafruit.com/adafruit-moto ... rduino/faq), but I could not notice any improvements. Also, I tried to see whether the voltage of the power supply could be a problem, but I obtained the exact same results with a 9 V supply instead of 12 V.
Here’s the sample code I used for the project (I used a button push to start the routine):
Code: Select all
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);
int switchPin = 6;
int val;
void setup() {
digitalWrite(switchPin, HIGH);
Serial.begin(9600);
Serial.println("Stepper test!");
AFMS.begin();
myMotor->setSpeed(320);
}
void loop() {
while (digitalRead(switchPin) == LOW)
{
myMotor->setSpeed(5);
myMotor->step(2000, FORWARD, MICROSTEP);
delay(1000);
myMotor->setSpeed(12);
myMotor->step(2000, BACKWARD, MICROSTEP);
}
}