The ramps X Clone as X1 works beautifully
But I am having a strange problem:
If you look at the code ,there are two different parts. One is for simple move of a srepper the other is for a simple acceleration. The simple move with X and clone X1 work. Simple Accel clone X1 does not.While X fulfills its command to move to the right side by a thousand steps , X1 does not: It moves 300 steps to the left (approx) and then 700 steps to the right.!!
Can anyone find the bug?
Thanks
#include<Stepper.h>
#define X_DIR_PIN 55
#define X_STEP_PIN 54
#define X_ENABLE_PIN 38
#define X_MIN_PIN 3
#define X_MAX_PIN 2
#define X1_DRIVER_TYPE DR8825
#define X1_DIR 55
#define X1_STP 54
#ifndef X1_STEP_PIN
#define X1_STEP_PIN 36
#endif
#ifndef X1_DIR_PIN
#define X1_DIR_PIN 34
#endif
#ifndef X1_ENABLE_PIN
#define X1_ENABLE_PIN 30
#endif
#ifndef X1_CS_PIN
#define X1_CS_PIN AUX1_07
#endif
void setup() {
pinMode(X_STEP_PIN, OUTPUT);
pinMode(X_DIR_PIN, OUTPUT);
pinMode(X_ENABLE_PIN, OUTPUT);
pinMode(X1_STEP_PIN, OUTPUT);
pinMode(X1_DIR_PIN, OUTPUT);
pinMode(X1_ENABLE_PIN, OUTPUT);
}
void simpleMove(int steps) {
int interval = 1000;
for (int i = 0; i < steps; i++) {
digitalWrite(X_STEP_PIN, HIGH);
digitalWrite(X_STEP_PIN, LOW);
digitalWrite(X1_STEP_PIN, HIGH);
digitalWrite(X1_STEP_PIN, LOW);
delayMicroseconds(interval);
}
}
void simpleAccel(int steps) {
int lowSpeed = 3000;
int highSpeed = 200;
int change = 2;
int rampUpStop = (lowSpeed - highSpeed) / change;
if ( rampUpStop > steps / 2 )
rampUpStop = steps / 2;
int rampDownStart = steps - rampUpStop;
int d = lowSpeed;
for (int i = 0; i < steps; i++) {
int interval = 100;
digitalWrite(X_STEP_PIN, HIGH);
digitalWrite(X_STEP_PIN, LOW);
digitalWrite(X1_STEP_PIN, HIGH);
digitalWrite(X1_STEP_PIN, LOW);
delayMicroseconds(d);
if ( i < rampUpStop )
d -= change;
else if ( i > rampDownStart )
d += change;
}
}
void loop() {
digitalWrite(X_DIR_PIN, LOW);
simpleMove(1000);
digitalWrite(X1_DIR_PIN, LOW);
simpleMove(1000);
delay(10000);
digitalWrite(X_DIR_PIN, HIGH);
simpleAccel(1000);
digitalWrite(X1_DIR_PIN, HIGH);
simpleAccel(1000);
//while (true);
delay(10000);
}