LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Increasing While Loop Iteration Speed

Hello All,

 

I have a code that essentially reads a pressure transducer (signal input 4-20 mA) and outputs its readings (in Atm) to an excel file. 

 

This seems to me to be an incredibly simple code, however, my data acquisition while loop is iterating incredibly slowly (less than one iteration every second). 

 

This is a problem for me because I plan on having a digital step motor open and close a needle valve based the measurements from this thermocouple. I will need to have a sampling speed much faster than once a second for this purpose. 

 

Any help you can give is much appreciated!

 

Thanks,

Sage 

 

 

0 Kudos
Message 1 of 4
(709 Views)

A while loop can ONLY iterate as fast as the contents of it can be executed. With this said, your choice of architecture and implementation is the only reason your while loop iterates slow.

 

santo_13_0-1660235819554.png

 

You will get better performance adopting a state machine architecture and better usage of DAQmx functions, in general, 1 sample read is very slow and doing the signal processing within the acquisition loop will definitely slow you down from reading the next sample.

 

Edit: Just noticed that you're adding a delay inside your loop which again slows your iteration speed.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 2 of 4
(701 Views)

You have two while loops and also some disconnected code islands. Your code is very difficult to read, mostly because you seem to hide most of the labels of terminals. These should always show.

 

  • Why are there So. Many. Local. Variables???. Virtually none are needed.
  • I don't see where you measure the actual loop time.
  • Doing the "array to cluster to unbundle" dance instead of a simple "index array" is just plain silly.
  • I don't think you need the dynamic data and various "collector" express VIs. Just accumulate in a shift register.
  • A collector with a history of one is just a wire, right?
  • Your build array is not reasonable because most inputs will be padded to the longest input. What do you really want? All inputs to the built array are actually scalars (or arrays with one element), so why do you do a 2D array at all?
  • What are the default values for your controls?
  • How long does it take to read the transducer signal? This is out of your control. (Sorry, I cannot see how your task is configured).
  • Shouldn't there be some synchronization mechanism between the loops? You should only save if there is new data and not blindly. You seem to append a row with each iteration, so opening the file before the loop and using lower level primitives are more efficient. Your high-level save will open and close the file with each call.

 

I won't fault you for the yellow diagram background, but it is ugly and make certain parts harder to read (It has the same color as most primitives!).  The only explanation would be elimination of glare due to vision problems.

0 Kudos
Message 3 of 4
(698 Views)

Given that you have a WAIT MSEC function INSIDE your loop, if the control it's wired to contains anything above zero, then you're ASKING the computer to slow down.

 

Don't complain because the computer is doing what you ask it to  (don't ask me how I know this😣)

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 4 of 4
(650 Views)