From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to do two seperate loops in one VI

Hi all,

 

I need to have two timing functions running in the same VI... But, I havent found a good way to do this....

 

I need one loop to control a cycle that turns a signal on and off, fx. 2min on and 3 off. (must be configurable).

At the same time, I need to sample data at a defined interval, independent of the other loop, every 10sek. (these data are logged in a file).

(All timmer intervals must be configurable).

 

To avoid doing it more complicated that it needs to be, I hope that I can have some inputs of how to do/solve this...

(without doing too many first time mistakes).

 

Thanks,

Martin.

0 Kudos
Message 1 of 3
(3,745 Views)

If the long times (2min, 3min) are always an integer multiple of the short times (10sec), all you needs in one loop running at the fast rate. Use a case structure to occasionally enable the other code. (This assumes that code execution is fast compared to the loop time).

 

Do both loops access the same DAQ hardware? How are things configured?

 

In principle, you can just run two loops in parallel if the tasks are independent.

 

What have you tried so far?

0 Kudos
Message 2 of 3
(3,728 Views)

Hi Martin,

 

You can store the time values in a shift register on your while loop. You could also use the Elapsed Time express VI, but I usually just make one myself. You will have some control like an "Interval" which is your target time. When you start, take the initial time (I usually use the High Resolution Seconds) and set it as the start time in the shift register. Every loop, take the current time, subtract the start time, and see if it is greater than your Interval. If it is, then go ahead and do your action, and set the current time as the new start time.

0 Kudos
Message 3 of 3
(3,723 Views)