Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Getting binary data and timestamp for triggered analog acqu. with NI6110

Hi,

I asked this question a couple of days ago and got a reply, but the reply didn't actually solve my problem, so I'm trying again:

I'm performing digitally triggered, buffered data acquisition with a PCI-6110E, possibly with pretrigger sampling. The data I'm acquiring may extend several second before and after the trigger.  Additionally, my application may call the AI READ VI at some unpredictable time several seconds after data acquisition is complete.  The AI READ VI can be used to get either binary data or waveform data representing the acquired data. As far as I can tell, the timestamp of the waveform (whose exact nature appears to be undocumented) is calculated from the time shown by
system clock at the time at which the digital trigger occurs, and doesn't depend on when the AI READ VI is called. I want to get EXACTLY the timestamp that the AI READ VI would include in waveform data, were it asked to return waveform data, but I want to use the AI Read VI to return binary data, instead.  Is there a way to get this timestamp without getting the waveform data?

Thanks,
Neal
0 Kudos
Message 1 of 7
(3,601 Views)
Neal,

In cases where the answer to your question is not completely satisfactory I suggest you place a comment in your previous question explaining why, and also place a link to your new posting. This way you effectively share your concern and experience with the rest of the discussion forum.

This question was previously answered at:

http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=135&HOID=506500000008000000DD830000&UCATEGORY_0=_30_%24_12_&UCATEGORY_S=0

Regarding your question:

The Waveform Timestamp is calculated by AI Read VI as soon as the data becomes available to it. AI Read polls for the requested amount of data and once it becomes available it gets the System Time and performs some calculations using the dt (Scan Rate) to provide a timestamp for the first point in the waveform it will return to the user.

The timestamp always refers to the first point in the waveform, so for reference triggered applications (stop trigger, aka applications with pre and post-triggered data), assuming you don't change the read/search position parameters, the timestamp is referred to the first pre-triggered sample in your waveform.

The above information should serve as the background that would help you solve the issue. Some things to watch out for:

- Since AI Read gets the system time as soon as the data is available to it, delaying the AI Read call so that it executes after the operation has already acquired the data will yield an erroneous timestamp. This is expected behavior because as soon as AI Read is called, the data is available, so it gets the system time, performs the extra calculations to determine t0 and returns the waveform data.
- The timestamp on the waveform data type was designed to give a rough estimate of the time the waveform was acquired. It�s accuracy is limited by the system�s time accuracy, ~1ms. The board�s internal timebase provides much higher time resolution (relative time).

Some suggestions on how to obtain a good timestamp:


- Call AI Read right after you start the acquisition. Read only a couple of points in waveform datatype to get the timestamp. After that you may call AI Read (binary or any data type you want) to get the rest of the data. You can read the whole buffer again if you want by changing the Read/Search parameters in AI Read.

- Modify your application to use a counter to timestamp your trigger. Basically take advantage of the internal timebase of the board, start a buffered event counting application and get the system time at that instant, for future reference. Use the start trigger signal as the counter�s gate and an internal timebase as the source (preferably the 100kHz to avoid the counter roll-over). Once the trigger occurs you�ll be able to read the timestamp from the counter and correlate it to the system time you obtained earlier.


I hope this helps,

Alejandro Asenjo
Applications Engineer
National Instruments
0 Kudos
Message 2 of 7
(3,601 Views)
Timestamps with a 1 ms accuracy are enough for my purposes.

>> Call AI Read right after you start the acquisition. Read only a couple of points in waveform datatype to get the timestamp. After that you may call AI Read (binary or any data type you want) to get the rest of the data. You can read the whole buffer again if you want by changing the Read/Search parameters in AI Read.

I've been experimenting with a similar method and I've run into an inconvenience. I use the AI READ VI to get all the acquired data (including pretrigger samples) as binary data and then I use the AI READ VI to get a wavform for first acquired point (i.e. the earliest pretrigger sample). It seems that to get a waveform for the first acquired data point, I need to use the AI READ VI with a read/search location with a position of -(nscans-1) relative to the "end of data", where nscans is the number of scans acquired. I'd like to create a subVI to do all the work to determine the timestamp for the beginning of acquistion, but this VI needs to know the value of nscans, which is information I'd like to avoid passing in through a control (mostly for asthetic reasons). Is there some AI utility VI that could be used by my hypothetical subVI to determine the number of scans that have been acquired and are sitting in the buffer? On a related note, is there an AI utility VI that can be used to determine the number of pretrigger scans


>> Modify your application to use a counter to timestamp your trigger. Basically take advantage of the internal timebase of the board, start a buffered event counting application and get the system time at that instant, for future reference. Use the start trigger signal as the counter?s gate and an internal timebase as the source (preferably the 100kHz to avoid the counter roll-over). Once the trigger occurs you?ll be able to read the timestamp from the counter and correlate it to the system time you obtained earlier

Can you point me to example VIs that will teach what I need to do this? In particular, can you point me to an example of how to "Use the start trigger signal as the counter?s gate"?

Thanks,
Neal.
0 Kudos
Message 3 of 7
(3,601 Views)
Neal,

Regarding your questions:

1) I've been experimenting with a similar method and I've run into an inconvenience. I use the AI READ VI to get all the acquired data (including pretrigger samples) as binary data and then I use the AI READ VI to get a waveform for first acquired point (i.e. the earliest pretrigger sample).

I can�t recommend this approach because I don�t see how it would work. Based on what I mentioned before. The Read VI gets the system time for reference once all requested samples are available. If the call to AI Read is done way after the samples are already available then the timestamp is not really valid.
I�ll try to help out with the rest of the questions:

2) Is there some AI utility VI that could be used by my hypothetical subVI to determine the number of scans that have been acquired and are sitting in the buffer?

With NI-DAQ 6.9.3 the only way to find this out (determine the backlog) is to call AI Read with number of scans to read equals to zero. This will not return any data and will give you the current scan backlog number as an output.

3) On a related note, is there an AI utility VI that can be used to determine the number of pre-trigger scans

Not really, the number of pre-trigger samples is always specified by the user (the default is zero which is not a valid pre-trigger count) and we don�t currently expose a function that would let the user read that value back.

4) Can you point me to example VIs that will teach what I need to do this?

Sure. You can access the examples that route the Analog Trigger Output to the gate of the counter by going to NI Developer Zone and searching for:

+trigger +counter +analog

You'll find two examples at the top of the list:

Using the Analog Trigger Circuitry Output as an External Signal

Measuring Analog Input (AI) Frequency with Analog Triggering

The first one might be a little complicated. The second one will be really useful for what you are doing. You�d basically need to change the counter operation to be buffered event counting and select the 100 kHz timebase as the source (to avoid counter rollover).

I hope this helps,

Alejandro
0 Kudos
Message 4 of 7
(3,601 Views)
>> The Read VI gets the system time for reference once all requested samples are available. If the call to AI Read is done way after the samples are already available then the timestamp is not really valid.

I've been experimenting with the AI Read VI and digitally triggered, buffered acquisition. I modified an example VI called, I think, "Acquire N Scans Digital Trig.vi" to call AI Read two times with several seconds of delay between calls. The first call, which returns the entire acuisition as waveform data, is made before acquisition is complete, so it blocks until it can return the data. The second call, after after the imposed delay, returns 1 scan worth of waveform data with a read/search location of -(NSCANS-1) relative to "end of data". It turns out that the timestamps of both sets of waveform data are the same to within a millisecond, in spite of the delay. Clearly, AI Read doesn't generate a new timestamp every time it is called between completion of acquisition and the calling of AI Clear. Does the first call to AI Read cause the storage of a system time which is then used for subsequent calls to AI Read that occur before AI Clear, or does the PCI6110E board store a system time when it acquires the data, independent of when AI Read is called, that the AI Read VI refers to to generate timestamps? The distinction is important since I would like the first call to AI Read to return binary data, rather than waveform data as was returned in the above experiment, but I would not like the system time used for timestamps to be stored only upon the second call to AI Read.

>> With NI-DAQ 6.9.3 the only way to find this out (determine the backlog) is to call AI Read with number of scans to read equals to zero.

If the AI Read VI has already been called at least once to read the entire set of acquired data (= entire buffer?), will this method work? I was under the impression that "backlog" only refers to data which has never been returned by the AI Read Buffer VI, or AI Read VI. This is significant to me because I was hoping to create, for my own future use, a subVI that would return the timestamp of the first acquired data point given as input only a task id. For maximum flexibility in future use, I wanted to be able to insert this subVI anywhere in a diagram with the only restrictions being that it should be executed after triggered acquisition was complete but before the AI Clear VI cleared the task ID. If the definition of "backlog" depends on whether the data has already been read at least once, then using the AI Read to get the backlog to determine the number of scans acquired will have different results depending on when it is executed with respect to other calls to AI Read. This would make it difficult to use it in my hypothetical timestamp subVI.

>>>> 4) Can you point me to example VIs that will teach what I need to do this?

>>Sure....

Thanks. This should be very useful.


Thanks,
Neal.
0 Kudos
Message 5 of 7
(3,601 Views)
>> I've been experimenting with the AI Read VI and digitally triggered, buffered acquisition. I modified an example VI called, I think, "Acquire N Scans Digital Trig.vi" to call AI Read two times with several seconds of delay between calls. The first call, which returns the entire acquisition as waveform data, is made before acquisition is complete, so it blocks until it can return the data. The second call, after the imposed delay, returns 1 scan worth of waveform data with a read/search location of -(NSCANS-1) relative to "end of data". It turns out that the timestamps of both sets of waveform data are the same to within a millisecond, in spite of the delay.

Your point is valid. If you call AI Read with a read/search location of -(NSCANS-1) relative to "end of data" then it will not generate a second timestamp because the read/search location relative to "end of data� is telling the VI that the data has already been acquired and that it should use the timestamp already associated with it

>> Clearly, AI Read doesn't generate a new timestamp every time it is called.

As can be inferred from above, AI Read will generate a new timestamp when called depending on the read/search mode used.

>> Does the first call to AI Read cause the storage of a system time which is then used for subsequent calls to AI Read that occur before AI Clear?

The short answer is yes. Let me clarify under which circumstances the timestamp remains associated with the data:

If using a reference trigger
AND calling AI Read before the hardware has finished the input operation
AND specifying the read search location relative to the trigger point
AND reading the total amount of points in the buffer (read = buffer size)

Then:

A correct timestamp (precise to the ms range) will be associated to the data. The timestamp will be obtained from the system time by the AI Read VI as soon as the data is available. Calculations will be performed in order to subtract the total acquisition time ((pre-trigger + post-trigger samples) / Scan rate)) from the time the data was available to AI Read (the time the hardware operation completed) therefore obtaining the t0 (initial time of the returned waveform).

Additionally:

Successive calls to AI Read with a read/search position relative to the end of data will not yield in a new timestamp and will use the original system time (from when the data became available and perform the same calculations again in order to return t0.

>> or does the PCI6110E board store a system time when it acquires the data, independent of when AI Read is called, that the AI Read VI refers to to generate timestamps?

No, the hardware does not access the system time. AI Read obtains the timestamp. You can verify it by delaying the initial AI Read long enough so that the operation is complete way before you issue the Read call.

>> If the AI Read VI has already been called at least once to read the entire set of acquired data (= entire buffer?), will this method work?

Assuming you are referring to finding out what the current backlog is:

It will work if you use the read search position relative to the end of data, with an offset of �NSCANS. And the number of scans to read equals zero.
I must warn you that the timestamp will be bogus because the calculations will not work correctly unless you read all the data available in the buffer (make the number of scans to read equals to the buffer size). This takes us to the next point:

>> I was under the impression that "backlog" only refers to data which has never been returned by the AI Read Buffer VI, or AI Read VI. This is significant to me because I was hoping to create, for my own future use, a subVI that would return the timestamp of the first acquired data point given as input only a task id.

If you are willing to make the timestamp calculation yourself then I believe it would possible to do it by:

- Reading from the same task ID before you clear the operation.
- Setting the read search position relative to the end of data, with an offset of �NSCANS
- Reading 0 scans and subtracting the total acquisition time ((pre-trigger + post-trigger samples) / Scan rate)) from the timestamp you obtain from the waveform returned by the read call.

I know one of your concerns has been the amount of data you pass into your sub-VIS. I understand this concern and I wanted to point out that there is more than one way to pass data in LabVIEW. Things that might be useful:

- Using clusters
- Using local Variables
- Using clusters and local variables
- Using Global Variables
- Using VI Server to read, write and programmatically control VIs (even if they are not sub-VIs of your application)

I have also noticed that you are concerned with the fact that AI-Read blocks the program execution. AI Read is a synchronous call and it will wait for the requested amount of data or time-out. Some things you might want to experiment with:

- Using parallel architecture within your Vis, there are all kinds of synchronization objects available in LabVIEW, you can use local variables to pass data.
- Using a timeout of 0 in your AI-Read and polling every so often to see if the data is there (your timestamp will be affected by how often you poll)
- Using DAQ Events (occurrences in LabVIEW). Unfortunately the DAQ Occurrences do not apply to pre-triggered (this case) acquisitions because the occurrences are fired by the continuous acquisition (which is waiting for the reference trigger).
- Using VI Server to execute a separate VI which could perform the acquisition and hold the data for you, without obstructing the dataflow of your main VI.
- Dynamically calling a sub-vi and using VI Server to read the results from it (similar to the previous option)

For more information on the topics I have mentioned above please consult the LabVIEW User Manual and the LabVIEW Measurements manual. There are also shipping examples available for some of these concepts.

I hope this helps,

Alejandro
0 Kudos
Message 6 of 7
(3,601 Views)
Thanks for the suggestions (VI server, synchronization, global variables...). I've actually tried or considered most of these things. I think I understand now how the timestamp is generated. The solution I may ultimately go with, if it's possible, is to set up a VI that watches for the digital triggger that runs simultaneousy and seperately from the subVIs which do the acquisition starting and reading. In a previous post, you described how a counter might used to count time elapsed from the trigger. I might, instead, set up a VI that watches for the trigger and gets the system time when it occurs, so that the AI Read VI needn't be called before the acquisition is complete.

Thanks,
Neal.
0 Kudos
Message 7 of 7
(3,601 Views)