Go Down

Topic: pulse/direction stepper (Read 2 times) previous topic - next topic

Robbieuitos

Dear all,
I'm trying to figure out the following. I'm driving 2 steppermotors each one has a driver. The driver is pretty nice! I can control it with a pulse and a direction. That's it, so the normal arduino stepper library is useless for me at the moment.

I'm not what you call, a programming hero, but I've got it to work. What I do is to create a pulse with changing the state of a pin with the digitalWrite command with a few microseconds of delay in between.

But to the arduino there are a few more thing connected. 2 steppers, 4 servo's, a compass, a external clock and some switches.

I'm not having problems at the moment, but I'm already expecting some because I create a pulse fromout the mainloop. Also because I read somewhere that changing the state with digitalWrite can not be faster than 5ms. Which is a bit slow if i want to use the drivers microsteps.

My question is; is there a library or a piece of code which will work from outside the mainloop? I think it's called 'interupt-driven', but I'm not familiar with it.

Thanks in advance,
Rob.

PS the drivers are really nice, you can take a look here, mine is the M415C http://stappenmotor.nl/Steppermotor/Microstepdrivers/Stepmotordrivers%20global.htm


My best Arduino project: Bench. Interactive transformable furniture.

AWOL

Quote
Also because I read somewhere that changing the state with digitalWrite can not be faster than 5ms

Reference?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Robbieuitos

Hi AWOL,

In this topic, http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1232754040. The fourth post from the top, mem mentions this.

Rob.
My best Arduino project: Bench. Interactive transformable furniture.

AWOL

No, he mentions it takes 5 microseconds, 1000 times faster than 5ms.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Robbieuitos

#4
Feb 13, 2011, 10:06 pm Last Edit: Feb 13, 2011, 10:09 pm by Robbieuitos Reason: 1
Hi AWOL,

sorry, that would be a typo from my side. I'm very sorry.
But is there a way to create these pulses. Can TimerOne or Timer3 be use for this? And if yes, in what way(or can you give me a hint?
Thanks in advance,
Rob.
My best Arduino project: Bench. Interactive transformable furniture.

Robbieuitos

Dear all,

There must be a way to create a steady pulse with an arduino library. Sure there is someone who knows about this library that I don't know! I'd be pretty thankfull for any tips!

Rob.
My best Arduino project: Bench. Interactive transformable furniture.

djc


There must be a way to create a steady pulse with an arduino library.


http://www.open.com.au/mikem/arduino/AccelStepper/

Robbieuitos

Hi djc,

There's a difference between two wire stepper and the way I have to control my stepper. The library looks pretty awesome, i saw it before, that will be for a future project.

But I did find something else, easydrive has a driver that works in exactly the same way. And someone wrote the code ;-) I was on the right track, but had some delayMicroseconds() that weren't needed.

Thanks all!

http://translate.google.pt/translate?js=y&prev=_t&hl=pt-PT&ie=UTF-8&u=http://www.lusorobotica.com/index.php/topic,106.0.html&sl=pt&tl=en&history_state0=&swap=1
My best Arduino project: Bench. Interactive transformable furniture.

robtillaart

@RobbieuitOS,
Please share your working code (when ready) as other people may find it useful,
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Robbieuitos

#9
Feb 17, 2011, 11:59 am Last Edit: Feb 17, 2011, 12:46 pm by Robbieuitos Reason: 1
Hi all,

Here the code! Thanks robtillaart for mentioning! It feels good to give something back to the community!

I hope someone can use it!

Rob.


Code: [Select]
/*
* Steppercontroller program for running a stepperdriver that only needs two lines
* A pulse line and a direction line. For example like the 'easydriver' stepper motor controllers
* This example is for using 2 stepper motor controllers.
* By Rob Hebing (robhebing.nl) on 17/02/2011
* Of course this is free for use, but if you do, a nice update about your project would be much appreciated!
*
*/

//the number of steppermotors connected to arduino
#define nrOfSteppers 2
//the pins of the steppers that control the direction
const int stepperDirectionPin[nrOfSteppers] = {8,4};
//the pins of the steppers that control the pulse
const int stepperPulsePin[nrOfSteppers] = {10,2};

void setup() {               

  //set the output pins right and set them LOW
  for(int s=0; s<nrOfSteppers; s++){
    pinMode(stepperDirectionPin[s], OUTPUT); 
    digitalWrite(stepperDirectionPin[s], LOW);
    pinMode(stepperPulsePin[s], OUTPUT);
    digitalWrite(stepperPulsePin[s], LOW);
  }

Serial.begin(9600); 
}

void loop(){
 
// just moving 2 stepper motors back and forth
//stepper(number of the motor to control, amount of steps, the direction(0 or 1));
stepper(0,3200,1);
  stepper(0,3200,1);
stepper(0,3200,0);

stepper(1,3200,1);
stepper(1,1600,1);
stepper(1,1600,0);
Serial.println("---");

}

void stepper(int motor, int steps, boolean stepDirection){
  //first check the direction, if it's not the current direction change it.
    int currentDirection = digitalRead(stepperDirectionPin[motor]);
    if(stepDirection != currentDirection){
     digitalWrite(stepperDirectionPin[motor], stepDirection);
     //this delay makes the motor stop for a while when changing direction.
      delay(100);
    }
  //a for loop to create the pulse
  for(int s=0; s<steps; s++){
    //the LOW, then HIGH creates the pulse the driver is waiting for, no delay needed.
    digitalWrite(stepperPulsePin[motor],LOW); 
    digitalWrite(stepperPulsePin[motor], HIGH);
    //this delay creates the pulse, the lower the number the faster the pulse.
    //play around with it to get your desired speed
    delayMicroseconds(500);
  }
}

My best Arduino project: Bench. Interactive transformable furniture.

djc


I hope someone can use it!


Please don't be offended by the following remarks as they are meant for your education, not as a personal attack.

The code you have is OK as long as you want to put a motor on your desk and watch it go back and forth all day long. It will be less useful if you actually connect the stepper to something and expect it to do useful work.

There is no means of varying the pulse speed or its rate of change. Just as you can't start your car in top gear from a standstill nor do 0-60 in half a second flat, you can't do this with a stepper. It will stall and lose steps - and the whole ethos of a stepper motor is that the steps enable you to monitor its position.

If you have any kind of load attached to your motor, you need to increase its speed gradually to overcome the inertia of the load.

Similarly, just as you cannot stop your car instantly at the end of your journey (even by crashing into a wall), you need to decelerate the stepper as you approach the commanded position. If you just switch off the pulses, the load will cause the motor to overrun, again losing position.

The hard work has been done for you in the library referred to above.


Robbieuitos

Hi djc,

I'm not offended at all, I'm glad your pointing this out to me and I'm glad I'm learning!
I see what you mean, and would have found it out when I would have been nearly finished. So thank you very much!

I see what you mean. Clear example. And your right, I assumed the power of the stepper would solve the -mass in motion- problem, but making the motors accelerate would be much better.

What I was wondering, can I use this library with my kind of driver. They mention the sparkfun easydriver which also has a pulse and a direction line. (while writing this post reading a lot....) Yes it is possible! I'm working on the project next week. But djc, thank you so much. If you like, I'll keep you posted!

Thank you,
Rob.
My best Arduino project: Bench. Interactive transformable furniture.

Robbieuitos

Hey,

I'm on the project again, and still figuring some things about controlling the steppers. Basically I have one question. How do i make my stepper go faster.
I have driver which is pulse/direction controlled. In the code I posted earlier the stepper is fast and strong, with accelStepper it's really slow because I use *16 microstep.

Anyone, has an idea how to really increase accelStepper maxSpeed?

Rob
My best Arduino project: Bench. Interactive transformable furniture.

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview