LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass external control into multiple loops

Hi,

     I am trying to excute two loops in a sequentially timed order. I am not familiar with timed for loops, so I just used ordinary for loops with different loop numbers(loop count 1 and loop count 2) to control the timing. But if I wanted to change the loop counter number in the middle of excution, it would not change immediately , but only to change until an entire big loop completed. And also I want to time the entire excution, but the timer would not count continously as you can see from the attached vi's. So my questions are:

1) How to pass the external loop control into multiple loops, especially the middle layer loop?

2) How to make the timer to run continously?

 

Thanks,

Platform: xp/labview 2011

Download All
0 Kudos
Message 1 of 9
(3,675 Views)

I am not sure exactly what your final goal is, but I think you would be much better off with a state machine.  It is likely that you could do everything you are tryng to do with one while loop, no for loops, no property nodes, no sequence structure, and much more versatility.

 

Lynn

0 Kudos
Message 2 of 9
(3,666 Views)

@Exia wrote:

But if I wanted to change the loop counter number in the middle of excution, it would not change immediately , but only to change until an entire big loop completed.


Is that what you want or what you don't want?

 

I agree with Lynn that a simple state machine is the answer. Use the outer while loop for all loop operations and use a case structure to switch between states, i.e. what happen in an iteration.

 

Also, what is your obsession with value property nodes?? Why do you write to them in the innermost loop, even thought the value never changes until it the next time the big FOR loop starts over.

0 Kudos
Message 3 of 9
(3,662 Views)

Are you wanting to change the length of time for each piece of code executes in the loop?

 

As others have commented, there are some fundamental problems with the LabVIEW code you attached. The use of property nodes to change control/indicator values should only be done in rare cases. They are the slowest method of updating a control/indicator and they break data flow. Using the sequence structure to control execution flow, in the way you have, is also considered poor programming style. It make it more difficult to modify execution flow and update the code.

 

I have attached a refactored version of your application for you to look at. No doubt there is room for further improvement, but it will give you an idea of how to implement your program.In case you don't have LabVIEW 2011 I have attached a PDF file of the documentation.

 

You should also consider attending a LabVIEW Core 1 course, or purchasing LabVIEW for Everyone. Once you have some basic skills in developing dataflow applications in LabVIEW I think you will find development a lot easier.

David C
0 Kudos
Message 4 of 9
(3,650 Views)

Thanks for your advice. I have spent some time learning state machine and got it to work for both my projects during last few days. It is really flexible to add different functionalities.

What I am actually doing is to control a shutter and acquire data at the same time. And I want to set shutter frequency  freely without affecting data acquisition rate. Unfortunately, I only have one piece of hardware (3rd party with both DAC and AIN on board). But after learning state machine, I found it meets most of my goals.

As for property nodes, I found those pretty cool and convenient back in the days when I started learning labview, but only realized they break the data flow and have bad influence on timing recently.

 

Hope you guys all had a wonderful thx giving!

 

Exia

0 Kudos
Message 5 of 9
(3,610 Views)

Forgot to attach my solution

0 Kudos
Message 6 of 9
(3,602 Views)

OK, that looks much better!

 

I haven't studied the algorithm in details, but (1) what's with these "divide by 1...to U32" fragments? (2) Why are you carrying the orange wires to an autoindexing output tunnel? (Most likely the dead code eliminator of the compiler will remove them internally, but autoindeixng at a while loop boundary might lead to excessive memory use, because arrays will be built without an upper limit, depending on how long the loop runs.

0 Kudos
Message 7 of 9
(3,598 Views)

Oh, I forgot to delete those two. Those two are sending data out to a txt file. Never mind.

Do you have any idea how to handle the data out more efficiently if not using auto indexing? put file i/o inside the loop?

0 Kudos
Message 8 of 9
(3,593 Views)

I previously used Elapsed Time function which has the units of second instead of Tick Counts(ms), so that converstion is 1000 originally, then changed to 1 for convenience.

0 Kudos
Message 9 of 9
(3,586 Views)