LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how can i make this loop quicker (more efficient)?

Solved!
Go to solution

Iv attached a screen shot of my code. In the books it says to not have 'build array' and 'concetenate strings' in the loop,but what can i use instead?Also are there any other alterations I can make to this program, to make it quicker?

 

Cheers,

Sam 

0 Kudos
Message 1 of 9
(3,187 Views)

Sam,

 

the screenshot reveals, that you have a general misunderstanding regarding passing data from loops. The inner loop (the timed loop) will return only the last set of acquisition (so last iteration only), not the whole iterations. In order to change that, you have to configure the output tunnelsto autoindex. This is not recommended for while loops (true for timed loop as well).

Another notable thing is that the timed loop is not necessary in this context. You do many things in the loop which are not deterministic. So using the timed loop under the presumption "this will be deterministic" is wrong. The biggest problem is the instrument io assistent here because the interface is definetly not deterministic (doesn't matter if serial of gpib).

In addition to that, the DAQ assistant does no good here either. Ok, with a timing of 100ms, you can supose that the timing will be kept, but there is no garantee.

 

As a general rule:

timed structures are focused on real time and fpga targets. You can use them in Windows, but the major benefit is lost there. Maybe you would use it because of some features (like "finished late[i-1]") or for external clockings. Both do not apply to your VI.

 

So remove the timed loop and replace it with a simple for loop. Insert a timing function (Wait/Wait until next multiple of ms) to keep the timing you need. Replace the assistants with proper "streaming code" in order to improve performance. If this application should log continuously, switch to a parallel loop architecture like producer/consumer.

 

hope this helps,

Norbert 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 2 of 9
(3,176 Views)

Hi Sam,

 

and in addtion to Norberts comments you should also remove that silly time string formatting code and replace it with a simple "format date/time string" function with a format of "%S%3u" (similar to what you already have done to get the hour/minute string)!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 9
(3,161 Views)
Cheers, Iv changed the timed loop to a for loop, does this mean that all the data will be passed to 'write file', not just the last loops?and Im having a go at putting in the timing you suggetsed.
Im not sure what you mean by streaming code (that I should replace the assistants with)? Lastly, parrelel loop structure, what is the benefit to continuos logging?
 Cheers,Sam 
0 Kudos
Message 4 of 9
(3,119 Views)

Sam,

 

the output tunnel will pass a collection of values (as array) if it is configured to be "autoindexing". For loops do by default index the outputs which makes sense since LV knows the maximum amount of iterations before it enters the loop. So LV knows, how much memory is needed for the array. So no additional memory allocation, so less overhead, leading to a better overall performance.

 

Regarding the Assistants: The DAQmx Assistant for example will create a new measurement task in each iteration. This takes several ms which are effictively be wasted. If you want to get away from this, you have to make yourself familiar with the DAQmx API (Application Programming Interface). You can find many examples in the LV Example Finder. I suggest you to start looking into the analog input examples and compare Acq & Graph vs. Cont. Acq & Graph....

 

The benefit of parallel loops in regard to logging is that you break logging and acquistion apart. So if delays in one of the two functionalities does not necessarily "kill" your application. 

 

hope this helps,

Norbert 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 5 of 9
(3,110 Views)

Thanks, I have found the wait(ms) vi, but not sure how to hook it up to the for loop, to get it to wait 100ms between starting the loops. Also how do you assure that a for loop is autoindexing?

 

Cheers 

0 Kudos
Message 6 of 9
(3,108 Views)
Solution
Accepted by topic author ssteel

Sam,

 

in order to time a structure (except "timed structures" like the timed loop), you place the wait-function inside the frame where the wait should take place. So in regard to a loop simply drag and drop it iside the loop and connect a time to wait to it.

 

Looking into your VI, there are still some thing which prevent the VI from working:

- Delete unnecessary logic (comparison against 10) including invalid wires

- Connect a numeric '10' to the 'N'-terminal of the for loop in order to limit the number of iterations to 10.

- Change the output terminal of the for loop of the data cluster to be "indexing" (rightclick on the tunnel and select "enable indexing"). This will create a 2D array of strings; therefore, you have to connect the stringarray to the 2D array connector of the "write spreadsheet file" instead of the 1D connector.

- Never ever, really never never never work with unstoppable loops in Windows! This already messed up complete testing systems doing serious damage to hardware. The only target i am ok with infinite loops are fpgas and, to some extend, real time targets.....

 

The correct approach would be a producer/consumer but looking into your messages you posted the last days, i'd say that this exceeds your current knowledge of LV....

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 7 of 9
(3,090 Views)
Im going to try using parallel loops, one to read the data, one to build an array. Should I use local variables?
0 Kudos
Message 8 of 9
(3,073 Views)

Actually could you let me know were I can get some examples on the 'producer/consumer approach'.

 

Cheers 

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