LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

timing of loop

i am using the structure of the function(looping)
and i want to ask how to control the timing of the loop?
if i have 2 functions needed to be execute, let say function A and B
for example, at t=2 execute function A
and at t=5 execute function B
and at t=11 execute function A again.


i would like to ask, whether i can run the VI in this way and, what
looping i should use?? and how can i control the timing of the
functions?

It would be great if there are any solutions on that, thanks a lot!
0 Kudos
Message 1 of 5
(3,323 Views)
I made an example vi to try and help. It's pretty simple, what you do is you put a "wait until ms multiple" function inside it, and that makes it so that the entire time for each time the loop runs is however many milleseconds you input. So basically the time it takes to run your code + the time it waits = the time input on the wait until ms multiple function. What I did was make it so that the time input was 1000, or 1 sec, this way you can use the loop index to tell you how many seconds the loop has been running. You then divide the loop counter by 2, 5, and 11, and you run the code if the remainder equals zero (in this case adding one to the counter). otherwise, you shouldn't do anything. You have to be careful though because if your code in
side the loop takes longer than one second to execute then it will end up that the loop waits for 2 seconds because 2000 is the next "ms multiple" that would satisfy the condition. Hope this helps.
Message 2 of 5
(3,323 Views)
You could write the loop such that the loop time is equal to t. Next, take the loop counter and do modulo divisions by 2, 5 and 11. When the remainder if a given division operation is 0, have the output select a case that does what needs to be done for that time interval.

Of course, this assumes that "t" is longer than the execution times of all the intermediary processes put together.

Also, be sure to use the "metronome" timer function if you want a particular time period, regardless of what gets executed in the loop.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 3 of 5
(3,323 Views)
Thanks for yr solutions~
I get what you mean in the calculation of timing, but as i am the
beginner of LabVIEW, I just know a little bit about the functions and
tools.
How can i get the timing of the loop?
can i just use 'Tick Count'and use it as the input of the calculations
of the timing you teach me ? As i am using version 5.0, I cant find
the "metronome" timer function you mentioned before.

😆 thanks again!
0 Kudos
Message 4 of 5
(3,323 Views)
Sorry for the confusion, the "metronome" timing function is the one that has an icon that is a picture of a metronome. I have attached an example that shows the whole thing in operation.

A couple notes: All this example does is build a string based on the value of the count. However, the stuff that you will really be wanting to do probibly will have the ability to generate errors. Therefore, have used an error cluster to establish a data dependency between everything else. The single frame sequence at the end is to make sure that the timer doesn't run until all the timed events finish.

Finally, yes you could alternately use the output of the tick count function as the input to the dividers, but you would have to remember when setti
ng the divisors that the tick count outputs counts in milliseconds--not seconds. Also, everytime the counter rollsover to 0 all three events will fire.

With the code I am sending you, the first time through the loop all the events will execute, also the first loop time will be less than a second because the code is essentially synchronizing itself to the computer's clock.

Finally, if you need help with anything else just call. In addition, if you need someone to take on a complete development project that you don't have time to do, let me know as I do a lot of contract work remotely over the internet.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 5 of 5
(3,323 Views)