LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to optimize code for speed

I need help with optimizing my code for speed.  I'm running my code in labview 8.5 with an NI PCI 6259 M series card and BNC 2120.  I'm reading one analog channel, and writing two (one constant enable voltage, and the other from a closed loop PD controller I'm running).  On a fast computer, I can only run at about 400Hz.  I'm monitoring loop time, and it goes up as I try to run at 500Hz and up.  Removing a few waveform charts from the front panel helped a lot, but this is still too slow.

 

Maciek

Download All
0 Kudos
Message 1 of 3
(2,674 Views)

You should use 'Continous' acquisition instead of 'Hardware timed single point'.

 

That should do the trick.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 2 of 3
(2,656 Views)

Sorry, I am not a "hardware guy", so you should listen to Ton. 🙂

 

Programming wise, you do a couple of things very inefficiently, for example you retain a history by building an array then trimming it back to the original length using "array subset". Use a fixed size array and do things "in place". You can keep the number of "valid" elements in another shift register for the average calculation.

 

  • Why do you use "read N chanNsampl" for the AI, and then index out the first element. Wouldn't "1chan1sampl" be more approriate?
  • What is the purpose of the flat sequence? Execution order is the same without it.
  • You might try if "disable debugging" provides any speed benefit.

 

Have you also looked at the PID toolkit? Are you running this on an RT system or under windows? For really fast control, FPGA can easily go into the MHz.

0 Kudos
Message 3 of 3
(2,626 Views)