Data Acquisition Toolbox
  Function/Property:
    Search    Help Desk 

Repeating Triggers

Triggers may be configured to occur once (one-shot acquisition) or repeated times. Trigger repeats are controlled with the TriggerRepeat property. If TriggerRepeat is set to its default value of 0, then the trigger occurs once when the trigger condition is met. If TriggerRepeat is set to a positive integer value, then the trigger is repeated the specified number of times when the trigger condition is met. If TriggerRepeat is set to Inf then the trigger repeats continuously when the trigger condition is met and the data acquisition can be stopped only with an explicit stop command.

Example: Voice Activation and Repeating Triggers

In this example, two triggers are issued. An amount of data given by SamplesPerTrigger is acquired for each trigger and stored in a separate variable. The Timeout value is set to five seconds. Therefore, if getdata does not return the specified number of samples in five seconds plus the amount of time required to acquire the data, the acquisition will be aborted.

Initialization: Create the analog input object AIVoice for a sound card. The available adaptors are found with daqhwinfo.

Configuration: Add one hardware channel to AIVoice, and copy it to the variable chan, define a one second acquisition, and set up a software trigger. The source of the trigger is chan, and the trigger is issued when a rising voltage level has a value of at least 0.2 volts. Additionally, the trigger is repeated once when the trigger condition is met.

Execution: Start AIVoice, wait for AIVoice to stop running, extract all the data from the first trigger as sample-time pairs, and extract all the data from the second trigger as sample-time pairs. Note that the data acquired from both triggers can be extracted with one getdata call by specifying getdata(AIVoice, 44100).

Termination: Plot the data for both triggers and delete AIVoice.

The data acquired for both triggers is shown below


You can keep track of the number of triggers issued and the absolute times they occurred with the TriggerTime property. To find out how many triggers occurred, you can use MATLAB's length command

To find out the trigger times, you must convert the elements of the TriggerTime array from the datenum format to a string. For example, the time of the first trigger is calculated below.

You can also return data from multiple triggers with one call to getdata by specifying the appropriate amount of data. This number is given by (SamplesPerTrigger) × (TriggerRepeat + 1). When you return data that spans multiple triggers, a NaN is inserted in the data stream between triggers. Therefore, an extra "sample" (the NaN) is stored in the engine and returned by getdata. Identifying these NaNs allows you to identify where and when each trigger was issued in the data stream.

The figure below illustrates the data stored by the engine during a multiple-trigger acquisition, and the relationship between SamplesPerTrigger and the time recorded by TriggerTime. The first element of TriggerTime corresponds to t1, the second trigger time corresponds to t2, and so on.


The commands shown below modify the previous example so that multiple-trigger data is extracted from the engine with one call to getdata.

The data is shown below.


The following code illustrates how you can find the relative trigger times, measured in fractions of seconds, from the absolute trigger times.

Another way to find the relative trigger times is to search for NaNs in the returned data. You can find the index location of the NaN in d or t using the isnan function.

With this information, you can find the relative time that the second trigger was issued.



[ Previous | Help Desk | Next ]