Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Switching DAQ Tasks for a Single Channel with Hardware-Enforced Timing

Hello,

 

I am working on an application that requires an analog output signal that switches between a pre-defined waveform and a feedback control signal that depends on an external signal. An example of the type of signal I would like to generate is a ramp up from 0 to 2V over 1 second, 1 second of feedback control, then a ramp down from 2 to 0V over 1 second. For this signal, I would like for each output signal to last for exactly one second, with the precision limited only by the DAQ clock rate. I am using a NI 6353 DAQ card to generate this signal. This output signal should be synchronized with other inputs and outputs on the DAQ, and therefore strict timing is necessary. I am wondering what the best approach is to ensure hardware-enforced timing when I need to switch tasks as described above.

 

As an example, the code below implements the waveform I described above, where I simply output a sine wave one sample at a time to simulate a feedback control signal:

 

Working But Slow.png

 

This code produces the desired waveform:

 

Signal.jpg

 

However, zooming in shows that there is a latency incurred by stopping, clearing, and restarting the DAQ channel when switching between the three waveforms that can be up to about 20ms depending on how many samples there are in the waveform. This 20ms latency is too long to achieve the level of accuracy in timing for my application. I have tried a number of schemes where I attempt to parallelize the code to some degree by writing both waveforms at the program start and not waiting for the tasks to be cleared between each step:

 

Parallel Non Funtional.png

 

However I have been unable to get this type of scheme to work as I always get errors related to resources being reserved and/or buffer sizes being incorrect.

 

I was wondering if there is any way to output such an analog voltage using the DAQ that enforces strict timing to ensure that my output signal is synchronized with other inputs and outputs on the DAQ. An FPGA may be the ultimate solution, but I would like to make it work with the hardware I'm currently using if possible.

0 Kudos
Message 1 of 2
(3,461 Views)

Hi EthanJ,

 

I would suggest using a state machine with three states to select what data to write, all using the same task (one start, one stop, one clear).

 

The concept is the same as you have in your for loop (where you write your sine wave), but instead you would use a while loop and a case structure. You would add logic to determine when the case had been met (ie when the ramp has reached its maximum value, when the sine function has written exactly 1000 samples, and when the ramp has reached its minimum value). Once the final case is complete, you would exit the loop and close your task.

 

Here's a little more information on using case structures: 

http://www.ni.com/tutorial/7595/en/

 

Let me know how it goes! 

Derek B. (esoDerek)
Product Marketing Engineer
National Instruments
0 Kudos
Message 2 of 2
(3,436 Views)