Salta al contenuto
Note per Studenti Lab 6 - Interaction with DAQ Modules Report

Lab 6 - Interaction with DAQ Modules

Background on DAQ modules (multiplexer, ADC, trigger, input configurations): Data Acquisition SystemsA DAQ module multiplexes several analog inputs through a programmable gain amplifier into one ADC, stores the samples in a buffer and hands them to a PC, with sampling timing, trigger modes (digital, analog level, window, pre-trigger) and input configuration (differential or referred to ground) that the user must know.Data Acquisition Systems →. RC filters: Lab 4 - RC FiltersLaboratory activity on first-order RC filters: build low-pass, high-pass and band-pass circuits with R of 1 kOhm or 10 kOhm and C of 100 nF, compute the cutoff frequency 1/(2 pi R C), and measure gain and phase with the oscilloscope for sinusoidal, square and triangular inputs.Lab 4 - RC Filters →. Matlab sampling and quantisation: Lab 5 - ADC with MatlabMatlab laboratory that simulates an acquisition chain step by step: generate a sinusoid, sample it at a chosen frequency, quantise it with a uniform rounding quantiser (step V_FS/2^Nbit with saturation), estimate the RMS value from N samples, add Gaussian noise for a chosen SNR and check it with snr().Lab 5 - ADC with Matlab →.

Part 1 - Signal acquisition through DAQ modules

Tools

  • National Instruments MyDAQ module
  • Keysight MSOX3024T digital oscilloscope
  • Keysight 33600A signal generator

Aim and connection

Acquire a signal coming from the generator through the DAQ module. The connecting cable must have a coaxial connector on the generator side and a two-wire termination on the opposite side. To get the signal, use one of the Input lines of the DAQ module (an AI x input).

The MyDAQ is programmed with the functions of the Matlab Data Acquisition Toolbox. These functions interact with the software called Data acquisition engine, which in turn interacts with the hardware devices of the module. Information on the toolbox: Matlab help, via the command help daq.

Steps

1. Check that a DAQ module is present and recognised. Type in the Command Window:

matlab
daq.getDevices

It lists the devices present and their identification code, with the entries index, Vendor, Device ID and Description.

2. Create a session, the software object through which the interface with the Data acquisition engine is managed:

matlab
s = daq.createSession('ni');

The string 'ni' identifies the manufacturer of the hardware to be controlled ('ni' = National Instruments, as in the Vendor entry of the list); s is the variable identifying the session (the handle) and can be chosen freely.

3. Set the sampling rate, which is associated with the session:

matlab
s.Rate = Fs;

Fs is the sampling frequency expressed in Hz.

4. Define the channel. After creating the session, define the set of physical lines involved and their characteristics. The signal from the generator must be connected to the prepared AI x input. In the script define the channel, of the "input" type:

matlab
ch = addAnalogInputChannel(s, deviceName, channelID, measurementType);
  • s: handle of the session;
  • deviceName: string identifying the device (the DAQ module), the Device ID reported by daq.getDevices;
  • channelID: the channel used, for example '0' (or 'ai0') refers to analog input AI0;
  • measurementType: the measured quantity.

Example on the sheet:

matlab
ch = addAnalogInputChannel(s, 'Dev1', 'ai2', 'Voltage');

It associates the device 'Dev1' (identifier obtained from daq.getDevices) to session s; 'ai2' is AI2, the input whose terminals are connected to the generator; 'Voltage' means the acquired signal is a voltage.

5. Configure the input channel. Alternatives: 'SingleEnded', 'SingleEndedNonReferenced', 'Differential' and 'PseudoDifferential'. If the configuration is not specified, the measurement is differential (difference between the two channels). If the acquired voltage is measured as a potential difference with respect to the ground reference (using the AI SN terminal as reference), the 'SingleEnded' or 'Differential' type must be explicitly indicated, with:

matlab
ch.InputType = 'Differential';

(The two measurement schemes, differential and referred to ground, are explained in Data Acquisition SystemsA DAQ module multiplexes several analog inputs through a programmable gain amplifier into one ADC, stores the samples in a buffer and hands them to a PC, with sampling timing, trigger modes (digital, analog level, window, pre-trigger) and input configuration (differential or referred to ground) that the user must know.Data Acquisition Systems →.)

6. Set the acquisition duration, chosen carefully according to the sampling frequency and the signal to be collected:

matlab
s.DurationInSeconds = Tw;

7. Start the acquisition and store the data in a vector (name freely chosen):

matlab
data = startForeground(s);

8. Time axis and plot. To have the correct time reference, create a time axis depending on the sampling frequency and the number of samples; then show the result with figure and plot as usual.

Part 2 - Signal generation and acquisition using the MyDAQ

Objective

Use the NI MyDAQ not only to acquire but also to generate a sinusoidal waveform through one of its Analog Output (AO) lines. The generated signal is applied to a passive RC filter assembled on a breadboard; the filter output is acquired again through the DAQ module and displayed in Matlab together with the original generated waveform.

The activity allows to:

  • generate test signals directly in Matlab;
  • apply signals to simple analog circuits;
  • acquire and visualise the input-output behaviour of an RC filter;
  • verify the expected frequency response of first-order passive networks.

Required tools

  • National Instruments MyDAQ module
  • Breadboard and components for a first-order RC filter
  • Matlab with Data Acquisition Toolbox
  • USB cable and connection wires

Generating a sinusoidal signal with Matlab

The MyDAQ has two analog output channels, AO0 and AO1, controlled from Matlab with daq.createSession('ni'). After creating the session an analog output channel is added and the waveform is generated in Matlab as a voltage vector.

Sampling frequency and duration (example values from the sheet):

matlab
Fs = 100000;
Tw = 1;

Signal features (amplitude and frequency):

matlab
A = 2;
f_test = 2000;

Session creation:

matlab
s = daq.createSession('ni');
s.Rate = Fs;
s.DurationInSeconds = Tw;
addAnalogOutputChannel(s, 'Dev1', 'ao0', 'Voltage');

Remember that 'Dev1' must be changed to the ID of your DAQ.

Sinusoid of amplitude AA and frequency ff:

matlab
t = (0:1/Fs:Tw)';
inputSignal = A * sin(2*pi*f_test*t);

Send it to the DAQ output:

matlab
queueOutputData(s, inputSignal);

The waveform is now present on the physical pins of the AO0 output.

Assembling the RC filter

Assemble a simple first-order RC filter on the breadboard.

  • Low-pass: Input -> RR -> Node, and CC from the node to ground.
  • High-pass: Input -> CC -> Node, and RR from the node to ground.

The AO0 output is connected to the filter input; the filter output node is connected to analog input AI0. The ground of the DAQ must be shared with the breadboard ground.

 AO0 ----[ R ]----+----> AI0          (low-pass)
                  |
                [ C ]
                  |
 DAQ GND ---------+---- breadboard ground

The sheet gives no component values for this exercise (see Lab 4 - RC FiltersLaboratory activity on first-order RC filters: build low-pass, high-pass and band-pass circuits with R of 1 kOhm or 10 kOhm and C of 100 nF, compute the cutoff frequency 1/(2 pi R C), and measure gain and phase with the oscilloscope for sinusoidal, square and triangular inputs.Lab 4 - RC Filters → for the cutoff formula fc=1/(2πRC)f_c = 1/(2\pi RC) with the values used in that laboratory).

Acquiring the filter output

For simultaneous generation and acquisition, an analog input channel is added to the same session:

matlab
chIn = addAnalogInputChannel(s, 'Dev1', 'ai0', 'Voltage');
chIn.InputType = 'Differential';

Using a single session ensures synchronous timing between input and output. The acquisition:

matlab
[data, tStamps] = s.startForeground();

Visualising the results

Plot the generated input and the filter output versus time:

matlab
figure;
plot(t, inputSignal, 'LineWidth', 1.2); hold on;
plot(t, data(:,1), 'LineWidth', 1.2);
xlabel('Time [s]');
ylabel('Voltage [V]');
legend('Generated input', 'Filter output');
grid on;

Observation (from the sheet's own numbers, not stated by the sheet): with Fs = 100000 and Tw = 1, the vector t = (0:1/Fs:Tw)' has FsTW+1=100001F_s T_W + 1 = 100001 elements; plot needs vectors of equal length, so check that the length of data(:,1) matches t (the sheet also returns tStamps from startForeground, which could be used as the time axis).

Versione ripasso

  • Setup (Part 1): NI MyDAQ, Keysight MSOX3024T oscilloscope, Keysight 33600A generator; cable with a coaxial connector on the generator side, two-wire on the DAQ side, to an AI x input.
  • Toolbox: Matlab Data Acquisition Toolbox (help daq) talks to the Data acquisition engine, which talks to the hardware.
  • Command sequence for acquisition:
    1. daq.getDevices (index, Vendor, Device ID, Description);
    2. s = daq.createSession('ni'); (handle s);
    3. s.Rate = Fs; (Hz);
    4. ch = addAnalogInputChannel(s, 'Dev1', 'ai2', 'Voltage'); (device ID from the list, channel, quantity);
    5. ch.InputType = 'Differential'; (alternatives 'SingleEnded', 'SingleEndedNonReferenced', 'PseudoDifferential'; default is differential);
    6. s.DurationInSeconds = Tw;
    7. data = startForeground(s); then build the time axis from Fs and the number of samples, figure, plot.
  • Generation (Part 2): MyDAQ has AO0 and AO1. addAnalogOutputChannel(s, 'Dev1', 'ao0', 'Voltage'); t = (0:1/Fs:Tw)'; inputSignal = A * sin(2*pi*f_test*t); queueOutputData(s, inputSignal); Example values: Fs = 100000, Tw = 1, A = 2, f_test = 2000.
  • RC test: low-pass (R in series, C to ground) or high-pass (C in series, R to ground); AO0 to filter input, filter output to AI0; share the DAQ ground with the breadboard ground.
  • Simultaneous generation and acquisition: add chIn = addAnalogInputChannel(s, 'Dev1', 'ai0', 'Voltage'); to the same session (synchronous timing), then [data, tStamps] = s.startForeground(); and plot inputSignal and data(:,1) with labels, legend and grid on.
  • Typical errors: wrong 'Dev1' (must match daq.getDevices); forgetting the shared ground; mismatching input type (differential vs single-ended); choosing Tw and Fs that give too few periods or aliasing; vector length mismatch in plot.

Teoria collegata