Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronize DAQmx and NI-SCOPE triggers

Hi,

 

I have a DAQmx and an NI-5122 scope device set up to capture from two different sources, but sharing a common external TTL trigger.  The DAQmx device is sampling at around 60 KS/s and the scope is at 100 MS/s.   When a trigger occurs, I want to capture about .1 seconds from each device.  The timing of these triggers is unpredictable and I need to combine the data on a per trigger basis for saving.  It takes longer to download the data from the scope than from the DAQmx device and I cannot lock out the DAQmx device while the scope is downloading.  For this reason, I need to be notified of triggers with as precise timing as possible.  

 

Our current solution is to use the .Net measurement studio driver for the DAQmx device and the P/Invoke wrapper for the scope.  The DAQmx side is great, I do an asynchronous read and get notified when data is received, store the trigger time and then download the data.  This gives me an accurate trigger time.  Unfortunatley, the scope driver does not have such a model and I'm polling the completion status to know when there was a trigger and grabing the time when I've detected the completion status change, and then fetch the data.  I find that the trigger times are usually about 200ms different for the two devices, but they often go as high as 2 seconds apart for the same trigger.

 

I've found the .Net scope driver 1.1 (the application is .Net 3.5) and I'm porting the code over.  It has an event driven model, but the event handler looks like it is called after the data is downloaded.  I need to get the trigger time before the data is downloaded in order to line things up later.  I really don't want to go back to polling the completion status to know when the trigger occured.

 

Is there a way to make the scope work like DAQmx, with some soft of trigger event?  Is there a totally different way of syncrhonizing the devices that I'm missing?

 

Thanks,

 

Kyle

0 Kudos
Message 1 of 3
(5,208 Views)

Kyle,

 

What DAQ card are you using? What is the DAQ card doing as well? Depending on what you are doing you may be able to use a different card (if you have one) that supports TCLK which would sync that card with the scope card you are using automatically. 

 

In the case you do not have any other cards, there should be some waveform infomation that is recorded with the signal when measuring with a scope. In that information there should be a time stamp on the initial time that the first sample was taken.

 

I would not recommend using a soft trigger if your start timing is critical as the trigger would be controlled by software and Windows is not deterministic so your trigger could take too much time to actually cause anything to happen.

 

Could you post the smallest amount of example code that can illustrate what you are trying to do?

Noah | Applications Engineer | National Instruments
0 Kudos
Message 2 of 3
(5,190 Views)

Hi Noah,

 

Thanks for your reply.  The low speed card is a PCI-6251.  We only need 5 channels at around 60 KS/s, but we have a lot of systems and it would be expensive to change hardware on all of them.  

 

As for code, it would be tricky to put something together that would compile, but it's easy to explain.  We basically have two separate classes to listen to the two devices and raise events when the data is captured.  When data arrives, we put it into an object that matches the two and raises an event with the matched data.  The code looks only vaguely like this, but the following should give you an idea of the class responsabilities.

 

// interface on the two DAQ devices

interface IDaq

{

   event EventHandler<DataCapturedEventArgs>  DataCaptured;

}

 

// Event args to provide captured data 

class DataCapturedEventArgs : EventArgs

{

   public CapturedData Data;

}

 

// timestamped data captured from a DAQ

class CapturedData

{

   // the data

   public double[,]  Data;

 

   // the trigger time of the data

   public DateTime timeStampUtc;

}

 

 

// listens for triggers on the low speed card and provides data

class DaqmxDevice : IDaq

{

   event EventHandler<DataCapturedEventArgs>  DataCaptured;

}

 

// listens for triggers on the high speed card and provides data

class NI5122Device : IDaq

{

   event EventHandler<DataCapturedEventArgs>  DataCaptured;

}

 

 

// class to listen for data from two sources and match them on timestamp from when they

// are acquired, keeping queues and handling when one daq doesn't trigger as often as the other and when

// one daq triggers before or after the other.

class Matcher

{

   public Matcher(IDaq daq1, IDaq daq2);

 

   public event EventHandler<DataMatchEventArgs>  DataMatched;

}

 

// event args for notifying of a match

class DataMatchEventArgs : EventArgs

{

   public CapturedData Data1Data;

 

   public CapturedData Data2Data;

}

 

 

As you can see, we assumed that the two devices know nothing about each other, and this is why it is so important that we know the moment that each one triggered.  If we need to combine the DAQs together to exploit some feature, we can definitely do that.  I took a very brief look at TCLK and it looks promising.  Any method of getting a timestamp of the first sample, even if it is a sample number relative to acquisition start also sounds like it would do the trick.  I'll look more into TCLK.  Could please you point me in the right direction to get first-sample timestamps?

 

Thanks,

 

Kyle 

 

 

 

0 Kudos
Message 3 of 3
(5,182 Views)