Main Content

Acquire Data from Two Devices at Different Rates

This example shows how to acquire data from two different DAQ devices running at different sampling rates. The example uses two National Instruments CompactDAQ analog input modules (9201 and 9211) that have different acquisition rate limits. The 9211 module is used for temperature measurements and acquires at a slower rate (10 Hz) than the 9201 module, which is used to measure voltage (100 Hz). Since all channels in a data acquisition object must acquire at the same rate, to acquire from two modules at multiple rates you need to use two data acquisition objects. To make both DAQ devices start simultaneously, you can use a hardware digital triggering configuration.

Hardware Setup

  • CompactDAQ chassis NI cDAQ 9178 ('cDAQ1')

  • NI cDAQ 9211 module with thermocouple measurement type ('cDAQ1Mod1')

  • NI cDAQ 9201 module with voltage measurement type ('cDAQ1Mod2')

  • Thermocouple probe (type K)

  • Analog voltage signal generated by a function generator instrument

Configure Data Acquisition Objects and Channels

Create two data acquisition objects, each with one analog input channel from a 9211 module or 9201 module. The data acquisition objects acquire data at rates of 10 Hz and 100 Hz, respectively.

% Specify a common acquisition duration for both devices, in seconds
daqDuration = seconds(3);

% Create and configure DataAcquisition object and channels for cDAQ 9211 module
d1 = daq('ni');
addinput(d1, 'cDAQ1Mod1', 'ai0', 'Thermocouple');
d1.Channels(1).ThermocoupleType = 'K';
d1.Rate = 10;
Warning: The Rate property was reduced to 14.2857 due to changes in the channel
% Create and configure DataAcquisition object and channels for cDAQ 9201 module
d2 = daq('ni');
addinput(d2, 'cDAQ1Mod2', 'ai0', 'Voltage');
d2.Rate = 100;

Configure Trigger Connections

To synchronize the acquisition start you can use hardware triggering and a source/destination approach. One of the data acquisition objects (source) is started manually and triggers the acquisition start of the other data acquisition object (destination).

Note: If you have a CompactDAQ chassis model (such as NI 9174) which does not have PFI triggering terminals, you can use an additional digital I/O module (such as NI 9402) to provide the PFI terminals for the trigger connections.

% Configure the source data acquisition object to export a triggering
% signal on the PFI0 terminal of cDAQ1 chassis
addtrigger(d1, 'Digital', 'StartTrigger', 'cDAQ1/PFI0', 'External');

% Configure the destination data acquisition object to start acquisition when an
% external triggering signal is received at PFI0 terminal of cDAQ1 chassis
addtrigger(d2, 'Digital', 'StartTrigger', 'External', 'cDAQ1/PFI0');

Start Acquisition and Wait Until Complete

The destination data acquisition object must start first and be ready for an external trigger before the source data acquisition object starts.

start(d2, 'Duration', daqDuration)
while ~d2.WaitingForDigitalTrigger
start(d1, 'Duration', daqDuration)

% Wait until data acquisition is complete
while d1.Running || d2.Running
Background operation has started.
Background operation will stop after 3 s.
To read acquired scans, use read.
Background operation has started.
Background operation will stop after 3 s.
To read acquired scans, use read.

Save Data as Timetable

For each data acquisition object, the acquired measurement data and timestamps were stored in memory. Read all acquired data from memory in the default timetable format.

data1 = read(d1, 'all');
data2 = read(d2, 'all');

Plot Acquired Data

Because the acquired data from the two devices have different scales and units, create a chart with two y-axes.

yyaxis left
plot(data1.Time, data1.Variables, '-x')
ylabel('Temperature (deg. C)')
ylim([0 50])
yyaxis right
plot(data2.Time, data2.Variables, '-o')
ylabel('Voltage (V)')
xlabel('Time (s)')

Clean Up

Clear the data acquisition objects to disconnect from hardware.

clear d1 d2