LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

best way to run two processes (loops or VIs)

Hello,

 

I was wondering, what's the best way to run two things at the same time? One is data aquisition and the second is a voltage output (for a motor control), both of these have to happen at the same time, but it's critical that the motor control happens at 20ms steps (outputs a pulse every 20ms).

 

should I create 2 VIs, and run them at the same time? or would two parallel loops be better (I haven't had much luck with parallel loops, it makes one loops slow down for me)... or is this where timed loops come in? maybe 2 timed loops, one with high prioority with respect to eachother (I've tried some stuff with timed loops, and didn't have much luck but I'm not sure if your messing with paralleled timed loops, do all of the loops have to be timed loops in order for priorities to work right?)

 

much thanks!

0 Kudos
Message 1 of 21
(6,386 Views)

It seems like two While loops within the same VI should work well for your application. If the loops aren't synchronized, their timing should be independent of one another. Depending on how your analog output and input is configured, your loop speed will be dictated by the task unless you slow it down with a Wait function. It sounds like you aren't using an RT system, but I'm not sure from your description. If it is important that the loops stay synced with the clock, you can use Wait Until Next ms Multiple instead of just Wait. You wouldn't have to use timed loops to do this.

 

Can you describe your hardware setup? Do you have something else going on within the loops that is very processor intensive?

 

Eric

0 Kudos
Message 2 of 21
(6,376 Views)

 


Fibo wrote: 

should I create 2 VIs, and run them at the same time? or would two parallel loops be better (I haven't had much luck with parallel loops, it makes one loops slow down for me)... or is this where timed loops come in? maybe 2 timed loops, one with high prioority with respect to eachother (I've tried some stuff with timed loops, and didn't have much luck but I'm not sure if your messing with paralleled timed loops, do all of the loops have to be timed loops in order for priorities to work right?)


 

You shouldn't see much difference between putting two loops in the same VI, and putting those two loops into separate VIs that are both called from the same main VI.  For that matter you can put one loop in the top-level VI and the other inside a subVI.  The major advantage to putting the loops in subVIs is that you can assign them different execution subsystems and different priorities.

 

I don't understand what you mean by "not much luck with parallel loops."  To me this suggests problems with your programming style - are you sharing data, resources, or subVIs between the two loops?  Do both loops contain some sort of wait function?  Are you using property nodes, which must execute in the user interface thread, inside those loops?

 

My understand is that timed loops are assigned their own threads, which should improve timing stability but may not be necessary for you.  How critical is the 20ms timing (what amount of jitter can you accept)?  Even with a timed loop, if you're running on a non-RT operating system (such as Windows), you may occasionally see jitter if the operating system is busy doing something else.

Message 3 of 21
(6,372 Views)

Do you have an example of your code so that we can help with suggestions for your program?

Tim
GHSP
0 Kudos
Message 4 of 21
(6,366 Views)

hello....... i have a similar query..... though i have seached and read a lot.. i still cant get it working..

I have made 3 subvis to find each of the x,y and z coordinates of the stepper motor in the test bench.

I am using the click of a button as the event to get the x,y,z coodinates.

For this I am calling the 3 subvis simultaneously in the single event in the main vi. But I am not able to make the 3 different subvis in parallel. When one is running, the others dont. 

Can anyone please help.... thanx....

0 Kudos
Message 5 of 21
(6,318 Views)

 


@Preetisar wrote:

hello....... i have a similar query..... though i have seached and read a lot.. i still cant get it working..

I have made 3 subvis to find each of the x,y and z coordinates of the stepper motor in the test bench.

I am using the click of a button as the event to get the x,y,z coodinates.

For this I am calling the 3 subvis simultaneously in the single event in the main vi. But I am not able to make the 3 different subvis in parallel. When one is running, the others dont. 

Can anyone please help.... thanx....


As with the orignal poster you really need to post some code. Otherwise it is very difficult to tell what is not working and how to resolve your issue.

 



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 6 of 21
(6,313 Views)

my main point it... everywhere there are many suggestions on how to call the same subvi by many main VIs by making it reentrant. But what I want is the other way round. I want to call different subvis simultaneously in one main vi. i cannot use parallel loops because the 3 subvis r called in the event structure and the event is the click of a button.

0 Kudos
Message 7 of 21
(6,310 Views)

I suggest you look at the producer/consumer architecture. In your case it sounds like you would have one producer (the loop with your event structure) and three consumers. When the event is triggered the producer would post messages to queues/notifiers that the consumer loops are waiting on. However, you can call three subVIs in the event structure and they will run in parallel provided they have no data dependencies between them. However, it is generally a good idea to keep the code that runs in event structures very small and allow parallel tasks to perform the work. This keeps the UI very responive. If you have lots of code in your event structure the UI appears to be unresponsive.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 8 of 21
(6,304 Views)

 


@Preetisar wrote:

my main point it... everywhere there are many suggestions on how to call the same subvi by many main VIs by making it reentrant. But what I want is the other way round. I want to call different subvis simultaneously in one main vi. i cannot use parallel loops because the 3 subvis r called in the event structure and the event is the click of a button.


 

Yes you CAN use parrallel loops!  look into the queue and notifier shipping examples.  Thes will give you some ideas on how to control the execution of independant threads from a single event.

 

On the other hand- you seem to be queriing a single stepper stage for x-y-z.  Are the axisi truely independant or do they share a com port?


"Should be" isn't "Is" -Jay
0 Kudos
Message 9 of 21
(6,298 Views)

A person cannot click the mouse 3 times simultaneously. Therefore, if your subVIs are in the event structure, this is impossible. If you post code, like has been suggested multiple times, I am sure we suggest a way to implement what you are trying to do.

0 Kudos
Message 10 of 21
(6,293 Views)