I'm making an overhead stirrer for a hobby laboratory. I have chosen to use a stepper motor for propulsion over a DC one, to avoid sparks from commutators that can be detrimental when working with volatile fluids. Boom, fire, bad.
I'm however new to stepper motor control and have been trying out a lot of different controls and drivers to find the most suitable solution. I ended up with:
- Arduino UNO board
- AccelStepper library
- Classic A4899 driver (tried TMC2209, but it was too slow even though it was BEAUTIFULLY quiet ...).
- NEMA 17 1,5A stepper which I power with a 20 V 1,5A switched power supply decoupled with a suitable capacitor.
It all works great in my first basic trials with potentiometer control, except I can't get the acceleration/deceleration to work. When stirring viscous mixtures one really want the acc&decelleration to be really slow, especially at high speeds.
I use 1/8 hardwired micro stepping to smoothen motion a bit. Along with the capacitor and a careful setting of peak current the motion is now satisfactory free from vibrations. I've tried different speed settings, and with the suitable micro steps a maximum speed of 3000 steps/s produces a sufficient top stirring speed. Any speed above this creates jagged results. I can't however get it to decelerate at any speed.
See my trial code below. I run the stepper at a speed set by a potentiometer, and then simulate a panic stop by a pushbutton through the stop()- function in the library. From the available documentation (available here and here, also see the stop()-function text cited below) it is my understanding that the motor is supposed to decelerate with the previously set acceleration value (in steps/s/s) to a full stop when calling this function. This is not what happens. It comes to an instant halt and then makes slow, jagged steps for a while before stopping completely.
What am I doing wrong? I know I latch the code into a while(1)-loop after calling the function, but this is just for the trial to avoid any new commands after the calling of stop(), and whichever way I do this ends in the above result.
I guess I just don't understand the function properly, but at this point I really need help if someone can spare their time and experience!
#include <AccelStepper.h>
int potVal;
int potPin = A0;
int stopBut = 7;
AccelStepper stepper(AccelStepper::DRIVER,3,4);
void setup()
{ stepper.setMaxSpeed(3000);
stepper.setAcceleration(1000.0);
pinMode(potPin,INPUT);
pinMode(stopBut,INPUT);
}
void loop()
{ potVal = analogRead(potPin);
int spdVal = map(potVal, 0,1023,0,3000);
stepper.setSpeed(spdVal);
stepper.runSpeed();
if(digitalRead(stopBut)){
stepper.stop();
while(1);
}
}
Notes on stop() function from documentation:
> Sets a new target position that causes the stepper to stop as quickly as possible, using the current speed and acceleration parameters.
*> *
> References move().
