12-22-2023 08:56 AM
I measure with osciloscope input and output signals and get 44ms between they
12-22-2023 11:02 AM
If lag (aka "latency") is your biggest concern, you should probably remove the calls to DAQmx Timing from both tasks, putting both in software-timed on-demand mode. Start both tasks before entering the main loop. I don't have DAQmx on this machine, so I can only mock up a fake illustration. (Note: loop termination definitely needs to be smartened up.)
A simple sequential method would feed the value coming out of DAQmx Read into DAQmx Write within the same loop iteration:
Another thing you might try would be pipelining, where read and write are free to execute in parallel, but you write the value from the previous loop iteration.
It's conceivable that a generally-frowned-upon approach may be useful here as well. Separate parallel loops for read and write, using a local variable to transmit new info from read to write. This lets you run each operation as fast as the driver allows. The read loop updates the value as fast as it can, the write loop always retrieves the freshest value it finds there. Note: this does *not* necessarily reduce the lag!
Further, you can probably expect to sometimes see multiple reads between writes and other times see multiple writes between reads. You lose the 1:1 correlation. But you may still judge it more appropriate overall. (Note: startup needs to be smarter, to make sure the 'data' local variable is valid before the first write)
-Kevin P
12-22-2023 12:39 PM
Thanks for the tips I have another doubt is I want use a button to enable input data to output data but when button is off the output data value change to 0