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

조회 수: 8 (최근 30일)
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
Lorena Santamaria
Lorena Santamaria 2022년 12월 14일
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 2022년 12월 14일
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);

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Instrument Connection and Communication에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by