Acquire data from multiple analog channels of data acquisition device
Data Acquisition Toolbox™
Note: Some devices are not supported by the Simulink® blocks in Data Acquisition Toolbox. To see if your device supports Simulink, refer to Supported Hardware.
The Analog Input block opens, initializes, configures, and controls an analog data acquisition device. The opening, initialization, and configuration of the device occur once at the start of the model execution. During the model run time, the block acquires data either synchronously (deliver the current block of data the device is providing) or asynchronously (stream buffered incoming data).
The block has no input ports. It has one or more output ports, depending on the configuration you choose in its dialog box.
Use the Analog Input block to incorporate live measured data into Simulink for:
System and algorithm modeling
Model and design validation
The following diagram shows the basic analog input usage configuration, with which you can:
Acquire data at each time step or once per model execution.
Analyze the data, or use it as input to a system in the model.
Optionally display results.
Notes To use this block, you need both Data Acquisition Toolbox and Simulink software.
You can use the Analog Input block only with devices that support clocked acquisition. To acquire data using devices that do not support clocking, use the Analog Input (Single Sample) block.
If you have DSP System Toolbox™, you can use this block for signal applications.
This block supports the use of Simulink Accelerator™ mode, but not Rapid Accelerator or code generation.
The block supports the use of model referencing, so that your model can include other Simulink models as modular components.
For more information on these features, see the Simulink documentation.
Use the Block Parameters dialog box to select your acquisition mode and to set other configuration options.
The device from which you want to acquire data. The items in
the list vary, depending on which devices you have connected to your
system. Devices in the list are specified by adaptor or vendor name
and unique device ID, followed by the model name of the device, for
ni Dev1 (USB-6255). The first available
device is selected by default. CompactDAQ chassis would be shown as
a single device; vendor name, chassis ID, and chassis model would
be shown in the list, for example,
ni cDAQ2 (cDAQ-9172).
Asynchronous — In asynchronous mode, the data acquisition from the device and the simulation happen in parallel. The model initiates the acquisition from the device when the simulation starts. Data from the device is continuously acquired into a FIFO (first in, first out) buffer in parallel as the simulation runs. At each time step, the model fetches data from the FIFO buffer and outputs a block of data. The data in the FIFO buffer is contiguous according to the hardware acquisition clock.
Synchronous — In synchronous mode, the simulation is blocked while acquiring data from the device. The model initiates the acquisition from the device at each time step and immediately enters a wait state until the acquisition request has completed. This is unbuffered input; the block outputs the latest block of data at each time step.
The following diagrams show the difference between synchronous and asynchronous modes for the Analog Input block.
Synchronous Analog Input
At the first time step (T1), the acquisition is initiated for the required block of data (B1). The simulation does not continue until B1 is completely acquired.
Asynchronous Analog Input – Scenario 1
Scenario 1 shows the case when simulation speed outpaces data acquisition speed. At the first time step (T1), the required block of data (B1) is still being acquired. Therefore, the simulation does not continue until B1 is completely acquired.
Asynchronous Analog Input – Scenario 2
Scenario 2 shows the case when data acquisition speed outpaces simulation speed. At the first time step (T1), the required block of data (B1) has been completely acquired. Therefore, the simulation runs continuously.
Note: Several factors, including device hardware and model complexity, can affect the simulation speed, causing both scenarios 1 and 2 to occur within the same simulation.
The channel configuration table lists the hardware channels of your device, and lets you configure them. Specify which channels to acquire data from (by default all the channels are selected). These parameters are specified for each selected channel:
Channel ID — Hardware channel ID specified by the device. The Channel ID column is read-only, and the parameters are defined when the device is selected.
Name — Channel name. By default
the table displays any names provided by the hardware, but you can
edit the names. For example, if the device is a sound card with two
channels, you can name them
Module — Device ID the channel belongs to. The Module column is read-only. If compactDAQ chassis is selected, it shows the ID of the compactDAQ module which the channel belongs to; otherwise the ID of the device.
Measurement Type — Measurement type of the channel.
Input Range — Input ranges available for each channel supported by the hardware, defined when a device is selected.
Terminal Configuration — Specifies the hardware terminal configuration, such as single-ended, differential, etc. The terminal configuration options are defined by the capabilities of the selected channel.
Coupling — Hardware coupling configuration, such as AC or DC. The coupling type is defined when a device is selected
1 for all channels (default) — Output data from a single port as a matrix, with a size of blocksize by number of channels selected.
1 per channel — Output data from
N ports, where N is equal to the number of selected channels. Each
output port is a column vector with a size of blocksize-by-1. For
naming, each output port uses the channel name if one was specified,
otherwise the channel ID, for example,
The rate at which samples are acquired from the device, in samples per second. This is the sampling rate for the hardware. The sample rate must be a positive real number within the range supported by the selected hardware.
The number of data samples to output at each time step for each channel. It must be a positive integer greater than or equal to 2, within the range supported by the selected hardware.
Select this option to output the relative data timestamps, one for each sample. This option adds a new output port to the block. The data type of this port is double, and corresponds to the time offset in seconds of the sample related to the start of acquisition. For asynchronous acquisition, the acquisition is initiated once at the start of model execution, the relative timestamp is a monotonically-increasing number relative to the start of simulation. For synchronous acquisition, an acquisition is initiated at every time step; as a result, the relative timestamp is reset to zero every time an acquisition is initiated.