LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Running simultaneous while loops. Dual core needed?

I have two while loops running simultaneously, one running an "elapsed time" express VI and one sampling resisances. Do I need a dual core processor to run them? It works in highlight mode, but in realtime, one loop waits for the other to finish.

0 Kudos
Message 1 of 6
(3,104 Views)

You don't need a dual core processor to run two while loops.

 

It would help if you posted your VI so we could look at what might be forcing one to wait on the other.

 

Do both of your loops have delays?  Greedy loops are bad.  Is any data shared between the loops?

Message 2 of 6
(3,098 Views)

Values are sent to both loops initially but they should run independently after that. The loops are in the 8th sequence of the big sequence structure.  The bottom loop should finish first and essentially wait for the top loop to finish getting to a specified number of seconds, then the next sequence start.  Its basically a messy way of triggering and timing without a trigger available.  I commented in the program where Im having issues.

 

1)  "power -" until bottom loop is true, wait for top loop to finish.  

 

2)  Next sequence in loop.

 

3)  "power +" until bottom loop is true, wait for top loop to finish.

 

Repeat 1-3 until N of the 'for loop' reaches the final number.

 

There is a subVI in there that just has formulas so I didnt include it

0 Kudos
Message 3 of 6
(3,085 Views)

You really need to look at getting rid of that sequence structure.  What you want is a state machine.  It'll make expanding the capability of your program much easier.  As a nice plus everything will fit on one screen and make a lot more sense.  I think there's an example of a state machine in the example finder.  I'd do that before I did anything else.

 

I don't see anything that would force the second loop to always execute second.  However, it might run several times before the condition to stop is true (Current Retraction >= R_Cutoff).  One way to check that would be to wire the "i" terminal to the end of the loop and probe it.

 

The express VIs execute more slowly than configuring the DAQ yourself.  Each loop iteration it has to create, configure, start, read, and stop the task.  Once you move to a state machine architecture it should be much easier for you to move away from the Express VIs.  At that point you'll only have to read data each loop - no more create, configure, start, and stop.

 

Also - why do you want to wait a certain amount of time before moving on to the next measurement?  As soon as the bottom loop finishes executing you're not really doing anything but waiting.  The top loop isn't functioning as a timeout that forces execution to continue if the bottom loop never finishes.

 

If you really want to write pretty code you should look at a producer / consumer architecture as well.  With that setup you use two while loops and communicate between the two.  The producer does your data acquisition and your consumer processes and displays the data.  Learning to write a state machine and use producer / consumer will let you do almost anything you need in LabVIEW.

Message 4 of 6
(3,077 Views)

Ive never heard of a state machine, but I will certainly look into it.  In essence, Im making a cyclic step function.  Im missing digital outputs right now in the bottom loop but it will power the actuator with a potentiometer feedback until that resistance is reached, then power will be cut off until the top loop finishes.  For instance, if its a 1Hz cycle Im looking for, the first top loop will run for 0.5 seconds, bottom for ~0.2 (power on) and then wait the remaining 0.3 (power off).  Then the next sequence runs, top loop for 0.5 seconds, bottom for ~0.2 (power reversed) and wait 0.3 (power off).  I tried getting into timed loops and timed sequences, and that didnt work out very well.

0 Kudos
Message 5 of 6
(3,069 Views)

Here's a link that'll get you started http://zone.ni.com/devzone/cda/tut/p/id/3024

Rodéric L
Certified LabVIEW Architect
Message 6 of 6
(3,061 Views)