Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Acquiring and Generating Data at the Same Time with Digilent® Analog Discovery™

This example will show you how to synchronously generate and acquire voltage data (at a rate of 300 KHz). You will use the session-based interface with Digilent Analog Discovery hardware.

Create a session with a Digilent device

Discover Digilent devices connected to your system using daq.getDevices and create a session using the listed Digilent device.

s = daq.createSession('digilent')
s = 

Data acquisition session using Digilent Inc. hardware:
   Will run for 1 second (10000 scans) at 10000 scans/second.
   No channels have been added.
   

Add an analog output channel

Add an analog output channel with device ID AD1 and channel ID 1. Set the measurement type to Voltage.

ch_out = s.addAnalogOutputChannel('AD1', 1, 'Voltage')
ch_out = 

Data acquisition analog output voltage channel '1' on device 'AD1':

 TerminalConfig: SingleEnded
          Range: -5.0 to +5.0 Volts
           Name: ''
             ID: '1'
         Device: [1x1 daq.di.DeviceInfo]
MeasurementType: 'Voltage'


Add an analog input channel

Add an analog input channel with device ID AD1 and channel ID 1. Set the measurement type to Voltage.

ch_in = s.addAnalogInputChannel('AD1', 1, 'Voltage')
ch_in = 

Data acquisition analog input voltage channel '1' on device 'AD1':

       Coupling: DC
 TerminalConfig: Differential
          Range: -25 to +25 Volts
           Name: ''
             ID: '1'
         Device: [1x1 daq.di.DeviceInfo]
MeasurementType: 'Voltage'


Set session and channel properties

Set the generation rate (300kHz).

rate = 300e3;
s.Rate = rate;

Define the output waveform

Generate a 10 Hz sine-wave for 1 second.

f = 10;
duration = 1;
t = (1:(duration*rate))/rate;
output = sin(2*pi*f*t)';

Generate / Acquire continuous data

Generate queued data and acquire timestamped data in the foreground. For any given session, generation and acquisition run at the same rate.

s.queueOutputData(output);
[data, timestamps, triggerTime] = s.startForeground;

Display the results

plot(timestamps, data);
xlabel('Time (seconds)'); ylabel('Voltage (Volts)');
title(['Clocked Data Triggered on: ' datestr(triggerTime)])

Was this topic helpful?