Best Way to Acquire Data and perform PID Control Simultaneously

Hello-
I'm interested in using IGOR PROs NIDAQmx Tools to:

1) Acquire a voltage input at a relatively fast sampling rate (scan a channel), while
2) Simultaneously operating a control loop based on said signal, at a substantially slower update rate. This could be either through a separate read/write loop or by reading off data from the above signal and writing out the control signal.

The DAQ device is the NI USB-6259. Is this even possible with Igor? Is the only way to use two DAQ cards on two different computers? Thanks for any suggestions!
I'm guessing that you are Ray Friddle, and you posted to the Igor mailing list as well. But there you added a suggested approach:
Quote:
It sounds like the simplest approach is to run the fast scan of the data in the background, and use DoXOPIDLE in a user function loop to allow access to that data for feedback. Although my feedback loop can be slow, I fear this will be too slow and limited.

For the record, here is my response that I posted on the mailing list:

It sounds like you have a pretty good understanding of the problem. The DAQmx_AI_SetupReader operation and fDAQmx_AI_GetReader function are provided exactly in order to provide a way to implement a feedback loop, but they don't achieve the goal of getting a high-rate scan while providing low-rate feedback. For the output part of the feedback loop, you need DAQmx_AO_SetOutputs and fDAQmx_AO_UpdateOutputs.


I'm afraid the only way to find out if you can make your scheme work is to try it out.

When you find out that your solution isn't adequate, you may need to consider getting a second device so that you can do high-rate scanning with one, and do the feedback loop on the other. Or you might be better off writing a custom XOP to implement your scan/feedback loop.

I might also add that there was another response on the mailing list.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Yep, I thought I'd hit both fronts. Thanks a lot for the advice. I have a solution that works for what I'm doing - I'll post the basic idea once I've worked out the kinks in case anyone else is interested.
Do you need continuous acquisition of your voltage input? If small gaps are ok, you could acquire a block of readings, average them (or whatever), then output a voltage, then acquire another block, etc. This is easy and might result in a high "duty cycle" of data taking if your original blocks are long enough (their sampling rate could be very high, of course).

This would be a lot easier than doing a multirate feedback loop (one rate for input, one rate for output).

John Bechhoefer
Department of Physics
Simon Fraser University
Burnaby, BC, Canada
Hi Bech, I thought about doing that, but I've come up with something that works fast enough for me, and is faster than the main loop speed. I also posted this in the email list, but for consistency I'm putting it here too.

I took John's advice to just try it out. Here is what I've come up with and I'm able to get the feedback loop to run up to 675 Hz,

The fast input signal comes into a FIFO using the DAQmx_scan command. I'm sampling at about 100 kHz.

At the same time I start a user function which initializes output for fast writing (DAQmx_AO_setoutputs), then I run a Do-While loop for the PID control.

Within the body of the loop I call fDAQmx_ScanGetAvailable to dump the FIFO followed by FIFOstatus to get the last point written in the FIFO. Then I use FIFO2Wave to transfer the last 100 points of the FIFO into a wave, average them, operate the PID calculations, then output the result with fDAQmx_AO_UpdateOutputs.

Like I said, I can run the control loop up to 675 Hz while acquiring my input signal as fast as my Card can handle. So... I suppose this approach doesn't access the main loop (60 Hz limited)?