<< Appx., HDF5 Format >> Appx., MonkeyLogic Graphics Library ^ Top

# NIMH DAQ Toolbox

##
1. Introduction

NIMH DAQ Toolbox (NIMH DAQ) is a pacakge of MATLAB scripts and mex binaries that enable MATLAB to acquire digital samples or generate analog/TTL output through data acquisition hardware. There is MATLAB's own Data Acquisition Toolbox (MATLAB DAQ) for this purpose already, but MATLAB DAQ does not support its legacy interface on 64-bit MATLAB nor in the releases later than R2015b. NIMH DAQ is developed to extend the legacy interface to 64-bit MATLAB and continue to support it in the latest version of MATLAB so that users can keep running mission-critical codes written with the legacy DAQ interface.

NIMH DAQ includes some improvements in DAQ functions to support near-realtime behavior monitoring and stimulation that are required in neuroscience research. For example, it does not require two DAQ boards to compensate long sample update intervals in MATLAB DAQ. For the details of the improvements, see this PDF document and Hwang et al. (2019).

##
2. Supported devices

- National Instruments multifunction I/O device
- Sound card
- Parallel port
- Touchscreen (MonkeyLogic Graphics Library required)
- USB joystick
- TCP/IP eye tracker
- Keyboard
- Mouse
- Webcam
- Serial port

For those devices that do not have a sample clock (NI digital input, parallel port, touchscreen, USB joystick, TCP/IP eye tracker, keyboard, mouse), NIMH DAQ performs millisecond-resolution data acquisition based on a software timer.

##
3. Installation

NIMH DAQ is included in NIMH ML and not distributed as a separate package. Copy the daqtoolbox directory from the NIMH ML package and add it to the MATLAB path. Install additional libraries as explained in this manual page.

##
4. Usage

NIMH DAQ is made compatible with the legacy interface of MATLAB DAQ Toolbox, although not all the functions are implemented. Basic commands are shown below. There are more example scripts in the daqtoolbox\examples directory.

1. Hardware Discovery
2. Analog Input
3. Analog Output
4. Digital Input/Output

##
1. Hardware Discovery

###
1. Find all installed adapters

`>> devices = daqhwinfo >> devices.InstalledAdaptors ans = 2×1 cell array {'nidaq' } {'winsound'}`

###
2. Information about an installed adapter

`>> ni = daqhwinfo('nidaq') ans = struct with fields: AdaptorName: 'nidaq' BoardNames: {'PCIe-6323'} InstalledBoardIds: {'Dev1'} ObjectConstructorName: {1×3 cell}`

###
3. Information about a particular device

`>> ai = analoginput('nidaq','Dev1') >> daqhwinfo('ai') ans = struct with fields: AdaptorName: 'nidaq' Bits: 16 Coupling: {'DC'} DeviceName: 'PCIe-6323' DifferentialIDs: [0 1 2 3 4 5 6 7 16 17 18 19 20 21 22 23] ...`

##
2. Analog Input

###
1. Create an analog input object

`>> ai = analoginput('nidaq','Dev1'); >> addchannel(ai,0:1);`

###
2. Acquire a single sample

`>> getsample(ai)`

###
3. Acquire continuous samples

`>> ai.SampleRate = 1000; >> ai.SamplesPerTrigger = 1000; % Or Inf, which requires calling stop(ai) to stop acquisition >> start(ai); % Acquisition wiil stop after 1 s automatically >> data = peekdata(ai); % Preview data without actually retrieving >> data = getdata(ai); % Retrieve data`

###
4. Triggered sampling

`>> ai.TriggerType = 'manual'; >> start(ai); % Hardware is ready, but acquisition is not started yet
>> trigger(ai); % Triggered acquisition begins faster
`

##
3. Analog Output

###
1. Create an analog output object

`>> ao = analogoutput('nidaq','Dev1'); >> addchannel(ao,0);`

###
2. Send out a single sample

`>> putsample(ao,5)`

###
3. Generate a waveform

`>> ao.SampleRate = 1000; >> putdata(ao,sind(linspace(0,360,1000))'); % Load a waveform >> start(ao); % Start generation`

###
4. Triggered generation

`>> ao.TriggerType = 'manual'; >> putdata(ao,sind(linspace(0,360,1000))'); >> start(ao) % Hardware is ready, but generation is not started yet >> trigger(ao); % Triggered generation begins faster`

##
4. Digital Input/Output

###
1. Create a digital I/O object

`>> di = digitalio('nidaq','Dev1'); >> addline(di,0:3,0,'in'); % Add Line 0-3 of Port 0 for input >> do = digitalio('nidaq','Dev1'); >> addline(do,4:7,0,'out'); % Add Line 4-7 of Port 0 for output`

###
2. Read a value

`>> getvalue(di)`

###
3. Write a value

`>> putvalue(do,12) >> putvalue(do,[0 0 1 1]) % The same operation as the above line`

The National Institute of Mental Health (NIMH) is part of the National Institutes of Health (NIH), a component of the U.S. Department of Health and Human Services.

- Freedom of Information Act
- HHS Vulnerability Disclosure

- National Institute of Mental Health
- National Institutes of Health
- U.S. Department of Health and Human Services
- USA.gov