Data Acquisition Toolbox | ![]() ![]() |
Defining a Trigger: Trigger Types and Conditions
Defining a trigger for an analog input object involves specifying the trigger type with the TriggerType
property. You can think of the trigger type as the source of the trigger. For some trigger types, you may need to specify a trigger condition and a trigger condition value. Trigger conditions are specified with the
TriggerCondition
property, while trigger condition values are specified with the
TriggerConditionValue
property.
The analog input TriggerType
and TriggerCondition
values are given below.
TriggerType Value |
TriggerCondition Value |
Description |
{Immediate} |
None |
The trigger occurs just after you issue the start function. |
Manual |
None |
The trigger occurs just after you manually issue the trigger function. |
Software | {Rising} |
The trigger occurs when the signal has a positive slope when passing through the specified value. |
Falling |
The trigger occurs when the signal has a negative slope when passing through the specified value. |
|
Leaving |
The trigger occurs when the signal leaves the specified range of values. |
|
Entering |
The trigger occurs when the signal enters the specified range of values. |
For some devices, additional trigger types and trigger conditions are available. Refer to the TriggerType
and TriggerCondition
reference pages in Chapter 10, Base Property Reference for these device-specific values.
Trigger types are grouped into two main categories:
The trigger types shown above are device-independent triggers since they are available for all supported hardware. For these trigger types, the action that initiates the trigger event involves satisfying a trigger condition in the engine (software trigger type), or issuing a toolbox function (start
or trigger
).
Conversely, device-specific hardware triggers depend on the specific hardware device you are using. For these trigger types, the action that initiates the trigger event involves an external analog or digital signal.
Device-specific hardware triggers for National Instruments, ComputerBoards, and Agilent Technologies devices are discussed in Device-Specific Hardware Triggers. Device-independent triggers are discussed below.
Immediate Trigger. If TriggerType
is Immediate
(the default value), the trigger occurs immediately after the start
function is issued. You can configure an analog input object for continuous acquisition by use an immediate trigger and setting SamplesPerTrigger
or TriggerRepeat
to inf
. Trigger repeats are discussed in Repeating Triggers.
Manual Trigger. If TriggerType
is Manual
, the trigger occurs just after you issue the trigger
function. A manual trigger may provide you with more control over the data that is logged. For example, if the acquired data is noisy, you can preview the data using peekdata
, and then manually execute the trigger after you observe that the signal is well-behaved.
Software Trigger. If TriggerType
is Software
, the trigger occurs when a signal satisfying the specified condition is detected on one of the hardware channels specified by the TriggerChannel
property. The trigger condition is specified as either a voltage value and slope, or a range of voltage values using the TriggerCondition
and TriggerConditionValue
properties.
Example: Voice Activation Using a Software Trigger
This example demonstrates how to configure an acquisition with a sound card based on voice activation. The sample rate is set to 44.1 kHz and data is logged after an acquired sample has a value greater than or equal to 0.2 volt and a rising (positive) slope. A portion of the acquired data is then extracted from the engine and plotted.
You can run this example by typing daqdoc5_3
at the MATLAB command line.
1. Create a device object - Create the analog input object AIVoice
for a sound card. The installed adaptors and hardware IDs are found with daqhwinfo
.
AIVoice = analoginput('winsound'); %AIVoice = analoginput('nidaq',1); %AIVoice = analoginput('cbi',1);
2. Add channels - Add one hardware channel to AIVoice
.
chan = addchannel(AIVoice,1); %chan = addchannel(AIVoice,0); % For NI and CBI
3. Configure property values - Define a 2-second acquisition and configure a software trigger. The source of the trigger is chan
, and the trigger executes when a rising voltage level has a value of at least 0.2 volt.
duration = 2; % two second acquisition set(AIVoice,'SampleRate',44100) ActualRate = get(AIVoice,'SampleRate'); set(AIVoice,'SamplesPerTrigger',ActualRate*duration) set(AIVoice,'TriggerChannel',chan) set(AIVoice,'TriggerType','Software') set(AIVoice,'TriggerCondition','Rising') set(AIVoice,'TriggerConditionValue',0.2)
4. Acquire data - Start AIVoice
, acquire the specified number of samples, and extract the first 1000 samples from the engine as sample-time pairs. Display the number of samples remaining in the engine.
start(AIVoice) while strcmp(AIVoice.Running,'On') end [data,time] = getdata(AIVoice,1000); remsamp = num2str(AIVoice.SamplesAvailable); disp(['Number of samples remaining in engine: ', remsamp])
plot(time,data) drawnow xlabel('Time (sec.)') ylabel('Signal Level (Volts)') grid on
5. Clean up - When you no longer need AIVoice
, you should remove it from memory and from the MATLAB workspace.
delete(AIVoice) clear AIVoice
Note that when using software triggers, you must specify the TriggerType
value before the TriggerCondition
value. The output from this example is shown below.
The first logged sample has a signal level value of at least 0.2 volt, and this value corresponds to time = 0. Note that after you issue the getdata
function, 87,200 samples remain in the engine.
AIVoice.SamplesAvailable ans = 87200
![]() | Configuring Analog Input Triggers | Executing the Trigger | ![]() |