Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

daq process usb-6008

Asked by mado on 18 Aug 2013

how to acquire data from this code to process it in another operation in realtime

    % get connected devices
   d = daq.getDevices
   %create session 
    s = daq.createSession('ni')
    %add analog channel  s.addAnalogInputChannel('ID',channel num, 'measurement type')
   s.addAnalogInputChannel('Dev1',0, 'Voltage')
      % set rate of scan  4 scans/second ,  run for 3 seconds
   s.Rate=1000;
   s.DurationInSeconds=30;
v= s.Channels(1);
set(v)
%_____________________________
%%
v.TerminalConfig = ' Differential';
v.Coupling = ' DC';
%%
%start continuous aquisition and plot
h = s.addlistener('DataAvailable', @(src,event) plot(event.TimeStamps, event.Data/.001));
s.NotifyWhenDataAvailableExceeds = 200;
s.startBackground()

0 Comments

mado

Tags

2 Answers

Answer by Walter Roberson on 18 Aug 2013

The line

h = s.addlistener('DataAvailable', @(src,event) plot(event.TimeStamps, event.Data/.001));

creates the (anonymous) callback function that will be called when data is available; in this case the data is plotted. You would change that line to do whatever processing you needed.

17 Comments

Walter Roberson on 20 Aug 2013

Could you show your current code that tries to use single-ended ?

mado on 21 Aug 2013

just i changed differential to SingleEnded

    %%get connected devices
   d = daq.getDevices
   %create session 
    s = daq.createSession('ni')
    %add analog channel  s.addAnalogInputChannel('ID',channel num, 'measurement type')
    s.addAnalogInputChannel('Dev1',0, 'Voltage')
% set rate of scan  4 scans/second ,  run for 3 seconds
 s.Rate=1000;
 s.DurationInSeconds=30;
v= s.Channels(1);
set(v)
%_____________________________
%%
v.TerminalConfig = ' SingleEnded';
v.Coupling = ' DC';
%%
%start continuous aquisition and plot
h = s.addlistener('DataAvailable', @(src,event) plot(event.TimeStamps, event.Data));
s.NotifyWhenDataAvailableExceeds = 200;
s.startBackground()
 s.wait()
delete (h)
h = s.addlistener('DataAvailable', @storedata);s.NotifyWhenDataAvailableExceeds = 200;
s.startBackground()
global matrix_index
global matrix_data
matrix_data(1:matrix_index)
Walter Roberson on 21 Aug 2013

As complete speculation: is it possible that you need channel 1 instead of channel 0 for your single ended measurement ?

Walter Roberson
Answer by mado on 21 Aug 2013

I need to use both of channel 0 and 1 , will it make a difference ?

3 Comments

Walter Roberson on 21 Aug 2013

Looking at http://www.tau.ac.il/~electro/pdf_files/computer/ni_6008_ADC_manual.pdf

Could you have a look at page 7 and verify your wiring? Differential 0 uses pins 2 and 3, diff 1 uses pins 5 and 6, diff 2 uses pins 8 and 9, diff 3 uses pins 11 and 12; Single ended 0 is pin 2, SE 1 is pin 5, SE 2 is pin 8, SE 3 is pin 11, SE 4 is pin 3, SE 5 is pin 6, SE 6 is pin 9, SE 7 is pin 12.

mado on 21 Aug 2013

ok, i know that Analog Input Channels 0 to 7—For single-ended measurements, each signal is an analog input voltage channel. For differential measurements, AI 0 and AI 4 are the positive and negative inputs of differential analog input channel 0. The following signal pairs also form differential input channels: <AI 1, AI 5>, <AI 2, AI 6>, and <AI 3,AI 7>.

how to verify writing , i think it's written right

Walter Roberson on 21 Aug 2013

If you have checked your wiring, then I suggest you open a case with MATLAB technical support. I do not have the software or equipment to go further on this myself.

mado

Contact us