LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stepper Motor and LabVIEW - Loop

Solved!
Go to solution

Hi guys, 

I am trying to control a Stepper Motor using a NI 6008. I've done a little research and I know that there are some problems using the 6008 with a stepper motor, but for my project it should work just fine.

 

What I need:

A VI that will control a stepper motor and rotate the motor to the angle typed. The motor has an increment of 7.5 degrees. I construct a VI that will rotate the motor to the desired angle everytime I press the button "GO". But It only works for the first time that I press "GO".

 

The problem:

After the first iteration, if I press "GO" again, it won't apply voltage to the next pin, because it restarts the loop. And that causes the motor to go crazy.

 

The solution: (that I am not sure how to implement)

Make the motor go back to the initial position when I press the button "RESET". In the case, everytime I want to change the angle, I just have to press "RESET" and then "GO", and the motor would go to the desired position. Or even better: when I press the "GO" button the motor would automatically go back to the initial position, and then go to the desired position.

BTW: I would like to go back to the initial position without having to do a 360 loop. I know how to do that.

 

The VI that I created is attached to this message.

Please HELP.

Thanks.

0 Kudos
Message 1 of 11
(3,665 Views)

Gear,

 

Look into changing to a state machine. One of the state variables would be the current position of the motor. Then every time you press Go, you calculate the change required from the current position.  You could have states for initialization and for shutdown (if needed) as well as the Idle, Move to new angle, and Reset states. You might have only one loop when you are done.

 

Shift registers are your friend.  If you are not familiar with them, please work through the on-line tutorials for getting started with LabVIEW.

 

Lynn

0 Kudos
Message 2 of 11
(3,652 Views)

Never mind.  I replied into the wrong message thread.  The slow page loads of the forums these last few days has thrown me off.

0 Kudos
Message 3 of 11
(3,648 Views)

Can you show me how this could be implemented in this case? I am not sure how this would help my problem.

Thank you for your response.

0 Kudos
Message 4 of 11
(3,644 Views)
Solution
Accepted by topic author Gear

Hi, Gear,

 

I tried to drive the step motor by an pre-definded array and rotate it by each step.

Hope it help.

0 Kudos
Message 5 of 11
(3,612 Views)

wow, awesome!!

I didn't know I could do that.

There is one thing that I don't know how to do in this VI: the icon inside the for loop that says "status", with a little house. Can you please explain me what that is and how to create it?

Thank you!!

0 Kudos
Message 6 of 11
(3,582 Views)

Hi, Gear,

 

It's a local variable of LabVIEW.

You can right click your controls or terminals to create such a local variable.

It is very convenient to share the value of one varible, but easily leads to a terrible situation called "race condition".

You may refer to the following article to learn moreSmiley Happy

http://www.ni.com/white-paper/7585/en/

 

0 Kudos
Message 7 of 11
(3,576 Views)

As William1225 pointed out local variables are generally not a good way to pass around data. The one good place to use them is when intializing controls from a config file.

 

Consider the actions your program should take:

GO: Value Change:

   1. Set # Steps = | Angle/7.5|

   2. Set Direction = If (Angle > 0), then 1, else -1

   3. Set Timeout = 500

RESET: Value Change:

   1. Set # Steps = |Position|

   2. Set Direction = If (Position > 0), then -1, else 1

   3. Set Timeout = 500

STOP: Value Change: Exit loop.

Timeout:

   1. Rotate array n = Direction

   2. # Steps = # Steps - 1

   3. Position = Position + Direction

   4. Set Timeout = If (# Steps > 0), then 500, else -1

 

The LabVIEW implementation of this is attached. It contains no local variables, only one loop, and very little duplicated code. This is not quite the typical way a state machine is implemented in LV, but that is essentially what this is. At the end of each iteration of the loop, the action of the next iteration is determined by the values of # Steps, Position, or user input.

 

 

You are probably aware, but I want to point out in case a future reader of this thread is unfamiliar with stpeer motors, that the 0, 1, 2, 3, 0, ... sequence is not the typical coil drive sequence for stepper motors.

 

Lynn

0 Kudos
Message 8 of 11
(3,558 Views)

Hello. I need some help as a beginner. Would u please guide me?

 

Actually my project is about running a system with LabVIEW which is contain a stepper motor with different speeds in clockwise and unit clockwise, a pressure sensor, a switch for calibration the sensor and finally reporting the output as a graph with shows the distance that motor moves a barrier and changes of pressure during the movements of barrier. Right now, I have stuck in ordering the hardware parts for connecting the PC to the system. I don't know exactly what do I need to handle the hole system. Would you please help me? I don't know from were and how should I start?

 

Thank you

0 Kudos
Message 9 of 11
(3,350 Views)

Hi mkia,

 

please create a new thread for your own questions next time!

 

As for your hardware-related questions: Get all specs together and then call your local NI sales representative. (S)He will guide you to select appropriate hardware…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 11
(3,341 Views)