LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

running a stepper motor counter clockwise continuously

Solved!
Go to solution

hi I am trying to run a stepper motor clockwise one full rotation in 3 seconds, wait eight seconds and then one and a half rotations counter clockwise for five seconds. i am pretty new to labview and i have been able to make the first rotation using a shift register and a for loop and while loop but can't really figure out how to make it go in reverse.. if anyone could help it would be greatly appreciated.

0 Kudos
Message 1 of 5
(5,562 Views)

There are many types of stepper motors and many ways to send signals to them.  Without more information on your particular motor and driver system we have no idea what to tell you.  When you provide that info please post your current code as well.  

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019 - Unfortunately now moving back to C#, .NET, Python due to forced change to subscription model by NI. 8^{
0 Kudos
Message 2 of 5
(5,540 Views)

I am trying to use an elvis board to run a uni-polar stepper, and I know it's not recommended to use a sequence structure but I am not to familier with case structures So I went with the sequence. My trouble is with the last sequence, I cannot figure out how to make the numbers go in reverse. as you can see I tried using the rotate array function but it doesn't make it rotate backwards. please help!!! thanks.

0 Kudos
Message 3 of 5
(5,525 Views)
Solution
Accepted by topic author sammybammy

so if anybody could help me with this it would just make my day... thanks

0 Kudos
Message 4 of 5
(5,481 Views)
Solution
Accepted by topic author sammybammy

A state machine is often the preferred way to deal with a stepper motor and the reversal of a sequence of steps.

 

I do not have DAQmx so some of the DAQ code is broken. You will need to re-wire the property nodes in the Init state. I tested by using Diagram Disable for all the DAQ code. The logic appears to work.

 

The logic for this program is:

1. Initialize DAQ.
2. Wait for Go.
3. Run 60 cycles unless interrupted by user. 10 ms.
3. Wait 8 seconds
4. Run 80 cycles in reverse unless interrpted by user. 20 ms.
5. De-energize motor.
6. Stop and clear DAQ.

 

The states are Init, Wait, Run, Motor Off, and Halt. A real system might add an Idle state and Error handling state(s). This does not use the DAQ Assistant because it does not lend itself to the appropriate separation of tasks required for a state machine. The code is identical to that internal to the DAQ Assistant with all the extraneous code removed. If ELVIS will not accept the U32 data format, you will need to change that to something suitable.

 

Init: Creates and starts a digital output task.

Wait: Waits for a short time (10-100 ms) and then checks to see if something else should be done. More details below.

Run: Selects original or reversed array of data values for stepper motor. Indexes through the selected array, writing one value to the DO line on each iteration. The Wait value is obtained from a shift register which is loaded in the Wait state. Decrements Count. Checks to see if the specified number of steps have been taken. Selects next state.

Motor Off: Writes a zero value to the DO line, deenergizing all motor windings.

Halt: Stops DAQmx task. Clears DAQmx task. Stops program.

 

Details on Wait state logic: The shift register below the next state shift register contains a "prior" state, although not necessarily the state which executed on the previous iteration of the loop. The prior state is used to distinguish between waiting for Go and waiting between moving the motor forward and reverse. This table shows how I set it up.

 

Wait state

"Prior"     Condition                    Next               Wait interval             Count
  Init          Go=T                          Run                      10                        239
  Init          Go=F                          Wait                       --                          --
  Run        Dir=T & Count>=0      Wait                       --                         C-1
  Run        Dir=T & Count<0        Run                       20                        319
  Run        Dir=F                          Motor Off               --                          --
  Default                                      Wait                       --                          --

 

The counts for the Run states are calculated as 4*60 - 1 for the clockwise rotation and 4*80 - 1 for the counterclockwise rotation. The 60 and 80 values are inferred from the VI you posted. Those values are not consistent with the stated 1 full rotation CW and 1.5 rotations CCW. If your motor takes 60 cycles through the 4-value array for one rotation, the counterclockwise set should use 90, not 80. Similarly the timing will not be accurate. First, software timing is limited by the OS and any kind of timing in the 10s of milliseconds or less will experience considerable jitter. Second, the numbers do not add up. 240 steps in 3 seconds would require 12.5 ms/step and 320 (or 360) steps in 5 seconds would require a wait of 15.625 ms (13.89 ms).  In addition to the jitter issues it is not possible to do fractional millisecond waits in LV.

 

A more robust implementation would include a Producer/Consumer architecture using an event structure for responding to button presses. It might also allow user selection of timing for each segment (forward, wait, reverse) and multiple repetitions.

 

Lynn

0 Kudos
Message 5 of 5
(5,437 Views)