Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Simultaneous AO and AI with NI PCI-6229 MATLAB DAQ toolbox

Hi, All.

 

I need a help, an example of code in MATLAB how to make real-time generator for Analog Output channels and simultaneously and synchronously acquire the data from Analog Input channels for NI DAQ PCI-6229 board. For example: on 1st AO channel I set the sinus wave, on 2nd AO channel I set cosinus wave. On 1st and 2nd AI channels I need to get the input data with the same rate synchronously. And draw all the data (2 AO channels and 2 AI channels) on the same one plot in real-time.

How can I do it?

 

Thank you.

0 Kudos
Message 1 of 6
(4,311 Views)

It looks like you have a few questions about how to use DAQmx in MATLAB®. Take a look at the following link that has multiple examples of how to use the software to interact with your hardware:

 

Acquire Data Using NI Devices: https://www.mathworks.com/help/daq/examples/acquire-data-using-ni-devices.html

 

MATLAB® and Simulink® are registered trademarks of The MathWorks, Inc.

 

Alex C.

Applications Engineering

National Instruments

Alex C.
Applications Engineering
National Instruments
0 Kudos
Message 2 of 6
(4,266 Views)

There are no good examples about real-time AO generator and sycnronization AO and AI channels for NI DAQ board.

0 Kudos
Message 3 of 6
(4,264 Views)

I can outline some general info about the needed task configuration, but I'm no help at all on the specific syntax or limitations/capabilities of the MATLAB DAQ toolbox API.  Would an outline help you or do you already know that and only need the specific syntax details?

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy coming to an end (finally!). Permanent license pricing remains WIP. Tread carefully.
0 Kudos
Message 4 of 6
(4,258 Views)

I have an example of dabs.ni.daqmx wrapper, but I don't have any documentation of this toolchain.
MATLAB code here:

deviceName = 'Dev2';
aiChannelId = 0;
aoChannelId = 0;

%sampleRate = 1e3; % in Hz
sampleRate = 250000; % in Hz

outputWaveform = sin(linspace(0 , 2*pi, 262000));

hTaskAI = dabs.ni.daqmx.Task('Analog Input Task');
hTaskAI.createAIVoltageChan(deviceName, aiChannelId, 'Input channel');

hTaskAO = dabs.ni.daqmx.Task('Analog Output Task');
hTaskAO.createAOVoltageChan(deviceName, aoChannelId, 'Output channel');

hTaskAO.cfgSampClkTiming(sampleRate, 'DAQmx_Val_FiniteSamps', length(outputWaveform));
hTaskAI.cfgSampClkTiming(sampleRate, 'DAQmx_Val_FiniteSamps', length(outputWaveform));
assert(isequal(hTaskAI.sampClkRate, hTaskAO.sampClkRate, sampleRate), 'Sample Rate %fHz is not achievable.', sampleRate);

hTaskAO.disableStartTrig();
hTaskAI.cfgDigEdgeStartTrig(sprintf('/%s/ao/StartTrigger', hTaskAO.deviceNames{1}));

hTaskAO.writeAnalogData(outputWaveform(:));

hTaskAI.start();
hTaskAO.start();

hTaskAI.waitUntilTaskDone(length(outputWaveform)/sampleRate+3);
inputWaveform = hTaskAI.readAnalogData(length(outputWaveform));

hTaskAI.delete();
hTaskAO.delete();

figure();
plot(inputWaveform);
hold on;
plot(outputWaveform);

My question are:
1) How to modify the example and add two AO channels and two AI channels in this code?
2) How to make real-time generator here? Instead predefined wave such as: "outputWaveform = sin(linspace(0 , 2*pi, 262000));"

0 Kudos
Message 5 of 6
(4,247 Views)

Unfortunately, you're going to need to loosen up some of your apparent requirements. In a non-real-time OS and a standard MIO board, low-latency AO calculation & generation can pretty much only be done "on-demand" using software timing.  AI and AO synchronization can only be done with buffered tasks and hardware timing.  You'll have to pick which is more important.

 

In LabVIEW, AI or AO channels are designated with a string which can contain lists or ranges of channels.  The MATLAB code you posted appears to expect a scalar numeric value, but perhaps it would also accept an array of numeric channel numbers?  Just a guess.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy coming to an end (finally!). Permanent license pricing remains WIP. Tread carefully.
0 Kudos
Message 6 of 6
(4,237 Views)