Configuring Analog Input Properties

Analog Input: Basic Properties

After hardware channels are added to the analog input object, you should configure property values. As described in Configuring and Returning Properties, the Data Acquisition Toolbox software supports two basic types of properties for analog input objects: common properties and channel properties. Common properties apply to all channels contained by the device object while channel properties apply to individual channels.

The properties you configure depend on your particular analog input application. For many common applications, there is a small group of properties related to the basic setup that you will typically use. These basic setup properties control the sampling rate, define the trigger type, and define the samples to be acquired per trigger. Analog input properties related to the basic setup are given below.

Table 4-2. Analog Input Basic Setup Properties

Property Name

Description

SampleRate

Specify the per-channel rate at which analog data is converted to digital data.

SamplesPerTrigger

Specify the number of samples to acquire for each channel group member for each trigger that occurs.

TriggerType

Specify the type of trigger to execute.

The Sampling Rate

You control the rate at which an analog input subsystem converts analog data to digital data with the SampleRate property. SampleRate must be specified as samples per second. For example, to set the sampling rate for each channel of your National Instruments board to 100,000 samples per second (100 kHz)

ai = analoginput('nidaq','Dev1');
addchannel(ai,0:1);
set(ai,'SampleRate',100000)

Data acquisition boards typically have predefined sampling rates that you can set. If you specify a sampling rate that does not match one of these predefined values, there are two possibilities:

The list of valid sample rates is governed by the hardware clock on the device. Most devices offer a fixed speed hardware clock that is used to drive the timing of an acquisition. In order to achieve a required sample rate, there is a programmable divider that is set from 1 to 65536. This limits the device to 65535 possible sample rates. For instance with a 100,000Hz clock, if you request 1,200 samples per second, the divider can be set to either 83 or 84. This will result in a sample rate of either 1,204.82 (100,000/83) or 1,190.48 (100,000/84).

For hardware that supports simultaneous sampling of channels (sound cards), the maximum sampling rate for each channel is given by the maximum board rate. For scanning hardware (most National Instruments and Measurement Computing devices), the per-channel sampling rate is given by the maximum hardware rate divided by the number of channels contained by the device object.

After setting a value for SampleRate, you should find out the actual rate set by the engine.

ActualRate = get(ai,'SampleRate');

Alternatively, you can use the setverify function, which sets a property value and returns the actual value set.

ActualRate = setverify(ai,'SampleRate',100000);

You can find the range of valid sampling rates for your hardware with the propinfo function.

ValidRates = propinfo(ai,'SampleRate');
ValidRates.ConstraintValue
ans =
  1.0e+005 *
    0.0000    2.0000

Trigger Types

For analog input objects, a trigger is defined as an event that initiates data logging to memory or to a disk file. Defining an analog input trigger involves specifying the trigger type with the TriggerType property. The TriggerType values that are supported for all hardware are given below.

Table 4-3. Analog Input TriggerType Property Values

TriggerType Value

Description

{Immediate}

The trigger occurs just after the start function is issued.

Manual

The trigger occurs just after you manually issue the trigger function.

Software

The trigger occurs when the associated trigger condition is satisfied. Trigger conditions are given by the TriggerCondition property.

Many devices have additional hardware trigger types, which are available to you through the TriggerType property. For example, to return all the trigger types for the analog input object ai created in the preceding section:

set(ai,'TriggerType')
[ Manual | {Immediate} | Software | HwDigital ]

This information tells you that the National Instruments board also supports a hardware digital trigger. For a description of device-specific trigger types, refer to Device-Specific Hardware Triggers, or the TriggerType reference pages in Base Properties — Alphabetical List.

The Samples to Acquire per Trigger

When a trigger executes, a predefined number of samples are acquired for each channel group member and logged to the engine or a disk file. You specify the number of samples to acquire per trigger with the SamplesPerTrigger property.

The default value of SamplesPerTrigger is calculated by the engine such that 1 second of data is collected, and is based on the default value of SampleRate. In general, to calculate the acquisition time for each trigger, you apply the formula

acquisition time (seconds) = samples per trigger/sampling rate (in Hz)

For example, to acquire 5 seconds of data per trigger for each channel contained by ai:

set(ai,'SamplesPerTrigger',500000)

To continually acquire data, you set SamplesPerTrigger to inf.

set(ai,'SamplesPerTrigger',inf)

A continuous acquisition stops only if you issue the stop function, or an error occurs.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS