National Instruments 6002 Analog Write not outputing last 1000 entries

6 vues (au cours des 30 derniers jours)
Vanden
Vanden le 21 Jan 2024
Réponse apportée : Aditya le 26 Juin 2024
Hello,
I am attempting to output an analog signal on a national instruments 6002 DAQ where the last 1000 entries of what I am outputting are not being outputted by the DAQ. I am using the code that matlab provided with minor modifications (though the issue still occurs without these changes). When the number of entries is >1000, the final 1000 entries seem to be cut off, when it is <=1000, the output is garbuled (see picture below). This issue seems to happen no matter which computer I use or if I change the rate.
%% Generate Voltage Signals Using NI Devices
%
% This example shows how to generate data using a National Instruments
% device.
% Copyright 2010-2019 The MathWorks, Inc.
%% Discover Devices That Can Output Voltage
% To discover a device that supports analog outputs, access the device in
% the table returned by the |daqlist| command. This example uses an NI 9263
% module in National Instruments(R) CompactDAQ Chassis NI cDAQ-9178. This
% is module 2 in the chassis.
d = daqlist("ni")
%%
%deviceInfo = d{2, "DeviceInfo"}
%% Create a DataAcquisition and Add Analog Output Channels
% Create a DataAcquisition, set the generation scan rate by setting the
% |Rate| property (the default is 1000 scans per second), and add analog
% output channels using |addoutput|.
dq = daq("ni");
dq.Rate = 1000;
addoutput(dq, "Dev1", "ao0", "Voltage");
addoutput(dq, "Dev1", "ao1", "Voltage");
%% Generate a Single Scan
% Use |write| to generate a single scan (2 V on each channel). The output
% scan data is a 1-by-N matrix where N corresponds to the number of output
% channels.
output = 2;
write(dq,[output output]);
%% Create and Plot the Output Data
% Generate two output signals (a 1 Hz sine wave and a 1 Hz ramp) and plot them.
% The plot depicts the data generated on both channels for a device that
% supports simultaneous sampling.
n = dq.Rate;
outputSignal1 = sin(linspace(0,2*pi,n)');
outputSignal2 = linspace(-1,1,n)';
outputSignal = [outputSignal1 outputSignal2];
plot(1:n, outputSignal);
ylabel("Voltage (V)");
legend("Analog Output 0", "Analog Output 1");
%% Write Data
% Use |write| to generate the output waveforms.
while(1)
write(dq, outputSignal)
end
Output cut off when >1000 (rate set to 2000, this should be a full sin wave but is instead a half sin wave):
Output when <=1000(rate set to 1000, again should be a full sin wave):
Any help would be greatly appreciated.
  1 commentaire
Vanden
Vanden le 21 Jan 2024
I was able to come up with a solution, but it is not optimal.
I appended 1000 0's to the end of list of entries (the small break between the sin waves is due to delays related to matlab).
This however does not seem like the proper solution.

Connectez-vous pour commenter.

Réponses (1)

Aditya
Aditya le 26 Juin 2024
t looks like you're encountering issues with the output of your National Instruments (NI) 6002 DAQ when trying to generate analog signals. There are a few potential reasons for the behavior you're observing, including buffer size limitations, improper handling of the write operation, or device-specific constraints.
Here are some steps to troubleshoot and potentially resolve the issue:
1. Check Buffer Size and Configuration: Ensure the buffer size is large enough to handle the data you're sending. You can configure the buffer size using the preload function in the DataAcquisition object.
2. Use Continuous Output Mode: For continuous output, you should configure the session to continuously generate data. This involves setting up a listener for the DataRequired event to continuously feed data to the DAQ.
3. Avoid Blocking the Main Thread: Ensure that the main thread is not blocked, which can cause issues with data output. Use event listeners and callbacks to handle continuous data generation.
4. Error Handling and Logging: Add error handling and logging to capture any errors or warnings that might provide more insight into the issue.
Example Code for continuous output:
%% Discover Devices That Can Output Voltage
d = daqlist("ni");
%% Create a DataAcquisition and Add Analog Output Channels
dq = daq("ni");
dq.Rate = 1000;
addoutput(dq, "Dev1", "ao0", "Voltage");
addoutput(dq, "Dev1", "ao1", "Voltage");
%% Create and Plot the Output Data
n = dq.Rate;
outputSignal1 = sin(linspace(0, 2*pi, n)');
outputSignal2 = linspace(-1, 1, n)';
outputSignal = [outputSignal1 outputSignal2];
%% Preload Data to Buffer
preload(dq, outputSignal);
%% Set Up Continuous Output
dq.ScansQueuedFcn = @(src, event) preload(src, outputSignal); % Refill buffer when empty
%% Start Continuous Output
start(dq, "Continuous");
%% Run for a Specified Duration
pause(10); % Run for 10 seconds
%% Stop Output
stop(dq);

Catégories

En savoir plus sur Data Acquisition Toolbox Supported Hardware dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by