how to output continuous signal using usb6008
1 view (last 30 days)
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
0 Comments
Answers (2)
Julian
on 4 Nov 2016
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.
0 Comments
See Also
Categories
Find more on Digital Input and Output 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!