Hi All, I have a problem which I hope is going to be very simple to solve. My requirement is very simple - I wish to accelerate a stepper to a particular speed and run at constant speed until a button press is detected at which point the motor decelerates back to zero. I specify values for speed and acceleration and my code works fine taking the motor up to speed, but I cannot achieve deceleration back to zero. I am running on an Uno and to keep things simple will only post a snip of my code that deals with the stepper section.
stepper.setMaxSpeed(steps_per_sec); // SPEED = Steps / second
stepper.setAcceleration(ramp_rate); // ACCELERATION = Steps /second^2
stepper.setMinPulseWidth(15);
stepper.enableOutputs(); // enable pins
stepper.moveTo(10000000); // run indefinitely
while(true)
{
stepper.run(); // step the motor (this will step the motor by 1 step each loop)
if(chk_pin()) { // function that detects button press, very quick circa 1 uSec
break;
}
} // while true
stepper.stop(); // this does not work, nor does anything else I try
// code continues...
The documentation says stepper.stop() "causes the stepper to stop as quickly as possible, using the current speed and acceleration parameters", but the motor stops instantly without deceleration.
I have the Uno in a case with a 16 x 2 display and a button rotary encoder which enables me to set the input parameters, and I use it for testing steppers and drivers, and checking max speeds vs theoretical max speeds. I did see the post by Heredea on June 9th "AccelStepper acceleration and deceleration help" with an answer by DRMPF as Post #2 on June 10th. DRMPF suggested using the modified Speed Stepper library, but I really don't want to install yet another library if there is a simple solution to my problem. Thanks in advance.