Go Down

Topic: Stepper Motor Dir/Step help program. (Read 2403 times)previous topic - next topic

ash901226

Dec 08, 2012, 05:08 pmLast Edit: Dec 08, 2012, 05:10 pm by ash901226 Reason: 1
Hello all, Thank you for taking your time to read my post
first let me explain my setup.
I have an Arduino Uno the first model. anyway i want to move 2 bipolar stepper motor. For each motor i have a L297 and L298 ic that i connect according to the datasheet.
for now i have wire every other pin except for the Step(or according to the datasheet Clock) and the direction pin to ground or 5V. so i guess you could disregard all the other pin.
I would be driving the motor all in half step mode so theres 8 step to complete a rotation.
I connect my pin 2 and pin 4 as the direction pin and pin 3 and 5 as my step.
Anyway my big question is how can i program the arduino so that i can control both the motor relatively Simultaneously and how can i keep up with the pulse count.

I need to be able to control the stepper motor independently, meaning the direction speed and the number of step all need to be able to control independently.

i had try the stepper library and AccelStepper but what i really want is to learn how to control the step and actually keep count of each stepper and it must be non blocking. Any hint and help is much appreciated, if there is a link to where this actually have been done would be great too

Thank you again for taking the time to read my post and wish you all the best

PaulS

#1
Dec 08, 2012, 05:47 pm
Quote
Anyway my big question is how can i program the arduino so that i can control both the motor relatively

You need to step each motor one step at a time. You need to figure put which one needs to step the most times to get the pair where you want. Say that one needs to step 10 times while the other needs to step 8. In a loop, you step one motor 1.0 step and the other motor 0.8 steps. Notice that the values are NOT ints. You keep track of the position that the (slower) motor should be at (0, 0.8, 1.6, 2.4, etc.). Each time the position becomes greater than 1, step and decrement the value by 1.

So, the positions become 0.0, 0.8, 1.6 -> 0.6, 1.4 -> 0.4, 1.2 -> 0.2, 1.0 -> 0.0, 0.8, 1.6 -> 0.6, etc.

Each place where the -> is shown, you step and decrement. Meanwhile, the other motor steps every time.

The result will be a stair step arrangement, rather than a slope. How that impacts your process depends on how many steps are needed to move your whatever, and how precise that movement needs to be. For metal cutting CNC machines, they are usually geared, so moving the head 1.0" in one direction requires hundreds of steps. The difference between 1048 steps and 1048.5 is not going to make much difference.

ash901226

#2
Dec 09, 2012, 02:18 am
Thank you PaulS for your insight.
but how do i exactly pulse the Step with a know pulse count and still be non blocking. I do understand the concept well that i need to step one stepper then the other fast enough that it can be seen as in sync. But the question is how can i create a program where by i want the arduino to step one motor have a for instant of 800 step at maybe 30rpm while the other have maybe 500 step at maybe 10rpm? for the direction it seem that part is quite straight forward.

PaulS

#3
Dec 09, 2012, 02:27 am
Quote
how can i create a program where by i want the arduino to step one motor have a for instant of 800 step at maybe 30rpm while the other have maybe 500 step at maybe 10rpm?

What, exactly are these steppers going? If they are running at different speeds and different numbers of steps, I can't any reason to worry about keeping them in sync.

ash901226

#4
Dec 09, 2012, 04:33 am
you got me there haha.
Yeah i mean moving simultaneously not in sync. haha what am i thinking when i said that.
Anyway i really cant think of a way to program the arduino for the 2 stepper to be moving at different step at different speed.
i kept going to for loop which in turn make it rotate both motor at the same time but the number of step for each is the same. now I am stuck.

PaulS

#5
Dec 09, 2012, 12:59 pm
Quote
Anyway i really cant think of a way to program the arduino for the 2 stepper to be moving at different step at different speed.

I don't understand why speed is an issue. It seems to me that if the two steppers are trying to move something along orthogonal axes, like a plotter, then the idea would be to make it move at some speed along the desired vector. Then, the actual speed of each motor would be based on the number of steps each needs to take to get the something to go from point A to point B.

The time is given, the number of steps is known, so the only questions are when to step the motor the motor that needs to step the most times, and when to step the other motor.

The first question is easy to answer. Divide the time by the number of steps. That is the interval between steps for that motor. The other question is only slightly harder, but that is the answer I provided earlier. The 2nd motor does not step every time the first motor steps, but the position it should be at does increase every time. The 2nd motor steps only when the position it should be at (the number of steps it should have taken) is greater than or equal to 1.0.

So, pay attention this time. What are the steppers doing?

ash901226

#6
Dec 09, 2012, 01:50 pm
ok PaulS,
Urm the reason i think that the speed is a factor is that i am trying to find a way to impliment the S curve Acceleration/Deceleration profile. Well your example is spot on, I want to make a plotter.

wildbill

#7
Dec 09, 2012, 01:57 pm
Take a look at the code for the reprap project. There are routines in there that do exactly what you need - you just need to extract them from the G-code parsing.

Go Up

Please enter a valid email to subscribe