MATLAB Programming Example for U22351A USB Modular Data Acquisition (DAQ) module’s Analog Ouput

8 views (last 30 days)
I am trying to set up a DAQ with an arbritrary (custom) signal but as the daq toolbox is not supported any more, I need to use the instrument control toolbox with IVI components, which I am struggling with. Any advice will be great, my attempt is as follows.
addpath(genpath(toolboxdir('instrument'))); %intrument control toolbox pathway
% Connect steps: Use icdevice with the MATLAB instrument driver name and instrument's resource name to create a device object.
if (exist('KtU23xx_ivic.mdd','file') == 0)
makemid('KtU23xx', 'KtU23xx_ivic.mdd', 'ivi-c');
end
U2351A = icdevice('KtU23xx_ivic', 'USB0::0x0957::0x0F18::TW62020521::0::INSTR');
connect(U2351A);
% now the parameters for the output
U2351A.Instrumentspecificanalogoutgeneration.Mode = 1; % (1 is arbitrary signal)
U2351A.Instrumentspecificanalogoutarbitrary.SampleRate = 10000;
U2351A.Instrumentspecificanalogoutarbitrary.NumberOfStreams = -1; %continuous adquisition
U2351A.Instrumentspecificanalogoutgeneration.TriggerMode = 0; %no wait for trigger
invoke(U2351A.Instrumentspecificanalogout, 'analogoutsetpolarity', 'AOut1', 2); % AOut1 is the output analog channel and 2 is bipolar (+-10V).
invoke(U2351A.Instrumentspecificanalogout, 'analogoutsetreferencesource', 'AOut1', 1); % KTU23XX_VAL_OUTPUT_REFERENCE_INTERNAL = 1
invoke(U2351A.Instrumentspecificanalogout, 'analogoutsetenabled', 'AOut1', 1);
count=100; % silly example
while count
[ReturnCount] = invoke(U2351A.System, 'viwrite', 200, dat(count)); % dat is the signal I want to send
count=count-1
end
% stop
invoke(U2351A.Instrumentspecificanalogoutgeneration, 'analogoutgenerationstop');
% Cleanup
disconnect(U2351A);
delete(U2351A);
I am pretty sure I am missing something very obvious but I am cannot see it....
  4 Comments
Lorena Santamaria
Lorena Santamaria on 14 Dec 2022
Thank you @Mario Malic for your help!
I am trying to avoid the older version option as this will be for a EEG closed-loop stimulation so I prefer using more updated versions to avoid other problems but if I can't make it work I will definetly go for it!
Thanks a lot.
Lorena Santamaria
Lorena Santamaria on 14 Dec 2022
I managed to use a system generated signal (sinusoid) if this helps anyone else although not success with a custom signal yet...
% initial declarations
addpath(genpath(toolboxdir('instrument'))); %intrument control box pathway
% Connect steps: Use icdevice with the MATLAB instrument driver name and instrument's
% resource name to create a device object.
if (exist('KtU23xx_ivic.mdd','file') == 0)
makemid('KtU23xx', 'KtU23xx_ivic.mdd', 'ivi-c');
end
U2351A = icdevice('KtU23xx_ivic', 'USB0::0x0957::0x0F18::TW62020521::0::INSTR');
connect(U2351A);
%% Commands to prepare signal and channels
U2351A.Instrumentspecificanalogoutgeneration.Mode = 2; % waveform signal (1 is arbitrary and 2 a specific signal)
U2351A.Instrumentspecificanalogoutgeneration.TriggerMode = 0; %no wait for trigger
% commands for the signal
invoke(U2351A.Instrumentspecificanalogout, 'analogoutsetpolarity', 'AOut1', 2); % KTU23XX_VAL_ANALOG_POLARITY_BIPOLAR = 2
invoke(U2351A.Instrumentspecificanalogout, 'analogoutsetreferencesource', 'AOut1', 1); % KTU23XX_VAL_OUTPUT_REFERENCE_INTERNAL = 1
invoke(U2351A.Instrumentspecificanalogout, 'analogoutsetenabled', 'AOut1', 1);
invoke(U2351A.Instrumentspecificanalogoutwaveform, 'analogoutwaveformconfigure', 'AOut1', 1, 11, 0.3, 0); % SINE = 1 /freq/amplitude/offset
% everything ready to go
invoke(U2351A.Instrumentspecificanalogoutgeneration, 'analogoutgenerationstart');
%% writing output
count=1000;
while count
ReturnCount = invoke(U2351A.System, 'viwrite', 200, 200); % write it on the device
count=count-1
end
% stop
invoke(U2351A.Instrumentspecificanalogoutgeneration, 'analogoutgenerationstop');
% Cleanup
disconnect(U2351A);
delete(U2351A);

Sign in to comment.

Answers (0)

Categories

Find more on Instrument Connection and Communication in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!