LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

timed loop vs wait until vi

Hi there,
   My vi need a critial timed loop at 1ms cycle. I tried two way, one is with timed loop structure vi and the other is to put a "wait until" vi in a while loop structure. In the case of wait until vi, I used a flat sequence vi inside the while loop and put the wait until vi inside its first box and all other vi in another box to make sure the wait vi doesn't execute in the middle of other code inside while loop. All the codes inside the both cases are same and should be finish in less than 1ms, as I monitored "finished late" in the timed loop case.
   And I recorded time tick when every loop executes. What I found is the period of timed loop seems more accurate than that of while loop embedded with wait until vi.
   Why is it?
   I am using Labview 7.1
 
thanks for any reply
 
feilong
 
 
 
0 Kudos
Message 1 of 4
(5,043 Views)
A timed loop is always more accurate. That's what is was specifically designed for.
 
Your idea about the case structure is flawed, you need to ensure that the wait executes in parallel to the rest of the code, otherwise your loop time will be the sum of the wait time + the time it takes to execute the second sequence frame. Remove the sequence structure and see of the loop rate improves.
 
A wait in parallel will NOT slow down the rest of the code!! All nodes without data dependency will execute at the same time and the current frame wil finish once all nodes in it have finished. If you can ensure that all the other stuff takes less than 1 ms, the wait will be the last to finish and exclusively determine the loop rate. 🙂
 
Of course you should know that on a multipurpose OS, a 1ms loop rate cannot be guaranteed. You would need to go to a RT system for deterministic behavior.

Message Edited by altenbach on 08-28-2007 09:47 AM

0 Kudos
Message 2 of 4
(5,034 Views)
Thanks altenbach for your reply
But I don't understand about your words about where to put the wait until. because I want my code inside the loop to be execute at exacly every 1ms. so I put the wait in the first box of flat sequence structure to make sure everything else in next box will start to run at beginning of next 1ms.
 
If I put them in parallel without using sequence structure, the wait vi will have a chance to run in middle of some VIs when they don't have wire connection.
please correct me if I am wrong
 
feilong
 
 
0 Kudos
Message 3 of 4
(5,014 Views)


@feilong wrote:
because I want my code inside the loop to be execute at exacly every 1ms. so I put the wait in the first box of flat sequence structure to make sure everything else in next box will start to run at beginning of next 1ms.

You are thinking about this the wrong way.
 
If you place a wait inside the loop (no sequnce structures!), everything will start executing at the same time. The current loop iteration can only finish once ALL nodes in it have finished. Most likely, the wait will take the longest. As soon as the wait finishes (1ms after the loop started), the loop will go to the next iteration and all nodes will start executing again, exactly 1ms after the last time they executed. Repeat as long as you want.
 
Functionally, there are two main differences if you add the sequence structure with the wait in the first frame:
  1. the loop time will take slightly longer than 1ms because the time of the other code is added to the 1ms wait.
  2. When you start the program, your code first wait 1ms before starting the repetitions at slightly more than 1ms increments. My solution will execute the other code immediately, then exactly every 1ms.

 

0 Kudos
Message 4 of 4
(5,006 Views)