08-20-2014 01:47 PM
Hi guys,
In the "data acquisition loop" (bottom right), Ive applied a tick differential to measure time during the run. However, there appears to be about a half second delay and the first few values returned look like this:
0 |
480 |
483 |
483 |
484 |
485 |
485 |
486 |
486 |
487 |
487 |
488 |
489 |
490 |
490 |
491 |
495 |
What can I do to fix this delay? Or will this always be an offset?
08-20-2014 01:53 PM
The execution rate of your code is directly dependently on how long it takes the code inside the loop to run. Your first iteration is going to be zero because the tick count before the loop and the one inside the loop will run at almost the same time. After that, the time it takes for then tick count will depend on how long it takes for LVCanlvdt.vi to execute (it is missing so I can't see what it does) and the write to spreadsheet file.
Writing to a file can be notoriously slow and unpredictable on how long it takes. It is dependent on the Windows OS. If something else like a virus scan happens, it may put a low priority on file writes. If it needs to find another block on the hard drive to write data to, it can take longer. Plus you are constantly opening and closing the file which takes time.
08-20-2014 02:24 PM
I altered my write to file to look like this, and it does seem to help quite a bit!
08-20-2014 02:31 PM
08-20-2014 02:39 PM
That's good to see that it helps.
The next step to take if your loop still doesn't run as fast as you need it to would be to use the Producer/Consumer Architecture which uses queues to pass the data to a separate file writing loop. That decouples any delays in file writing from the execution rate of your data acquisition producer loop.