LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Measuring the execution time of a while loop iteration

I am trying to send a comand for motion control, i need to adjust the distance of this move command based on a user controlled speed and the # of ms it takes to get through one iteration so that i can have smooth, but not lagging movements.  Anyone know how to get an constantly updated value for loop execution?
0 Kudos
Message 1 of 5
(6,655 Views)
Russell,

Software timed loops are never going to be perfectly smooth if you are using a desktop operating system. If your update rates are fairly slow (several 10s to 100s of ms) or you can tolerate occasional glitches, you may be able to get by with specifying the delay in the loop. Put a Wait (ms) function in you loop and connect the desired delay to its input.

Also, it is never a good idea to rely on software alone to stop motion for emergency or safety purposes. Put a suitable Emergency Stop switch in the hardware circuit.

Lynn
0 Kudos
Message 2 of 5
(6,645 Views)
THanks Lyn,
I know about the nonperfect control in an os, right now i do put a wait comand of about 10 ms at the end of the sequence with in this loop, and i have a control on the front pannel to 'tune' the time between iterrations for the distance comand. The tunning is still glitchy, and so i thought if i could find out how long the loop took to execute last iteration, and use that for to tune my current distance command things might be a little smoother. so if im under heavy processing load, and the iterations are taking much longer, and i to not start-stop-start-stop in my motion, im increasing the distance for the motion so that it extends long enough untill the next iteration, but not so long that after i quit sending move inputs, the motion is continuing on.

So the question remains... Is there any way to get a value for the time it took the last iteration of my while loop to execute?
0 Kudos
Message 3 of 5
(6,639 Views)

Yes, use a shift register and store the value from the Tick Count function in it...in every iteration of the loop, get the current tick count, and subtract the current tick count from the value in the shift register, which is the tick count from the last iteration.  This will give you the execution time of the loop in milliseconds.  Note that the resolution of the Tick Count function is 1 millisecond.

-D

Message 4 of 5
(6,635 Views)
working smoothly now, thanks alot!
0 Kudos
Message 5 of 5
(6,625 Views)