|
I am trying to use matlab data acquisition to acquire data from 2
channels on an NI DAQCard-6036E. When I add channels to the ai the
inputs only work if there are 3 or more channels. The inputs are on
HW channels 0 and 1, but if I don't add an empty channel then the
inputs don't work.
The working code is
>> ai = analoginput('nidaq');
>> chan = addchannel(ai,0:2);
>> start(ai)
>> stop(ai)
However, I would like to use 100kHz sampling per channel and the
maximum sampling aggregate is 200kHz, so I have to use only two
channels.
When I use
>> ai = analoginput('nidaq');
>> chan = addchannel(ai,0:1);
>> set(ai,'samplerate',100000);
>> start(ai)
>> stop(ai)
both inputs read either -5V, 0V or +5V steady.
How can I get 100kHz per channel with only two channels?
Full working code follows.
Cheers,
Seth
% clean house
clc
clear all
close all
% delete open daqs
openDAQ = daqfind;
for i = 1:length(openDAQ)
delete(openDAQ(i));
end
% open the daq
ai = analoginput('nidaq');
% add the channels, HW chan 0&1 are the data chans, chan 2 must be
activated as well (for unknown reasons)
chan = addchannel(ai,0:2);
% logdata until 'stop' is issued
set(ai,'samplespertrigger',Inf);
% set sample rate
set(ai,'samplerate',50000); % I need 100k
% set to log to file
set(ai,'loggingmode','disk');
% start data collection
start(ai)
% collect for 4 seconds
pause(4)
% stop data collection
stop(ai)
% tell me when finished
message = 'data aqu finished'
clear message
% set sensitivity
sens = .02; %V/Pa
% get data from log file
file = get(ai,'logfilename');
data = daqread(file);
% apply conversion factor and save channels 1 and 2 (discard channel
3)
data = data(:,[1,2])./sens;
% actual fs is normally different from requested
fs = get(ai,'samplerate');
% skip 1st half second and last half second
skip = round(fs*.5);
datat = data(skip:end-skip,:); % truncated data
% create output file
fout = fopen('outputfile.txt','w');
fprintf(fout,'%f %f\n',[fs fs]);
fprintf(fout,'%f %f\n',datat');
fclose(fout);
% plot the data for verification
plot(datat)
% end script short_data.m
|