Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

how to synchronize AI and AO with a SW trigger

Hi
 
I have a NI-6221 card, with C#.NET.
I've set two channels, an AI Channel that samples and an AO channel that excites a sine wave.
The AI channel samples the AO channel.
I need to sync both channels to perform a 256 samples per burst with a software trigger, meaning that when I want I can ask the framework for a 256 length sample.
This sample has to be synchronize in such why that the sample will always start at the same phase.
 
I've used the sample that NI has on the install disc but the code sample support only external trigger.
(C:\Program Files\National Instruments\MeasurementStudioVS2003\DotNET\Examples\DAQmx\Synchronization\Multi-Function\SyncAIAO_DigStart\Cs)
 
Thanks for any reply.
0 Kudos
Message 1 of 3
(3,475 Views)
Hi yoramkr,
 
I wasn't able to find you a C# example that does this, but I can give you the basic idea.  You'll have two tasks, an AI and an AO.  We'll make the AI the master task and the AO the slave task. 
 
First, set up the master task by creating the channel and setting up the timing.  Do not start the task yet, since we'll want to do that on the software trigger. 
 
Next, set up the slave task.  Create the AO channels, and set up the timing.  This time, be sure to set the sample clock source for this task to the analog input sample clock, or /DevX/ai/SampleClock.  This time, we do want to start the task.  Because it will use the sample clock of the AI channels, it will not start until it receives that clock. 

Finally, when you want to grab those samples, call a function that starts the master task (which will start the AI sample clock, in effect starting both tasks).  Then call the AI read function to grab the 256 samples from the buffer.  Once these are finished, you can stop both tasks.

Pseudocode would look something like this:

//Set up Master AI task
DAQmxCreateChannel();
DAQmxCfgSampClkTiming();

//Set up Slave AO task
DAQmxCreateChannel();
DAQmxCfgSampClkTiming(sample clock = DevX/ai/SampleClock);
DAQmxWrite(); //write the 256 values to buffer for future output
DAQmxStartTask(Slave);

//Call trigger function
Function SoftwareTrigger()
{
DAQmxStartTask(Master);
DAQmxRead();
DAQmxClearTask(Master);
DAQmxClearTask(Slave);
}

I hope this helps!

Thanks,

Justin M.
National Instruments

0 Kudos
Message 2 of 3
(3,462 Views)
The SyncAIAO_DigStart example should give you a pretty good starting point.  All you should have to do to disable the digital start trigger is to comment out the following line:
 
//inputTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger(triggerSourceTextBox.Text,
//    triggerEdge);
 
This will cause the continuous AI/AO task to start immediately after pressing the Start button.  Implementing a software trigger to take a "snapshot" of the next 256 samples (from, say, pressing a button on the form), will take quite a bit more work, depending on the specifics of how you want it to work, but basically you have to process the data in the InputRead method in order to "capture" those samples and do something with them.  If you set your samples to read to 256, then you could fairly easily set up a way to capture the "next set" of 256 samples.

How you write your software trigger is really up to you, but we do have an Analog In example called Measure Voltage\ContAcqVoltageSamples_IntClk_SWTrigger which demonstrates how one might write a software trigger for continuous analog input.  Combining the concepts from these two examples will probably get you what you need.
Hexar Anderson
Measurement Studio Staff Software Engineer
National Instruments
0 Kudos
Message 3 of 3
(3,446 Views)