Go Down

Topic: Non blocking steppor motor control (Read 1 time) previous topic - next topic

C11MAN

for my project, im attempting to run six independent stepper motors off my arduino mega 2560.  the stepper controlers that i have dont seem to be a "standard" type as i was unable to get the stepper library to work on a single channel.  it seems to work by having two control pins, one for forward, and one for reverse and moving a step for every pulse sent to them.  would it be possible to use something similar to the servo library to send out the neccesary pulses and keep the rest of the code "unblocked"?

PaulS

Quote
the stepper controlers that i have

are?

Quote
it seems to work by having two control pins

Is it the stepper motor, your controller, or the library?

Quote
would it be possible to use something similar to the servo library to send out the neccesary pulses and keep the rest of the code "unblocked"?

No, because the pulses sent to a servo and the pulses sent a stepper controller are for entirely different purposes.

You can minimize the time that the library blocks by not trying to step more than one step at a time. Of course, this means that YOU have to determine when to send the next step instruction for each of the 6 motors.

C11MAN

#2
Mar 22, 2012, 02:46 am Last Edit: Mar 22, 2012, 02:50 am by C11MAN Reason: 1
sorry i forgot to mention about my stepper controlers but they are out of a robotic arm that was trashed.  there is not model on them nor could i find documentation on them,

i know this pic wont help with any specifics but just so you know what im working with
http://i696.photobucket.com/albums/vv321/c11man/WP_000022.jpg
and it is the motor controler that works with two pins

and as for the part about the library.  what i meant to say is that would it be possible to have a program that runs in the background and sends out the neccesary pulses and you just update the speeds.  in the same way that the servo library works expect for have to send out what the stepper controller needs instead of the servo stuff

dewy721

#3
Mar 23, 2012, 09:28 am Last Edit: Mar 23, 2012, 11:17 am by dewy721 Reason: 1
I haven't seen one of those in a LONG-LONG time! It technically does have a DIR pin (tied to one of the step pins with a pull-up resistor). Its a Uni-Polar driver ** IF ** I recall correctly.

Sure, you can work with that.

Here's a (modified) non-blocking function I use to drive the steppers for my CNC project.
You can call it as often as you like, from your loop() routine. It does not block, and it uses the digitalFastWrite library for an 8x speed boost.

Code: [Select]

#include <digitalWriteFast.h> // http://code.google.com/p/digitalwritefast/

#define stepPin1a 2
#define stepPin1b 3
#define stepPin2a 4
#define stepPin2b 5 // Add more as needed.

int minStepTime=25; //delay in microSeconds between step pulses. lower=faster.

boolean stepState=LOW;
unsigned long stepTimeOld=0;
long stepper1Pos=0;
long stepper2Pos=0;
long stepper1Goto=0;
long stepper2Goto=0;

void stepLight()
{
 unsigned long curTime=micros();
 if(curTime - stepTimeOld >= (minStepTime/2))
 {
   stepState=!stepState;
   
   // Add more as needed here as well. (Must match #define section.)
   if(stepper1Pos > stepper1Goto) digitalWriteFast2(stepPin1a,stepState);stepper1Pos--;
   if(stepper1Pos < stepper1Goto) digitalWriteFast2(stepPin1b,stepState);stepper1Pos++;
   if(stepper2Pos > stepper2Goto) digitalWriteFast2(stepPin2a,stepState);stepper2Pos--;
   if(stepper2Pos < stepper2Goto) digitalWriteFast2(stepPin2b,stepState);stepper2Pos++;

   stepTimeOld=curTime;
 }
}

// call from loop routine like this:

void loop()
{
 stepper1Goto=12345; // update as often as you like.
 stepper2Goto=67890;
 stepLight();
}


That should do what you want, add 8 more entries top and bottom and you'll have all 6 steppers looking for thier long lost arm in no time at all. If this rusty old mechanic's memory serves me right. That should handle about 24v@5 amps per coil (WITH FAN) [120 watts total]. Nice score on the salvage btw! :)

C11MAN

Thanks for all the info and sorry for the long delay.  I was able to drive the steppers perfectly without issue with that setup.  instead of having it based on position I went just with a simple on/off and a controller because the arm realy has no real use, more just a play thing.  currently I control 4 out of the six motors but I think the issue is with the controllers themselves.

you seem pretty familiar with these, did you used to work with them?  and if so, are they very difficult to fix/replace?  also is h

Go Up