Hi, I'm experiencing a problem using some simple functions of AccelStepper. Since I'm just starting out using AccelStepper, I tried a simple test of making the stepper motor go CW and CCW the same number of steps (100). The problem is that as it cycles back and forth it slowly advances further CW, i.e., it never really returns to the starting point (0). This "drift" might be 1-2 steps each cycle. It's pretty slow.
I'm using an Arduino Uno, a NEMA 17, 0.4,A 12V, 4-wire Bipolar 56.6oz.in stepper motor, a TB6600 Stepper Motor Driver from the Robot Shop (Product Code : RB-Dfr-727), and a 12V, 3A power supply.
My code is:
#include <AccelStepper.h>
const int pinSTEP=3;
const int pinDIR=4;
AccelStepper stepper(1, pinSTEP, pinDIR);
void setup()
{
stepper.setMaxSpeed(200.0);
stepper.setAcceleration(2500.0);
stepper.moveTo(100);
}
void loop()
{
if(stepper.distanceToGo() == 0)
{
// stepper.stop(); // I tried this but it didn't help
stepper.moveTo(-stepper.currentPosition());
// delay(10); // // I tried this also but it didn't help
}
stepper.run();
}
I read through all of the relevant questions raised on the AccelStepper Google Group and tried different ideas from there as well as everything I could think of with no success including
Using different commands (e.g., move vs. moveTo)
Various combinations of max speeds and accelerations (max speed up to 1000, accel up to 12500)
Different run commands (run, runToPosition, etc.)
Load (a thin aluminum 12” rail) and no load (bare shaft)
Adding a short delay (a few msec) between when the direction is changed and the run command (see above)
Using my own position variables, so as not to depend on currentPosition()
Using floating point numbers for max speed and acceleration
Up to 16:1 microstepping and no microstepping
Adding a stop() command when distanceToGo == 0 is true (see above)
When I try some basic code (see below) to accomplish the same thing without AccelStepper, the problem doesn't occur. This suggests that there's nothing wrong with the motor, driver, Arduino, and how they're wired.
// defines pins numbers
const int stepPin = 3;
const int dirPin = 4;
const int SPEED = 1000; // this is the width of the pulses
void setup()
{
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation (no microstepping)
for(int x = 0; x < 200; x++)
{
digitalWrite(stepPin,HIGH);
delayMicroseconds(SPEED);
digitalWrite(stepPin,LOW);
delayMicroseconds(SPEED);
}
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // One second delay
digitalWrite(dirPin,LOW); //Changes the rotations direction
// Makes 400 pulses for making two full cycle rotation
for(int x = 0; x < 200; x++)
{
digitalWrite(stepPin,HIGH);
delayMicroseconds(SPEED);
digitalWrite(stepPin,LOW);
delayMicroseconds(SPEED);
}
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000);
}
Thanks in advance for any ideas about what's going on.
--
You received this message because you are subscribed to the Google Groups "accelstepper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
still does it with max speed = 100/acc = 1000, and also with max speed = 50/acc = 250, all with no microstepping (200 steps/rev) and no load (bare motor shaft).
Ray Kimber
1. Using different commands (e.g., move vs. moveTo)
2. Various combinations of max speeds and accelerations (max speed up to 1000, accel up to 12500)
3. Different run commands (run, runToPosition, etc.)
4. Load (a thin aluminum 12” rail) and no load (bare shaft)
5. Adding a short delay (a few msec) between when the direction is changed and the run command (see above)
6. Using my own position variables, so as not to depend on currentPosition()
7. Using floating point numbers for max speed and acceleration
8. Up to 16:1 microstepping and no microstepping
9. Adding a stop() command when distanceToGo == 0 is true (see above)
--
You received this message because you are subscribed to a topic in the Google Groups "accelstepper" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/accelstepper/ZGCEFtEHOkM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to accelstepper...@googlegroups.com.
still does it with max speed = 100/acc = 1000, and also with max speed = 50/acc = 250, all with no microstepping (200 steps/rev) and no load (bare motor shaft).
I tried a more basic sketch and discovered that one extra step is sent each time the move/run commands are executed. With no microstepping 200 steps is a complete rev. If I move CW 200 and then CCW, I drift to the CW direction 2 steps (one for each move/run); If I move CW 200-1 steps and CCW -200-1 steps, I return to the starting point after each move. The code is
Thanks for the suggestion, Bart. I tried several more combinations of max speed and acceleration as you suggested:
I found the problem. I hooked up a scope to the step input to my driver to see if the Arduino was putting out the same number of steps for each move cycle (CW and CCW). It turned out it was, which suggested there was nothing wrong with the software. But I noticed that the pulses were very narrow, which led me to wonder if their pulse width was too short duration for the circuitry. I read through the AccelStepper.h file and saw that there was a setMinPulseWidth function, and that 20 usec was a typical width. I inserted the setMinPulseWidth(20) statement in the setup and the problem went away (I commented it out and the problem returned).
Glad it helped. Stay safe.
Ray Kimber
--
You received this message because you are subscribed to a topic in the Google Groups "accelstepper" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/accelstepper/ZGCEFtEHOkM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to accelstepper...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/accelstepper/0d06af13-b1ca-44ca-aaac-23b14e575a73%40googlegroups.com.