Not sure if this is possible or not. I'm using a closed loop stepper driven ballscrew and need to change directions as quickly as possible. Currently the motor driver is happy with a 400 ramp length (1 revolution), anything shorter than that and it trips out (too many lost steps I believe) but it's always on the acceleration side that it happens so I believe I could shorten the deceleration ramp but reading through the documentation I can't see where that's an option.
I know I could reset it in the code where it resets the moveto to the other direction but there's already a dwell for some reason that I'm working on getting rid of so I don't want to add more code at that spot and make it worse.
#include <MobaTools.h>
/* eps32 test code */
const int SEL_SW = 13; // Manual / auto select switch
const int MAN_UP = 16; // Stepper Manual Up button
const int MAN_DN = 17; // Stepper Manual Down Button
const int AUT_START = 18; // Auto Start Button
const int AUT_STOP = 19; // Auto Stop Button
const int HOME_SW = 33; // Manual / auto select switch
const int DIR = 2; // Stepper DIR Pin 2
const int STEP = 4; // Stepper STEP Pin 4
const int SPEED_IN = 32; // Analog Input
//const int CYCLES_IN = xx; // Analog Input
//const int DWELL_IN = xx; // Analog Input
bool isStepping = false;
bool home_state = 0;
bool MAN_UP_STATE = LOW;
bool MAN_UP_PREV = LOW;
bool MAN_DN_STATE = LOW;
bool MAN_DN_PREV = LOW;
bool AUT_START_STATE = LOW;
//int DWELL_DATA = 0;
//int DWELL = 0;
//int Start_Time = 0;
//int Stop_Time = 0;
int Cycle_To_Do = 0;
int cycle_cnt=0;
long maxSpeed = 20000;
int ramp_len=400;
bool HOMED = false;
// ballscrew is 5mm pitch
const long EndPoint = 36576; //52832 = 26" 36576 = 18" 24384 = 12"
long nextPos = 0;
MoToStepper myStepper (400,STEPDIR); // setps per rev and what type of control
//MoToTimer stepperPause; // leftover from example
void setup()
{
Serial.begin(115200);
pinMode(AUT_START,INPUT_PULLUP);
pinMode(AUT_STOP,INPUT_PULLUP);
pinMode(MAN_UP,INPUT_PULLUP);
pinMode(MAN_DN,INPUT_PULLUP);
pinMode(HOME_SW,INPUT_PULLUP);
myStepper.attach( STEP, DIR ); //4, 2
myStepper.setRampLen( ramp_len ); //400
delay(2000); // need to prevent partial run when loading
Cycle_To_Do=2; // this will come from selector switch CYCLES_IN
// ***** HOMING THE CARRIGE *****
myStepper.setZero(0); //
myStepper.setSpeed( 5000 ); // slow speed for homing
myStepper.moveTo(3000); // move the carrige down some
while ( myStepper.distanceToGo()!=0 )
{
//Serial.println("Staging");
myStepper.moveTo(3000);
}
while (HOMED == false ) // move up to home switch
{
//Serial.println("Homing");
home_state = digitalRead(HOME_SW); // Check the switch
// It was not working
// correctly when I used
// if (digitalRead(HOME_SW) == 0)
// but the switch was buggy
// so maybe ok now that its fixed
myStepper.moveTo(myStepper.currentPosition()-400); // keep moving up
if (home_state==0)
{
myStepper.stop();
myStepper.setZero(1200); // come down off the switch
myStepper.moveTo(0);
HOMED=true;
}
if (myStepper.distanceToGo()==0 && HOMED == true)
{
myStepper.setSpeed(maxSpeed); // Set full speed
Serial.println("HOMED");
}
}
}
void loop()
{
if(digitalRead(SEL_SW)==false) //****************** manual mode ***********
// none of this is tested yet
{
if(digitalRead(MAN_UP)==false && HOMED == false)
{
Serial.println("UP button pressed");
if (myStepper.currentPosition()-100 >0)
{
myStepper.moveTo(myStepper.currentPosition()-100);
if(digitalRead(HOME_SW)==false)
{
myStepper.stop();
Serial.println("LIMIT");
}
}
}
else if(digitalRead(MAN_DN)==false && HOMED == false)
{
myStepper.moveTo(myStepper.currentPosition()+100);
}
}
else //************************ automnatic mode **************************
{ // This is where I'm working now
if( !isStepping ) // not currently cycling
{
if(digitalRead(AUT_START)==false) // check for start button press
{
Serial.println("START button pressed");
isStepping = true;
myStepper.moveTo(EndPoint);
}
}
else // is running cycles
{
if ( myStepper.distanceToGo()==0 ) // reached target
{
if(myStepper.currentPosition() == EndPoint) // if it's at the bottom
{
myStepper.moveTo(0); // new target at the top
}
else // it's at the top
{
myStepper.moveTo(EndPoint); // new targer at the bottom
cycle_cnt++; // count the # of cycles
}
// if it's at the top
// and had done the # of
// cycles needed
if( cycle_cnt>=Cycle_To_Do && myStepper.currentPosition() == 0)
{
myStepper.stop();
isStepping = false;
cycle_cnt=0;
Serial.println("done");
}
}
else // moving between end points
{
if(digitalRead(AUT_STOP)==false) // check the stop button
{
Serial.println("STOP button pressed");
myStepper.setSpeed(0); // stop with ramp
stepperPause.setTime( 1000 ); // not sure if needed
myStepper.setSpeed(maxSpeed); // reset speed
myStepper.moveTo(0); // go back to the up position
cycle_cnt=Cycle_To_Do; // cancel any outstanding cycles
isStepping = false;
}
}
}
}
}
Any help would be appreciated
Thanks.