LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to make my program faster?

I have a program which produces two elements array. In normally the program ends in microseconds, however when I organize my program to send the array as a data to DAQ.mx write and the array will be the voltage output from my NI USB-6012 DAQ, my program ens in 40 seconds. How can I make my program faster? Is there any solution?

 

I have attached the normal program and with DAQ.vis.

Download All
0 Kudos
Message 1 of 6
(2,716 Views)

This appears to be a follow-up to this: http://forums.ni.com/t5/LabVIEW/Odd-Index-Transpozed-Arbitrary-1D-to-2D/m-p/1791130

 

As for your question: what were you expecting? When you have no hardware, of course the code is going to run that fast. Now that you are performing analog input and output, it's bound to run slower. Your outer loop runs 41 times, and for each iteration your inner loop runs ... 41 times. That's 41 x 41 = 1681. I'm surprised it only takes 40 seconds.

 

Also, you can simplify your code by using the Ramp Pattern function to generate your array of steps and then simply using Reverse 1D Array for the "odd" indices of your outer loop.

0 Kudos
Message 2 of 6
(2,697 Views)

Comparisons with floats as loop stop conditions is dangerous, you can easily get infinate loops due to rounding errors. Are you sure that's not what's happening?

Start by using the loop 'i' directly, you can easily recalculate how many loops you'll need to run. Or calculate and use a For loop.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 6
(2,694 Views)

Very good point about the floats. Missed that one, and now I have one less nickel in my retirement fund. Time to go back to work! Smiley Frustrated

 

Of course, the whole comparison thing would be moot if the OP simply used the Ramp Pattern as I suggested. Smiley Wink

0 Kudos
Message 4 of 6
(2,689 Views)

Program 1 runs 5 times and program 2 runs 41 times per loop. the total number of inner iterations is 25 vs. 1681 for a 67x difference.

Program 1 and program 2 have no timing information, thus spin at a undefined rate.

Program 2 does single point hardware IO and also has no timing information. The speed will depend on the hardware.

 

Running at a hardware dependent rate is not a good idea in general, because the speed will vary with every change in hardware and is not deterministic. You don't even know what occurs first at each iteration: the input or the output.

 

If speed is important, what you should do is use an improved variation (Yes, use FOR loops and ramps!) of program 1 to generate the final data array, then do a single "Nchan,Nsamp" IO, running input and output synchronized hardware timed off the same clock. This way you can select any acquisition speed up the the maximum supported by your DAQ hardware. It will be fast and at an exactly defined rate as it should be! 😄

 

Try it!

 

I am not familiar with your hardware: USB-6012. can you give a link to the product page?

0 Kudos
Message 5 of 6
(2,674 Views)

Oh, I am sorry my hardware is USB-6212 BNC.

 

http://sine.ni.com/nips/cds/view/p/lang/en/nid/207097

0 Kudos
Message 6 of 6
(2,649 Views)