I downloaded your code and I tweaked it a bit. You indicate that the code is running slow. How slow? Do you measure the difference with a stop watch or a calendar? In general remember that you are doing all your IO inside the PID loop, which will slo it down rather dramatically. Also you are accumulating an array inside the loop. This also slows things down.
In terms of the tweaks I made. The biggest change was to the simple PID subVI. The first thing I did was get rid of the unnecessary sequence structure. It did nothing for you computationally and would have a negative impact on the code's efficiency by preventing parallel operations. It's also much easier to read now and (if I didn't miss something) should do the same thing as the original one. The other c
hange I made to it was to remove the while loop wrapped around its insides. The reason for such a while loop is to store the values of shift registers. However, the way you have the code written the SRs were being reinitialized everytime the subVI was called--effectively nullifying the reason for the SRs to exist. So is the SRs aren't needed the loop isn't either.
I also bundled some of the IO going in and out of the subVI to cleanup the interface, and changed the way you were measuring time. The primative you were using is essentially the output of a 32-bit counter so it will rollover when it reaches its maximum count. This rollover will appear to your code as a huge jump in time. Which is probibly a BAD thing...
If you give me an email address I can send you the modified code (it's apparently too big to upload here--even zipped).
Mike...
mporter@arielcorp.com
BTW: One Major thing you are doing very well: Error handling. The only additional thing you need to be on the loo
kout for is that in the DAQ drivers NI doesn't consider things like acquisition timeouts as errors. Rather it flags them as warnings (error status good but with a non-zero code).
Be looking forward to hearing from you.