how to output continuous signal using usb6008

1 次查看(过去 30 天)
i need your help to use ni usb6008 to output analog signal , the continuous signal is the control signal from PID controller, i used timer but i don't why it isn't working i used this code
% %%get connected devices
d = daq.getDevices
%create session
s = daq.createSession('ni')
s1= daq.createSession('ni')
%add analog channel s.addAnalogInputChannel('ID',channel num, 'measurement type')
% s.addAnalogInputChannel('Dev1',0:3, 'Voltage')%irradiance
s.addAnalogInputChannel('Dev1','ai0', 'Voltage')%irradiance
s.addAnalogInputChannel('Dev1','ai1', 'Voltage')%Temperature
s.addAnalogInputChannel('Dev1','ai2', 'Voltage')%current
s.addAnalogInputChannel('Dev1','ai3', 'Voltage')%voltage
% s.addAnalogInputChannel('Dev1','ai3', 'Voltage')%Temperature
%set(s.Channels,'InputType','SingleEnded')
%set(s.Channels,'Range',[-10 10])
%s.addAnalogInputChannel('Dev1','ai6', 'Voltage')%Temperature
AO=s1.addAnalogOutputChannel('Dev1', 'ao0', 'Voltage')
% set rate of scan 1000 scans/second , run for 30 seconds
s.Rate=1000;
s.DurationInSeconds =10
v.TerminalConfig = ' Differential';
%v.TerminalConfig = ' SingleEnded';
%_____________________________
%aquire data and process
lh = s.addlistener('DataAvailable', @plotData);
%store data
%h = s.addlistener('DataAvailable', @storedata);
% Analog Output
% duty cycle control signal x amplification
%for i=1:5
e= 18 - Vref
%end
IE=sum(e); %Integral of Error
% C = pid(20,10,0,'InputName','e','OutputName','u') % calculate control signal of pid
u=C*er
for i=1:length(u)
t = timer('TimerFcn', ' putsample(AO,u)',...
'StartDelay',0.2);
start(t)
end
s.startBackground()
s.wait()
delete (lh)
s.release()
it gives me error message
Error while evaluating TimerFcn for timer 'timer-1840'
Undefined function 'putsample' for input arguments of type 'daq.ni.AnalogOutputVoltageChannel

回答(2 个)

Walter Roberson
Walter Roberson 2014-3-24
putsample() is only for the legacy interface.
  4 个评论
mado
mado 2014-3-24
in other questions i used singlescan but i want to output control signal which can't be one value , is there any solution ?is it available or should i switch back to legacy interface?

请先登录,再进行评论。


Julian
Julian 2016-11-4
Ok, this answer is quite late, and not only focused on your actual code, but as I had a similar question just a short time ago, here's my answer:
The NI-USB6008 doesn't support clocked operations. That means you must trigger by yourself when you want to output a signal. If the need of real continuity and speed are not too important you can use a loop or something like that. If you really like to output continuously, it's better to use a DAQ Device that supports Hardware Triggering. Then you can pre-buffer your signals, can controll the output rate etc., in the background or in the foreground.

类别

Help CenterFile Exchange 中查找有关 Digital Input and Output 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by