Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

how to synchronize a start triggered analog output with a reference triggered analog input ?

Here is the requirement:
2 Analog outputs have to be performed on DAC0 and DAC1 on the occurence of a digital trigger.
At the same digital trigger, the above DAC 0 output has to be sampled(pretrigger and postrigger acquisition has to be performed).

Analog output uses a start trigger and Analog input uses a reference trigger.
How do I make sure that analog output occurs before analog input is performed as both of them occur at the same digital trigger?

Here is a sample code am working on (C#):
DAC0 output is connected to Analog input channel 0 for sampling the DAC 0 ouput.

void someFunction()
{
.....
...
aoTask.AOChannels.CreateVoltageChannel ("Dev1/ao0" ,"StimulusPulse" , -5 ,5 ,AOVoltageUnits.Volts );
aoTask.AOChannels.CreateVoltageChannel ("Dev1/ao1" ,"DCVoltage" , 0 ,5 ,AOVoltageUnits.Volts );

aoTask.Timing.ConfigureSampleClock("",1000 ,SampleClockActiveEdge.Rising ,SampleQuantityMode.FiniteSamples,150 );
aoTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger( "/Dev1/PFI0",DigitalEdgeStartTriggerEdge.Rising);
aoTask.Control (TaskAction.Verify );

aoMultiChannelWriter = new AnalogMultiChannelWriter (aoTask.Stream );

aiTask.AIChannels.CreateVoltageChannel ( "Dev1/ai0","DAC0Output" ,AITerminalConfiguration.Nrse,-5 ,5 ,AIVoltageUnits.Volts ) ;
aiTask.Timing.ConfigureSampleClock("",10000,SampleClockActiveEdge.Rising ,SampleQuantityMode.FiniteSamples,1500);
aiTask.Triggers.ReferenceTrigger.ConfigureDigitalEdgeTrigger( "/Dev1/PFI0",DigitalEdgeReferenceTriggerEdge.Rising,500);
aiTask.Control (TaskAction.Verify );

aiMultiChannelReader = new AnalogMultiChannelReader(aiTask.Stream );

...
...
//aoData contains DAC0 and DAC1 data
aoMultiChannelWriter.WriteMultiSample(false,aoData );
aoTask.Start();

delegateCallBack = new AsyncCallback (AITaskCallBackFunction);
aiMultiChannelReader.BeginReadMultiSample(1500,delegateCallBack,null );

aoTask.WaitUntilDone (-1);
}

void AITaskCallBackFunction(IAsyncResult ar)
{

aiData = aiMultiChannelReader.EndReadMultiSample(ar);

... code to display data
}

Thank you in advance,
Rajesh
0 Kudos
Message 1 of 4
(3,917 Views)
Hello Rajesh,

If you use the same digital trigger as a start trigger for AO and a reference trigger for AI, your AI will start before you AO. This is because for reference triggering the AI will be running until it receives the reference trigger (plus whatever post triggered data you would like). Therefore, I would recommend using one digital trigger as a start trigger for both AI and AO (this way they both start simultaneously). Then use a second digital trigger as a reference trigger for the AI.

So for your code, I would change the "aiTask.Triggers.ReferenceTrigger.ConfigureDigitalEdgeTrigger( "/Dev1/PFI0",DigitalEdgeReferenceTriggerEdge.Rising,500); " to be a start trigger.
Then add this line of code: "aiTask.Triggers.ReferenceTrigger.ConfigureDigitalEdgeTrigger("a different PFI Line",DigitalEdgeReferenceTriggerEdge.Rising,500); "

I hope this helps... Let me know if you have any further questions.

Sincerely,
Sean C.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 4
(3,905 Views)
Hi Sean,

Thank you very much for the information.

I'm using start triggers for both the analog input and analog output but sometimes I see a situation where the analog input misses the trigger and analog output catches the trigger. I need to start both the analog input and analog output at the same time. Here is the sample code i'm working on.

aiTask.Stream.Timeout = -1;
while (!stopAO)
{


//Initializes aoData
........


Line 1: aoMultiChannelWriter.WriteMultiSample(false,aoData );
Line 2: aoTask.Start();
Line 3: aiData = aiMultiChannelReader.ReadMultiSample(aiSamplesPerBlock);
Line 4: Trace.WriteLine("****AI - Completed**********");
Line 5: aoTask.WaitUntilDone (-1);
Line 6: aoTask.Stop();
}

In the above code, I see a case where a trigger can occur between Line 2 and Line 3 and as a result the aoTask catches the trigger fine and performs the output operation(I can see this on the oscilloscope) where as the analog input statement blocks, waiting for the trigger to occur(as I don't see a trace message in the output window). Is there way that I could perform the operations in Line 2 and Line 3 atomically. In other words I should be able to execute the start operations for aoTask and aiTask atomically.

One more question sean,

Is there a way to disable the PFI0 trigger using the measurement studio api?

Thank you in advance,
Rajesh
0 Kudos
Message 3 of 4
(3,885 Views)
Rajesh,

Here is an example in C that demonstrates how to continuously acquire analog and digital data at the same time, synchronized with one another on the same device. It is not exactly what you are trying to do, but it should point you in the right direction.

Hope this helps.

JenK
0 Kudos
Message 4 of 4
(3,857 Views)