ADLM1000 Write to Buffer Downsample then append to file
2 views (last 30 days)
Show older comments
Hello,
I have an ADLM1000, which is truely a remarkable piece of hardware. The only challenge I have with it is that it records at 100kHz which is too much data for me. I'd like to read from it into a buffer downsample to 100Hz and then append the downsampled values (with timestamps) to a file.
When I run the code below I get the error: "ADALM1000 background operations do not support generation or finite acquisition." Can anyone think of a workaround?
Thank you,
-Matt
%% Start the DAQ session
clear ADISession
close all
daqlist("adi");
ADISession = daq("adi");
addoutput(ADISession, 'SMU1','a','Current');
addinput(ADISession, 'SMU1','a','Voltage');
%addinput(ADISession, 'smu1','b','Voltage');
ADISession.ScansAvailableFcnCount = 10000; % set the scans available to fire 100 times per second Samples at 100kHz so this function will be called every 1000 points or 100 times/second
%% Chrono Ampometry Sequence
fs = ADISession.Rate; % Sampling rate for chronoampometry
Current = 0.0002; % Amps for constant current up to 200mA
Duration = 5; % Time to record in seconds
T_Chrono = 0:1/fs:Duration;
A_Chrono = ones(1,fs*Duration)*Current;
StartTime = datestr(now,'yyyy-mm-dd_HHMM');
File = strcat('Chrono_',StartTime,'.mat');
Chrono_exp_resample = [];
save(File,'Chrono_exp_resample','-v7.3');
File_Obj = matfile(File,'Writable',true);
ADISession.ScansAvailableFcn = @(src,evt) AverageAndSave(src,evt);
start(ADISession, "Duration",Duration)
write(ADISession,A_Chrono')
while ADISession.Running
pause(0.5)
fprintF("While loop: Scans acquired = %d\n", ADISession.NumScansAcquired);
end
%% Close Down the DAQ
clear ADISession
close all
%% Functions at the end!
function AverageAndSave(src,~)
Chrono = read(src,src.ScansAvailableFcnCount);
Chrono_exp = retime(Chrono,'regular','mean','SampleRate',100);
File_Obj.Chrono_exp_resample = [File_Obj.Chrono_exp_resample, Chrono_exp];
end
%% Notes
%https://au.mathworks.com/help/matlab/import_export/load-parts-of-variables-from-mat-files.html
%https://au.mathworks.com/help/daq/acquire-continuous-and-background-data-using-ni-devices.html
0 Comments
Answers (0)
See Also
Categories
Find more on Analog Data Acquisition in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!