Multiple channel Data Acquistion - NI USB-6251 & BNC-2090

13 views (last 30 days)
Hello, I'm trying to write an m-file using only a couple of channels (triggering off 1 channel) on the NI hardware captioned above to collect voltage. However, after I add channels, specify which channel is the trigger and other parameters, run the program and get data, my plots only reflect data from the trigger channel. I've tried pulling only certain columns out to see the individual channels, but it didn't work. What am I doing wrong or not including in my script?
Also, any advice on the best way to trigger using this hardware configuration would be appreciated.
  2 Comments
Sean de Wolski
Sean de Wolski on 22 Aug 2011
Can you show us the script so we can see what you're not including !
Greg
Greg on 22 Aug 2011
Edited: Walter Roberson on 5 Aug 2020
Sure, this is the setup & script I have so far.
Setup:
Voltage Source---Ch0-NI Board/NI DAQ--\______[Computer/Matlab]
Trigger----------Ch1-NI Board/NI DAQ--/
Script:
%Add Channels from DAQ device to program
ai = analoginput ('nidaq','Dev1');
chan = addchannel (ai,0:1);
%Set DAQ Parameters (property values)
set(ai,'SampleRate', 500000); %Value in Hz
set(ai,'SamplesPerTrigger', 2.5e6); %No. of Samples
set(ai,'TriggerChannel',chan(1)); %Choose trigger channel
set(ai,'TriggerType','software'); %Choose trigger type
set(ai,'TriggerCondition','rising'); %Select how trigger initiates
set(ai,'TriggerConditionValue',0.01);%Choose voltage value for trigger to initiate
set(ai,'Timeout',5); %Time in sec for program to wait for trigger start
%Start Data Acq, plot, stop.
start (ai);
wait(ai,6)
[data,time] = getdata(ai);
trigger = data(:,2);
vout = data(:,1);
subplot(2,1,1),plot (time,vout);
subplot(2,1,2),plot (time,trigger);
title('Voltage Data');
xlabel('Time (s)');
ylabel('Voltage (V)');
stop (ai);

Sign in to comment.

Answers (1)

Chirag Gupta
Chirag Gupta on 22 Aug 2011
Greg from your code, it seems that:
ai = analoginput ('nidaq','Dev1');
chan = addchannel (ai,0:1);
%Set DAQ Parameters (property values)
set(ai,'SampleRate', 500000); %Value in Hz
set(ai,'SamplesPerTrigger', 2.5e6); %No. of Samples
set(ai,'TriggerChannel',chan(1)); %Choose trigger channel
set(ai,'TriggerType','software'); %Choose trigger type
set(ai,'TriggerCondition','rising'); %Select how trigger initiates
set(ai,'TriggerConditionValue',0.01);%Choose voltage value for trigger to initiate
set(ai,'Timeout',5); %Time in sec for program to wait for trigger start
%Start Data Acq, plot, stop.
start (ai);
wait(ai,6)
[data,time] = getdata(ai);
trigger = data(:,2);
vout = data(:,1);
You have assigned ai channel 0 as the trigger channel. Even though the NI channels start from zero, MATLAB index is 1 based. So I think, the code should be:
set(ai,'TriggerChannel',chan(2)); % Corresponds to ai channel 1

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!