how to output continuous signal using usb6008
Show older comments
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
Answers (2)
Walter Roberson
on 24 Mar 2014
0 votes
putsample() is only for the legacy interface.
4 Comments
mado
on 24 Mar 2014
Walter Roberson
on 24 Mar 2014
Don't use putsample().
It appears to me that if you do not use putsample() then the matter becomes the same as you have already asked in one of your other questions and so should be resolved there instead of here.
mado
on 24 Mar 2014
Walter Roberson
on 24 Mar 2014
I will have to look at this later.
Julian
on 4 Nov 2016
0 votes
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.
Categories
Find more on Data Acquisition Toolbox 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!