Measurement Computing   Easy to Use | Easy to Integrate | Easy to Support catalog banner

Simple Analog Input Acquisition Using a MCC USB-1408FS and MATLAB...

Expand / Collapse

Simple Analog Input Acquisition Using a MCC USB-1408FS and MATLAB R2017a

After successfully configuring a Windows system to use a MCC USB-1408FS module with MATLAB R2017a (reference KB article -, the following lines were used in a .m script to acquire and display data of an analog input signal.  

% Begin by creating a session.
s = daq.createSession('mcc');

% Add an analog input channel from device ID (Board0) and channel ID (Ai0), 
% with the measurement type set to ‘Voltage’.
ch0 = addAnalogInputChannel(s,'Board0', 'Ai0', 'Voltage');

% Configure input channel properties 
% (Verify module’s user guide for supported capabilities.) 
ch0.TerminalConfig = 'SingleEnded'; % 'Differential'
ch0.Range = [-10,10];

% Set the acquisition rate (Hz).
s.Rate = 10000;

% Set the input event handler by adding a listener for ‘DataAvailable’ events.
% The callback function plots the acquired data against time.
lh = addlistener(s,'DataAvailable', @(src,event) plot(event.TimeStamps, event.Data));

% Set the acquisition to run continuously in the background for a specified duration.
s.IsContinuous = true;
durationInSeconds = 3;
localTimer = tic;
while s.IsRunning && toc(localTimer) < durationInSeconds
    fprintf('Scans Acquired = %d\n', s.ScansAcquired)

% Cleanup

% Delete the listener.
delete (s)

*NOTE: This script works with a USB-1208FS, USB-1208FS-Plus, USB-1408FS-Plus, and a USB-1608FS-Plus.  Additional modules may also work or require minimal code changes to acquire and display data.

Rate this Article:

Add Your Comments

For comments email

Article ID: 50723

Last Modified:9/19/2017 2:30:49 PM

Article has been viewed 1,832 times.