03-03-2023 07:56 PM
I'm using a cDAQ 9174 chassis, with two modules 1) 9260 analog output and 2) 9215 analog inputs, connected to a Windows PC running Matlab. I can create signals within Matlab, make them play from the 9260 , capture them from the 9215 module, and read them in Matlab (using readwrite.m) . The problem I'm having is that the clocks on the 9215 and 9260 are not exactly synchronized. If for instance I use the maximum sampling rate of 51200 (or any rate for that matter) and create a sine wave with exactly 10 samples per period within Matlab, tie the output to the input on the 9260 and 9215, the measurement on the 9215 shows up in Matlab with not exactly 10 samples per period (might be 9.99 sample per period). This is a problem for a few different reasons. Is there a way to force the clocks on the analog output and input modules to be matched (or slave off of another clock) ? Can I do this within Maltab environment or using the NI Max free software I'm using. I wasn't able to find a way to do this. I'd like to ideally not have to add any other purchased software to do this.
Thanks!
03-04-2023 07:50 AM
Try Acquire Data and Generate Signals Simultaneously - MATLAB & Simulink. This code does not seem to implement any clock configuration. If the input and output are not synchronized, continue the next paragraph.
Due to the fact that NI-9215 uses SAR ADC and NI-9260 uses Delta-Sigma DAC, synchronizing them is a bit challenging. From Signal-based Synchronization of Analog Input C Series Modules with NI-DAQmx in LabVIEW:
Delta Sigma Modules use a 24-bit ADC and convert using a clock internal to the module. Slow Sampled Modules use a 24-bit ADC and convert using an external clock that originates from the CompactDAQ controller or chassis. Lastly, SAR Modules use a Successive Approximation ADC (12- or 16-bit) and convert using an external clock.
The easiest approach here is to force the SAR module to accept the clock from the Delta Sigma Modules. You can try adding
addclock(9215,"ScanClock","External","9260/ao/SampleClock")
to use the AO sample clock of 9260 in 9215. Reference: Add clock connection to device interface - MATLAB addclock
03-05-2023 01:27 PM
Thanks ZYOng for the suggestions. I tried variations of what you suggested, but am still getting errors (see below).
It appears, from the last warning message, that the 9215 analog input module cannot be used for synchronization with my analog output module 9260, which if true would be really disappointing. Any suggestions on what I might want to try next if it is in fact possible to synchronize my output and input module clocks? I'd like to continue to use Matlab to accomplish this. Thanks!
>> dlist = daqlist("ni")
dlist =
2×4 table
DeviceID Description Model DeviceInfo
___________ ________________________________________ _______________ _____________________________
"cDAQ1Mod1" "National Instruments(TM) NI 9260 (BNC)" "NI 9260 (BNC)" [1×1 daq.ni.CompactDAQModule]
"cDAQ1Mod2" "National Instruments(TM) NI 9215 (BNC)" "NI 9215 (BNC)" [1×1 daq.ni.CompactDAQModule]
>> dq = daq("ni");
>> dq.Rate = 51200;
>> ch = addoutput(dq,"cDAQ1Mod1",[0,1],"Voltage"); % both channels
Warning: Added channel does not support on-demand operations: only clocked operations are allowed. % note: this warning is not a problem
>> ch = addinput(dq, "cDAQ1Mod2", [0:3], "Voltage");
>> N = 10000;
>> y = sin(2*pi*0.1*[0:(N-1)]);
>> y = repmat(y',[1,2]);
>> addclock(dq,"ScanClock","cDAQ1Mod1/SyncPulse","cDAQ1Mod2/SyncPulse")
'cDAQ1Mod2' does not have any terminals that can be used for synchronization and clocking.
addclock(dq,"ScanClock","cDAQ1Mod2/SyncPulse","cDAQ1Mod1/SyncPulse")
'cDAQ1Mod2' does not have any terminals that can be used for synchronization and clocking.
>> addclock(dq,"ScanClock","External","cDAQ1Mod1/SyncPulse"); % trying to make the sigma delta DAC slaved to external (chassis?) clock
>> yout = readwrite(dq,y,"OutputFormat","Matrix");
Hardware does not support the specified connection. Check the device user manual for valid device routes and pin-outs.
03-05-2023 09:06 PM
I don't have access to Matlab and am not familiar with the API on Matlab. Perhaps you can try it out in Python. To get started, see Using a NI DAQ Device with Python and NI DAQmx. Then you can try the attached script.
03-06-2023 05:54 AM
I don't really know Python, but ZYong's example looks right to me. I only see one change you *might* need which is to explicitly declare finite sampling mode for the read task, as is done for the write task. But it probably won't be necessary -- in LabVIEW, finite is already the default behavior when not declared explicitly. I tend to expect that to be true with the Python API as well.
-Kevin P