Showing results for 
Search instead for 
Did you mean: 

Help with optimizing code speed

Hello, I'm having issues with optimizing my LabVIEW code to be faster. I have full functionality from my code, but my method of data recording is not nearly fast enough for the experiment I am trying to run. I'm looking to get data every 1 ms recorded. I know where the issue is, but I can't figure out how to program around this issue.The purpose of the program is to turn on a device and after it reaches a certain data value it will switch off. Now once this has completed it needs to go back to being turned on again and continue this process until the program is stopped. The only way I could think of doing this program is by creating a double while loop. That way after every iteration the program would basically reset and start from the on position and then turn off. I'm the only one at my institution that uses LabVIEW to this extent so this is the best place for me to get feedback.


My code is currently completing in about 15ms, but I need to record data every 1ms. I am unable to record steady data points below 20ms at the moment. So I either have to increase the number of data points I can store into excel at one time or I have to figure out a more efficient way that the LabVIEW program can run.


I've attached my code so it might be easier to see how to fix this issue.

0 Kudos
Message 1 of 2

What DAQ hardware are you using?


Your program reads and writes one sample at a time.  That is called software timed data acquisition and it is limited by the slowest thing in the loop and by several calls to the OS. You may want to switch to hardware timing and read/write mutliple samples on each call to the DAQ Read and Write VIs.


Next, separate the data acquisition from the file writes. The Write to Spreadsheet opens and closes the file each time it is called: SLOOOOWW!  Look at the Producer/Consumer Design Patterns for an example of how to do the file I/O in a parallel loop at a lower rate.  Also move all front apnel indicators to the slower consumer loop.


Move the AO Create Virtual Task.vis and the Clear Task.vis outside the loop.  Those processes are also SLOOOWW! Only write to the AO lines if something changes.  There is no need to repeatedly write the same value.  If this is controlling some kind of external device, you may want to add Writes outside the loop which send zeros (or other safe value) to the device before clearing the tasks.



Message 2 of 2