Pages: [1]   Go Down
Author Topic: Non blocking steppor motor control  (Read 1898 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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"?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50115
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: March 21, 2012, 08:50:00 pm by C11MAN » Logged

United States
Offline Offline
Newbie
*
Karma: 2
Posts: 49
Yes. Thats my donkey
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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! smiley
« Last Edit: March 23, 2012, 05:17:31 am by dewy721 » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

United States
Offline Offline
Newbie
*
Karma: 2
Posts: 49
Yes. Thats my donkey
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

A long time ago I saw some controllers that were similar in an old' school DIP-package auto-insertion machine that I had to nurse along from time to time. But I was just the night-shift operator of the machine and would read the tech manuals for it between cycles. I got to know that machine better than the maintenance crew did. In fact they unofficially called on me for light-duty repairs. (It was always wearing out a few segments of ribbon cable by flexing them to death.)

It sounds like you have the basis for a really killer toy CNC project.

I posted some files that allow people with an Arduino and a free copy of LinuxCNC to make there very own CNC machines. If your interested it can be found at http://emc2arduino.wordpress.com/
« Last Edit: April 10, 2012, 08:08:48 pm by dewy721 » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

that cnc stuff looks pretty cool, I may have to try my hand at it sometime.  I finnaly looked at what arm I have and its the atlas II so its just a bit old   smiley-mr-green

currently its my schools but its completely useless to them so I may get to bring it home at the end of the year.   

for control im using a ps/2 keyboard on the arduino but I am hoping to move to something more advanced, im thinking xbox controller...
Logged

United States
Offline Offline
Newbie
*
Karma: 2
Posts: 49
Yes. Thats my donkey
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Does it look like this one?
http://www.anf.nildram.co.uk/beebcontrol/arms/atlas/index.html

Looks like the gripper hold a cardboard sign pretty well. You could get some chuckles making it 'flag' messages with it. (Like "Wiley Coyote" from the road runner cartoons.)
Logged

Pages: [1]   Go Up
Jump to: