From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Simultaneous generation of output from 2 NI USB-6258; external trigger?

For about a year now I've been running Matlab scripts that use their Data Acquisition toolbox to interface with a NI USB-6259 NIDAQ to generate and collect multiple analog signals simultaneously with great results. Typically the signals are about 5 seconds long, I collect 3 signals with a A to D rate of 40 kHz, and generate 3 or 4 signals with a D to A rate of 200 kHz.

 

The application I'm prepairing for now is similar in those regards, however it requires that I generate up to 6 output signals. However the 6259 only has 4 outputs so I hooked up a second 6259 to my same PC. I added Matlab code to configure the second NIDAQ and changed my trigger command from "trigger([ai ao])" to "trigger([ai ao1 ao2])". This seems to work but when I send the same (digital Matlab) signal to a AO port on each NIDAQ and examine these 2 ports on a oscope I see that they are not synchronous but there's a delay between the 2. This delay seems to vary from run to run (a run being each time they are triggered) to as high as 4 or ms. If I querry Matlab for the actual trigger times after a run it consistantly reports times within 20-60 us of each other.

 

Is this much delay after a Manual trigger normal for a 6259. Is there any way to improve this?

 

I read in Matlab's help that NI devices support external TTL triggers so I configured a Matlab script for this but couldn't get it to work. I'm generating a 1 Hz TTL signal and tried feeding it to various ports on the 6259 but nothing seemed to cause the trigger.

 

So, does the 6259 support external triggering? Should it solve my delay problem? If so, how does it work?

 

A manual would probably help, but I couldn't find one with any good info about what the ports are, how they work, how triggering works, etc. on this site or on the CD that came with the device.

 

Thanks much for any help you can give me!

0 Kudos
Message 1 of 7
(3,386 Views)

Hi John,

You'll need to output the Start Trigger and/or the sample clock to a PFI line on one 6259 and wire that to a PFI line on the other 6259. Then use this input as the respective Start Trigger or Sample Clock for the second DAQ device.

 

If you're not already using it, I recommend using NI-DAQmx Tools, available here: http://zone.ni.com/devzone/cda/tut/p/id/3005. It provides major advantages including examples.

PBear
NI RF
0 Kudos
Message 2 of 7
(3,370 Views)

Hi John,

 

What you're doing should work fine.  Can you post the code that's setting up the analog output objects -- maybe we can see what's going wrong.

 

-Rob

-----
Rob Purser
Manager, Test and Measurement
MathWorks
rob.purser@mathworks.com
0 Kudos
Message 3 of 7
(3,359 Views)

Hi John,

 

ADE aside, you'll need to at least output a sample clock from one device and use it as the external clock on the other. The reason being is that starting both tasks in software doesn't ensure synchronization and I full well expect a variation in time on each run of your program because of this. There needs to be an actual hardware clock correlation on the device side of the USB chain. USB is highly latent in nature and nondeterministic so two software calls doesn't guarantee the same response time. So setting up the tasks on the devices and having one being driven by the clock from the other will ensure synchronization because one will be a 'master' and one will be a 'slave,' waiting for the master to start. When the master does start, the slave, which will already be armed, will begin generation upon receiving the clock from the master and each sample will be generated at the same time.

 

With NI's newest release of LabVIEW 8.6, the Mathscript node is highly improved. This allows you to use existing m files you've already created and leverage the easy to use DAQmx API graphically in LabVIEW. If this sounds of interest to you, give LabVIEW an evaluation at ni.com/labview/try/daq.htm.

Message Edited by PBear on 10-09-2008 11:50 AM
PBear
NI RF
0 Kudos
Message 4 of 7
(3,343 Views)

PBear,

 

Thanks for all the info. After looking more closely I may need to lock the sample clocks like I think you're suggesting in addition to the trigger, and I like your idea of a master/slave approach sounds the cleanest/easiest/best. I am still not clear how to do this, I should be able to figure it out with some playing, but again: is there a good manual on how to use the 6258 available anywhere? Of course I mean one that includes where to get the trigger and sample clock and where/how to provide them externally.

 

Rob,

 

Thanks much for the helpful offer. Here's a simple test script for this:

 

% dual_nidaq_test.m

% Gererate a simple signal and send it to AO0 on each of 2 NIDAQ devices.

 

clear all

 

% generate the test signal

fs = 50e3;

sig_len_secs = 5;

freq_change_rate = 10;
% sort of like a baud rate

 

sig_len_samps = sig_len_secs*fs;

t = (0:sig_len_samps-1)'/fs;

 

f_list = 800/3 * ( 1 + mod(0:ceil(freq_change_rate*sig_len_secs),3));

f_inst = f_list(floor(freq_change_rate*t)+1)';

sig_out = 2 * cos(2*pi*cumsum(f_inst)/fs);

 

% configure the 2 nidaqs

[ao1, ao2, ai, Vout, Vin, fs_out, fs_in] = nidaq2_config(1, 1, ...

1, fs/1e3, fs/2e3, 10, 10, 'Memory');

 

% play it 99 times or until ctrl-C is hit

for k=1:99disp('press any key to run the nidaqs')

pause

disp('key pressed, about to start the nidaq')

nidaq_insig = nidaq2_run(ao1, ao2, ai, [sig_out sig_out], .02);

end

0 Kudos
Message 5 of 7
(3,330 Views)

And here are the functions that I normally use, called by the above script:

 

function [ao1, ao2, ai, Vout, Vin, fs_out, fs_in] = nidaq2_config(num_chan_out1, num_chan_out2, ...
    num_chan_in, DtoA_Rate_kHz, AtoD_Rate_kHz, Vout_max, Vin_max, logmode)
% This function configures 2 NI-DAQ units for operation. For now we have 2
% NI USB-6259 units, but this function should support any 2 - the only
% assumption made here is that the second NIDAQ can have its Vout and DtoA
% rate set to the values used by the first.
% All inputs must go to the first NIDAQ - typically it handles far more
% than enough channels.
% NOTE that this function only truly supports the logmode of 'Memory' since if 'Disk' or
% 'Disk&Memory' is used the LogFileName used is always set to:
fixed_file_name = 'NIDAQ_collected_data.dat';

% define DAQ device ID
Dev1 = 'Dev1';       % DAQ device ID
Dev2 = 'Dev2';       % DAQ device ID

% check AO and AI devices
%error(nidaq_devchk(Dev1,{'ai' 'ao'}));
%error(nidaq_devchk(Dev2,{'ai' 'ao'}));

% construct Output and Input Objects
ai = analoginput('nidaq',Dev1);
ao1 = analogoutput('nidaq',Dev1);
ao2 = analogoutput('nidaq',Dev2);

% add channels to each object
for k = 1:num_chan_out1;
    out_chan_names1{k} = strcat('AO',num2str(k-1));
end
addchannel(ao1, 0:num_chan_out1-1, out_chan_names1);
for k = 1:num_chan_out2;
    out_chan_names2{k} = strcat('AO',num2str(k-1));
end
addchannel(ao2, 0:num_chan_out2-1, out_chan_names2);
for k = 1:num_chan_in;
    in_chan_names{k} = strcat('AI',num2str(k-1));
end
addchannel(ai, 0:num_chan_in-1, in_chan_names);

% configure each subsystem
set([ai ao1 ao2],'TriggerType','Manual');
set(ai,'ManualTriggerHwOn','Trigger');
set(ai,'LoggingMode', logmode);
set(ai,'LogFileName', fixed_file_name);

set(ao1.Channel,'OutputRange',[-Vout_max Vout_max]);
Vout = get(ao1.Channel,'OutputRange');
if num_chan_out1 > 1
    Vout = Vout{1};
end
set(ao1.Channel,'UnitsRange',Vout);

set(ao2.Channel,'OutputRange',[-Vout_max Vout_max]);
set(ao2.Channel,'UnitsRange',Vout);

set(ai.Channel,'InputRange',[-Vin_max Vin_max]);
Vin = get(ai.Channel,'InputRange');
if num_chan_in > 1
    Vin = Vin{1};
end
set(ai.Channel,'UnitsRange',Vin,'SensorRange',Vin);

% Set the D/A and A/D rates on the NIDAQ to get the actual values
fs_out = setverify(ao1, 'SampleRate', DtoA_Rate_kHz*1e3);
fs_out = setverify(ao2, 'SampleRate', DtoA_Rate_kHz*1e3);
fs_in = setverify(ai, 'SampleRate', AtoD_Rate_kHz*1e3);

 

and

 

function nidaq_insig = nidaq2_run(ao1, ao2, ai, nidaq_outsig, collect_dur_extra)
% Sends the first columns of nidaq_outsig to the output channels defined in ao1 and
% the next columns as needed to fill ao2, while collecting nidaq_insig on ai.
% Output signals are padded with collect_dur_extra seconds/2 worth of zeros in
% front, and collection is performed for the duration of nidaq_outsig plus an extra
% collect_dur_extra seconds worth of samples.

wait_mult = 5;  % how many input signal durations to wait for the nidaq to notify
% that it has finsished collecting before giving up and triggering an error.

% get sample rate and number of channels (in and out) from inputs
fs_out = ao1.SampleRate;
fs_in = ai.SampleRate;
[num_samps_out,out_chans] = size(nidaq_outsig); % or set out_chans using ao
out_chans1 = length(ao1.channel);
out_chans2 = length(ao2.channel);

num_samps_in = round((num_samps_out/fs_out + collect_dur_extra)*fs_in);
outsig1 = [zeros(round(collect_dur_extra/2*fs_out),out_chans1); nidaq_outsig(:,1:out_chans1); zeros(1, out_chans1)];
outsig2 = [zeros(round(collect_dur_extra/2*fs_out),out_chans2); nidaq_outsig(:, out_chans1+1:out_chans1+out_chans2); zeros(1, out_chans2)];

set(ai,'SamplesPerTrigger',num_samps_in);

putdata(ao1, outsig1);   %Queue output data
putdata(ao2, outsig2);   %Queue output data

try
    start([ai ao1 ao2]);    % Start the timers running
    trigger([ai ao1 ao2]);  % Manually initiate logging & sending
    wait(ai, wait_mult*num_samps_in/fs_in);
    nidaq_insig = getdata(ai);
catch
    stop([ai ao1 ao2]);
    rethrow(lasterror);
end
stop([ai ao1 ao2]);   % Stop DAQ

 

0 Kudos
Message 6 of 7
(3,329 Views)
Take a look at the options for 'TriggerType' -- you likely want 'HwDigital'.  You can then set which pin to use using HwDigitalTriggerSource, and use the technique outlined earlier (use a Digitial Output to start all three subsystems at once).

 Doc at http://www.mathworks.com/access/helpdesk/help/toolbox/daq/daq.html

-Rob
-----
Rob Purser
Manager, Test and Measurement
MathWorks
rob.purser@mathworks.com
0 Kudos
Message 7 of 7
(3,320 Views)