LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

problems with timing in a while loop in an event structure

Solved!
Go to solution

Hi,

 

I am using labview to control three stepper motors, that run three different translation stages in different axis (X, Y, and Z). Please see the attached VI, focusing on the event structure on the RHS.

In the Z axis, i am trying to run the stepper motor for 5 seconds, after clicking a button. This i have attampted to do by adding an elapsed time sub VI within a while loop, that is within the "Z forward mouse down" tab of the event structure. A similar 'elapsed time while loop' is also included in the "Z reversed mouse down" tab of the event structure.

Seperately these 'elapsed time loops' work fine, BUT when i run one Z direction after the other, say 'Z Reverse' then 'Z forward' then they annoyingly interact. The timing goes off, with the timing adding up, rather than resetting.

Any idea how i can reset these elapsed time while loops? Or is there another better method to do this?

 

Thanks very much,

Charlie

0 Kudos
Message 1 of 8
(3,407 Views)

You probably want to reset the elapsed time whenever i=0. Since you auto-reset, the timer starts again after it has elapsed, and will be elapsed right away if you enter ther same case  much later.

 

I would recommend to do some tutorials on common desing patterns. Your code has many very questionable features. Why are some of your events filtering? Instead of mouse up and mouse down events on booleans, I would change the mechanical action to switch until released, use value changed events, and combine the events. I would not use lenghty inner while loops inside events. There is way too much duplicate code.

 

 

0 Kudos
Message 2 of 8
(3,388 Views)

Sounds great - how do i do that??

Do i take a wire from the 'i' of the while loop to the autoreset input of the elasped tiem subVI?

 

Sorry I'm not that great at labview...

 

Thanks,

Charlie

0 Kudos
Message 3 of 8
(3,384 Views)
Solution
Accepted by charlieryan

charlieryan wrote:

Do i take a wire from the 'i' of the while loop to the autoreset input of the elasped tiem subVI?


No, you wire to the "reset", not "autoreset".

 

 

0 Kudos
Message 4 of 8
(3,378 Views)

Why do you need the timed loop?  I am not familiar with stepper motors but it appears that when you mouse down on the button, the stepper motors starts to move.  And when you mouse up, the motor should stop. What's the point of the loop?

aputman
0 Kudos
Message 5 of 8
(3,371 Views)

If you want to see how long the mouse was down, put a tick count in the mouse down, pass it to a shift register, and subtract it from another tick count in the mouse up event.  Or you can use the Time value on the event data node (left side of the event structure) rather than a tick count.

aputman
0 Kudos
Message 6 of 8
(3,362 Views)

Hi Aputman,

 

The loop should allow for the motor to run for a certain period of time, which with a bit of calibration of the stepper motor (a time versus distance factor), gives a distance that is moved. So rather than guessing how far the motor has moved by holding down the button manually, you can set it in the program.

I'm not sure though this is the best way to do it, so if you have a better idea I open to ideas!

 

Charlie

0 Kudos
Message 7 of 8
(3,358 Views)

Hi,

 

Thanks Altenbach that has worked perfectly.

 

Cheers,

Charlie

0 Kudos
Message 8 of 8
(3,315 Views)