Position from two signals Encoder A and B using counters in a session based DAQ
古いコメントを表示
Hi all,
I'm having some trouble getting the position of one tool. This is because the position should be computed from two quadrature signals (encoder A and encoder B), which I wanted to acquire with a NI cDAQ-9178 chassis and a NI 9402 module under Matlab 2012a (7.14, drivers are DAQmx-9.5.1).
The problem is that during the acquisition the second counter 'ctr1' of my session is 0 at anytime while the real signal is correct (I've checked with an oscilloscope). Here is my code :
function MultipleCounterTest
% Getting updated hardware informations
d.Chassis = daq.getVendors;
% Creating measurement session 1
s = daq.createSession(d.Chassis.ID);
% Adding channels to the measurement modules
s.addAnalogInputChannel('cDAQ1Mod2','ai2','Voltage');
s.addCounterInputChannel('cDAQ1Mod4','ctr0','EdgeCount');
s.addCounterInputChannel('cDAQ1Mod4','ctr1','EdgeCount');
s.DurationInSeconds = 1;
s.Rate = 1*1E2;
l = s.addlistener('DataAvailable',@f);
function f(src,event)
hold on;
figure(1);
A = event.Data(:,2);
h = plot(event.TimeStamps,A);
set(h,'Visible','On');
set(gca,'Visible','On');
set(gca,'XLim',[0,s.DurationInSeconds]);
set(gca,'YLim',[-max(A)/5,max(A)*6/5]);
set(h,'LineStyle','-');
set(h,'LineWidth',1);
set(h,'Color','Green');
set(h,'Marker','o');
set(h,'MarkerSize',1.5);
set(h,'MarkerEdgeColor','Green');
set(h,'MarkerFaceColor',[1,1,1]);
hold on;
figure(2);
B = event.Data(:,3);
h = plot(event.TimeStamps,B);
set(h,'Visible','On');
set(gca,'Visible','On');
set(gca,'XLim',[0,s.DurationInSeconds]);
set(gca,'YLim',[-max(B)/5,max(B)*6/5]);
set(h,'LineStyle','-');
set(h,'LineWidth',1);
set(h,'Color','Black');
set(h,'Marker','o');
set(h,'MarkerSize',1.5);
set(h,'MarkerEdgeColor','Black');
set(h,'MarkerFaceColor',[1,1,1]);
hold off;
end
% Executing acquisition
s.startBackground();
s.wait();
% Deleting measurement session
delete(l);
s.stop;
s.release;
end
Is there any way to get both outputs of two counters ('ctr0' ad 'ctr1') from a same module ('cDAQ1Mod4') working in the same session ('s') in matlab with a session based DAQ and without using?
pause(0.1);
s.inputSingleScan();
pause(0.1);
s.inputSingleScan();
Thank you very much, your help would be much appriciated...
Csaba
回答 (1 件)
カテゴリ
ヘルプ センター および File Exchange で Data Acquisition Toolbox Supported Hardware についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!