Thread Subject: NI Daq Initialization

Subject: NI Daq Initialization

From: Seth Gilchrist

Date: 3 Jul, 2007 19:37:09

Message: 1 of 6

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

Subject: NI Daq Initialization

From: Rob Purser

Date: 5 Jul, 2007 11:39:45

Message: 2 of 6

Hi,

Are you running single ended or differential?

-Rob


Subject: NI Daq Initialization

From: Seth Gilchrist

Date: 5 Jul, 2007 12:06:15

Message: 3 of 6

Rob Purser wrote:
>
>
> Hi,
>
> Are you running single ended or differential?
>
> -Rob
>
>

I am using differential. The full setup is below. thanks, Seth.

>> daqhwinfo(ai)
ans =
                AdaptorName: 'nidaq'
                       Bits: 16
                   Coupling: {'DC'}
                 DeviceName: 'DAQCard-6036E'
            DifferentialIDs: [0 1 2 3 4 5 6 7]
                      Gains: [0.50000000000000 1 10 100]
                         ID: '1'
                InputRanges: [4x2 double]
              MaxSampleRate: 200000
              MinSampleRate: 0.00600000000000
             NativeDataType: 'int16'
                   Polarity: {'Bipolar'}
                 SampleType: 'Scanning'
             SingleEndedIDs: [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]
              SubsystemType: 'AnalogInput'
              TotalChannels: 16
    VendorDriverDescription: 'National Instruments Data Acquisition
Driver'
        VendorDriverVersion: '7.4.1'

>> get(ai)
        BufferingConfig = [64 30]
        BufferingMode = Auto
        Channel = [0x1 aichannel]
        ChannelSkew = 5e-006
        ChannelSkewMode = Minimum
        ClockSource = Internal
        DataMissedFcn = @daqcallback
        EventLog = []
        InitialTriggerTime = [0 0 0 0 0 0]
        InputOverRangeFcn =
        InputType = Differential
        LogFileName = logfile.daq
        Logging = Off
        LoggingMode = Memory
        LogToDiskMode = Overwrite
        ManualTriggerHwOn = Start
        Name = nidaq1-AI
        Running = Off
        RuntimeErrorFcn = @daqcallback
        SampleRate = 1000
        SamplesAcquired = 0
        SamplesAcquiredFcn =
        SamplesAcquiredFcnCount = 1024
        SamplesAvailable = 0
        SamplesPerTrigger = 1000
        StartFcn =
        StopFcn =
        Tag =
        Timeout = 1
        TimerFcn =
        TimerPeriod = 0.1
        TriggerChannel = [1x0 aichannel]
        TriggerCondition = None
        TriggerConditionValue = 0
        TriggerDelay = 0
        TriggerDelayUnits = Seconds
        TriggerFcn =
        TriggerRepeat = 0
        TriggersExecuted = 0
        TriggerType = Immediate
        Type = Analog Input
        UserData = []

        NIDAQ specific properties:
        DriveAISenseToGround = Off
        ExternalSampleClockSource = PFI2
        ExternalScanClockSource = PFI7
        HwDigitalTriggerSource = PFI0
        NumMuxBoards = 0
        TransferMode = Interrupts

Subject: NI Daq Initialization

From: Rob Purser

Date: 6 Jul, 2007 19:20:50

Message: 4 of 6

What version of MATLAB?

I don't know of any reason that you should see this behavior. Check to see if you see similar results in Measurement and Automation Explorer. You might also consider moving from Traditional NI-DAQ to NI-DAQmx. We added support in R2006a. Current version of NI-DAQmx is 8.5.

One thing you can do is post the results of the command DAQSUPPORT, and that might offer some insights.

-Rob

Subject: NI Daq Initialization

From: Seth Gilchrist

Date: 9 Jul, 2007 18:15:42

Message: 5 of 6

Rob Purser wrote:
>
>
> What version of MATLAB?
>
> I don't know of any reason that you should see this behavior.
> Check to see if you see similar results in Measurement and
> Automation Explorer. You might also consider moving from
> Traditional NI-DAQ to NI-DAQmx. We added support in R2006a.
> Current version of NI-DAQmx is 8.5.
>
> One thing you can do is post the results of the command DAQSUPPORT,
> and that might offer some insights.
>
> -Rob
>

Rob,
Here is the result of 'daqsupport', as written to 'daqtest.txt':

Operating System:
Microsoft Windows XP [Version 5.1.2600]

MATLAB version:
7.0.0.19920 (R14)

Data Acquisition Toolbox version:
       Name: 'Data Acquisition Toolbox'
    Version: '2.5'
    Release: '(R14)'
       Date: '05-May-2004'

----------MATLAB root directory: ----------
C:\MATLAB7

----------MATLAB path: ----------

MATLABPATH

C:\MATLAB7\toolbox\daq\daq
C:\MATLAB7\toolbox\daq\daqguis
C:\MATLAB7\toolbox\daq\daqdemos
C:\MATLAB7\work

----------Testing nidaq adaptor for:----------

----------Registering adaptor: nidaq----------

Successfully registered nidaq adaptor

----------Available hardware: ----------

          ToolboxName: 'Data Acquisition Toolbox'
       ToolboxVersion: '2.5 (R14)'
        MATLABVersion: '7.0 (R14)'
    InstalledAdaptors: {3x1 cell}

----------Toolbox Version: ----------

2.5 (R14)

----------Adaptor Information for adaptor nidaq----------

adaptorInfo =
           AdaptorDllName:
'C:\MATLAB7\toolbox\daq\daq\private\mwnidaq.dll'
        AdaptorDllVersion: '2.5 (R14)'
              AdaptorName: 'nidaq'
               BoardNames: {'DAQCard-6036E'}
        InstalledBoardIds: {'1'}
    ObjectConstructorName: {'analoginput('nidaq',1)'
'analogoutput('nidaq',1)' [1x20 char]}

----------Adaptor DLL Name----------

C:\MATLAB7\toolbox\daq\daq\private\mwnidaq.dll

----------Adaptor Name----------

nidaq

----------Object Constructor Name ----------

analoginput('nidaq',1)

----------Object Constructor Name ----------

analogoutput('nidaq',1)

----------Object Constructor Name ----------

digitalio('nidaq',1)

----------Creating analoginput object for adaptor nidaq----------
ans =
                AdaptorName: 'nidaq'
                       Bits: 16
                   Coupling: {'DC'}
                 DeviceName: 'DAQCard-6036E'
            DifferentialIDs: [0 1 2 3 4 5 6 7]
                      Gains: [0.50000000000000 1 10 100]
                         ID: '1'
                InputRanges: [4x2 double]
              MaxSampleRate: 200000
              MinSampleRate: 0.00600000000000
             NativeDataType: 'int16'
                   Polarity: {'Bipolar'}
                 SampleType: 'Scanning'
             SingleEndedIDs: [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]
              SubsystemType: 'AnalogInput'
              TotalChannels: 16
    VendorDriverDescription: 'National Instruments Data Acquisition
Driver'
        VendorDriverVersion: '7.4.4'

----------Creating analogoutput object for adaptor nidaq----------
ans =
                AdaptorName: 'nidaq'
                       Bits: 16
                 ChannelIDs: [0 1]
                   Coupling: {'DC'}
                 DeviceName: 'DAQCard-6036E'
                         ID: '1'
              MaxSampleRate: 10000
              MinSampleRate: 0.00600000000000
             NativeDataType: 'int16'
               OutputRanges: [-10 10]
                   Polarity: {'Bipolar'}
                 SampleType: 'SimultaneousSample'
              SubsystemType: 'AnalogOutput'
              TotalChannels: 2
    VendorDriverDescription: 'National Instruments Data Acquisition
Driver'
        VendorDriverVersion: '7.4.4'

----------Creating digitalio object for adaptor nidaq----------
ans =
                AdaptorName: 'nidaq'
                 DeviceName: 'DAQCard-6036E'
                         ID: '1'
                       Port: [1x1 struct]
              SubsystemType: 'DigitalIO'
                 TotalLines: 8
    VendorDriverDescription: 'National Instruments Data Acquisition
Driver'
        VendorDriverVersion: '7.4.4'

----------Testing parallel adaptor for:----------

----------Registering adaptor: parallel----------

Successfully registered parallel adaptor

----------Available hardware: ----------

          ToolboxName: 'Data Acquisition Toolbox'
       ToolboxVersion: '2.5 (R14)'
        MATLABVersion: '7.0 (R14)'
    InstalledAdaptors: {3x1 cell}

----------Toolbox Version: ----------

2.5 (R14)

----------Adaptor Information for adaptor parallel----------

adaptorInfo =
           AdaptorDllName:
'C:\MATLAB7\toolbox\daq\daq\private\mwparallel.dll'
        AdaptorDllVersion: '2.5 (R14)'
              AdaptorName: 'parallel'
               BoardNames: {'PC Parallel Port Hardware'}
        InstalledBoardIds: {'LPT1'}
    ObjectConstructorName: {'' '' 'digitalio('parallel','LPT1')'}

----------Adaptor DLL Name----------

C:\MATLAB7\toolbox\daq\daq\private\mwparallel.dll

----------Adaptor Name----------

parallel

----------Object Constructor Name ----------

----------Object Constructor Name ----------

----------Object Constructor Name ----------

digitalio('parallel','LPT1')

----------Creating digitalio object for adaptor parallel----------
ans =
                AdaptorName: 'parallel'
                 DeviceName: 'PC Parallel Port Hardware'
                         ID: 'LPT1'
                       Port: [1x3 struct]
              SubsystemType: 'DigitalIO'
                 TotalLines: 17
    VendorDriverDescription: 'Win I/O'
        VendorDriverVersion: '1.3'

----------Testing winsound adaptor for:----------

----------Registering adaptor: winsound----------

Successfully registered winsound adaptor

----------Available hardware: ----------

          ToolboxName: 'Data Acquisition Toolbox'
       ToolboxVersion: '2.5 (R14)'
        MATLABVersion: '7.0 (R14)'
    InstalledAdaptors: {3x1 cell}

----------Toolbox Version: ----------

2.5 (R14)

----------Adaptor Information for adaptor winsound----------

adaptorInfo =
           AdaptorDllName:
'C:\MATLAB7\toolbox\daq\daq\private\mwwinsound.dll'
        AdaptorDllVersion: '2.5 (R14)'
              AdaptorName: 'winsound'
               BoardNames: {'SoundMAX Digital Audio'}
        InstalledBoardIds: {'0'}
    ObjectConstructorName: {'analoginput('winsound',0)'
'analogoutput('winsound',0)' ''}

----------Adaptor DLL Name----------

C:\MATLAB7\toolbox\daq\daq\private\mwwinsound.dll

----------Adaptor Name----------

winsound

----------Object Constructor Name ----------

analoginput('winsound',0)

----------Object Constructor Name ----------

analogoutput('winsound',0)

----------Object Constructor Name ----------

----------Creating analoginput object for adaptor winsound----------
ans =
                AdaptorName: 'winsound'
                       Bits: 16
                   Coupling: {'AC Coupled'}
                 DeviceName: 'SoundMAX Digital Audio'
            DifferentialIDs: []
                      Gains: []
                         ID: '0'
                InputRanges: [-1 1]
              MaxSampleRate: 44100
              MinSampleRate: 8000
             NativeDataType: 'int16'
                   Polarity: {'Bipolar'}
                 SampleType: 'SimultaneousSample'
             SingleEndedIDs: [1 2]
              SubsystemType: 'AnalogInput'
              TotalChannels: 2
    VendorDriverDescription: 'Windows Multimedia Driver'
        VendorDriverVersion: '1.0'

----------Creating analogoutput object for adaptor winsound----------
ans =
                AdaptorName: 'winsound'
                       Bits: 16
                 ChannelIDs: [1 2]
                   Coupling: {'AC Coupled'}
                 DeviceName: 'SoundMAX Digital Audio'
                         ID: '0'
              MaxSampleRate: 44100
              MinSampleRate: 8000
             NativeDataType: 'int16'
               OutputRanges: [-1 1]
                   Polarity: {'Bipolar'}
                 SampleType: 'SimultaneousSample'
              SubsystemType: 'AnalogOutput'
              TotalChannels: 2
    VendorDriverDescription: 'Windows Multimedia Driver'
        VendorDriverVersion: '1.0'

--------------------End test--------------------

This information has been saved in the text file:
daqtest.txt

If any errors occurred, please e-mail this information to:
support@mathworks.com

Subject: NI Daq Initialization

From: Rob Purser

Date: 10 Jul, 2007 15:44:48

Message: 6 of 6

Hi,

There have been a lot of changes and improvements to Data Acquisition Toolbox (and MATLAB) since the R14 release. We've added support for the current NI API, NI-DAQmx, and added support for a lot of new hardware, like the M-series devices. You really should consider updating to the current release of Data Acquisition Toolbox and NI-DAQ, which would likely address the issue you're seeing.

-Rob

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
data acquistion Rob Purser 5 Jul, 2007 07:40:52
hardware Rob Purser 5 Jul, 2007 07:40:52
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com