LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

why do i get incorrect direction change of stepper motor using an Arduino?

Solved!
Go to solution

Hi,

I have a stepper motor which I want to drive using an Arduino Mega, i am using labview 2012.

If i input a positive value in the "set input speed" control box then the motor moves forwards at the appropriate rate.

If i input a negative value in the "set input speed" control box then the motor moves backwards at the appropriate rate. However, if I then change the the speed ther motor moves forward at the new speed, not backwards, even though a negative value is entered.

No matter what the previous value, the motor always moves forward using a positive value. However, if i change the speed from say -100 to -101 then the motor will move forward at 101, not backwards as it should.

I know that the value received by the pin of the "stepper write.vi" is getting the correct signal, and have tried to dig into the sub vi's, but i soon get to a point where i don't understand what's going on.

Has any one else encountered this problem, know why this is occuring, or better still solved the issue?

I have attached a copy of the simple vi and images.

0 Kudos
Message 1 of 7
(10,070 Views)

Carlr wrote:

If i input a positive value in the "set input speed" control box then the motor moves forwards at the appropriate rate.

If i input a negative value in the "set input speed" control box then the motor moves backwards at the appropriate rate. However, if I then change the the speed ther motor moves forward at the new speed, not backwards, even though a negative value is entered.

No matter what the previous value, the motor always moves forward using a positive value. However, if i change the speed from say -100 to -101 then the motor will move forward at 101, not backwards as it should.

I don't entirley understand what you are trying to describe here.  Could you better explain each of these steps and the result of each step?  Thanks.

0 Kudos
Message 2 of 7
(7,313 Views)

Nathan,

I am trying to run a stepper motor in forward and reverse. The stepper motor always runs correctly when going forward. To go forward i supply a positive integer as the speed variable, to go backwards i supply a negative integer as the speed variable.

When going aiming to go backwards the motor does not behave correctly. If i set the speed at -100 and then want to change to -150, the motor will change direction and speed, i.e it will initialy be going backwards at -100, then when it gets the value of -150 it will go FORWARDS at 150. If a 3rd value was eneterd, say -130 then the motor would move backwards at -130. In short, when entering new negative values, for reverse, the motor changes direction every time at every input.

If I enter stepper speeds of -150, -100, -130 then the motor should always be reversing, but at 3 differnt speeds, this is not occuring.

0 Kudos
Message 3 of 7
(7,313 Views)

So, you are saying that when you put in successive negative speeds you get alternating backward and forwards motion as a result?  I.e.  it works correctly every other time you input successive negative numbers.

What happens if you alway set positive speeds and instead use negative steps to make the motor move backwards?  This should work the same way that you are expecting the current method to work.

Message 4 of 7
(7,313 Views)

yes you are correct- "So, you are saying that when you put in successive negative speeds you get alternating backward and forwards motion as a result?  I.e.  it works correctly every other time you input successive negative numbers."

If I use positive speeds and use the sign of the number of steps to change direction it works correctly, so I'll use this methodology, however I'm still confused as to why I can't use the speed to control the direction.

0 Kudos
Message 5 of 7
(7,313 Views)
Solution
Accepted by topic author Carlr

I found out why it doesn't work (I think).  It seems that the library used for the stepper motors requires a negative step and negative speed to go backwards.  The LIFA firmware corrects for this when you use negative steps but not when you use negative speed.

To make your inputs work like you would like, you can simply do this:

stepper_fix.png

You should get the following response given the sign of the two inputs:

StepsSpeedDirection
+-Backward
++Forward
-+Backward
--Forward
0 Kudos
Message 6 of 7
(7,313 Views)

Hi there, 

 

I can't control the direction for the second stepper even when i tried your tricks. 

Do you have suggestion ? 

thanks. 

0 Kudos
Message 7 of 7
(5,441 Views)