필터 지우기
필터 지우기

Position from two signals Encoder A and B using counters in a session based DAQ

조회 수: 2 (최근 30일)
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
  댓글 수: 2
Csaba
Csaba 2012년 5월 9일
I've also checked the following links without much success, because each time only one counter ('ctr0') is used :
http://www.mathworks.ch/products/daq/demos.html?file=/products/demos/shipping/daq/demo_countertimer_countingpulses.html
http://www.mathworks.it/matlabcentral/answers/6258-nidaq-continuous-and-background-acquisition
http://www.mathworks.it/matlabcentral/newsreader/view_thread/313543
Manisha
Manisha 2012년 5월 9일
Does inputSingleScan give you the correct answer? Also do you only get all zeros with startForeground also?

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

답변 (1개)

Csaba
Csaba 2012년 5월 10일
I also tried to dispatch the counter sessions in two different sessions like this :
function DispatchingCounterTest
ClearWorkspace();
AddBreakpoint('DispatchingCounterTest',0);
global Time;
global Data;
persistent NumberOfCall;
if not(exist('NumberOfCall','var')) || isempty(NumberOfCall)
NumberOfCall = 0;
Time.Stamps = [];
Data.A = [];
Data.B = [];
Data.C = [];
Data.F = [];
end
% Getting updated hardware informations
d.Chassis = daq.getVendors;
d.Modules = daq.getDevices;
% Creating measurement session 1
s = daq.createSession(d.Chassis.ID);
t = daq.createSession(d.Chassis.ID);
% Adding channels to the measurement modules
s.addAnalogInputChannel('cDAQ1Mod1','ai0','Voltage');
s.addCounterInputChannel('cDAQ1Mod4','ctr0','EdgeCount');
set(s,'DurationInSeconds',10);
set(s,'Rate',100);
t.addAnalogInputChannel('cDAQ1Mod2','ai2','Voltage');
t.addCounterInputChannel('cDAQ1Mod4','ctr1','EdgeCount');
set(t,'DurationInSeconds',get(s,'DurationInSeconds'));
set(t,'Rate',get(s,'Rate'));
l = s.addlistener('DataAvailable',@f);
m = t.addlistener('DataAvailable',@f);
function f(src,event)
hold on;
if(strcmpi(src.Channels(1,1).Device.ID,'cDAQ1Mod1'))
disp(strcat('ctr0 called at',32,datestr(now,'HH:MM:SS.FFF')));
Color = 'Black';
Time.Stamps = [Time.Stamps;event.TimeStamps];
Data.C = [Data.C;event.Data(:,1)];
Data.A = [Data.A;event.Data(:,2)];
else
disp(strcat('ctr1 called at',32,datestr(now,'HH:MM:SS.FFF')));
Color = 'Green';
Data.F = [Data.F;event.Data(:,1)];
Data.B = [Data.B;event.Data(:,2)];
end
Handle = plot(event.TimeStamps,event.Data);
set(Handle,'Visible','On');
set(gca,'Visible','On');
set(Handle,'LineStyle','-');
set(Handle,'LineWidth',1);
set(Handle,'Color',Color);
set(Handle,'Marker','o');
set(Handle,'MarkerSize',0.5);
set(Handle,'MarkerEdgeColor',Color);
set(Handle,'MarkerFaceColor',[0,0,0]);
end
% Executing acquisition
t.startBackground();
s.startBackground();
s.wait();
% Plotting data
figure(2);
hold on;
Data.A = (Data.A-Data.A(1))*333.4721;
h = plot(Time.Stamps,Data.A);
set(h,'Visible','On');
set(gca,'Visible','On');
set(gca,'XLim',[0,t.DurationInSeconds]);
set(gca,'YLim',[-max(Data.A)/5,max(Data.A)*6/5]);
set(h,'LineStyle','-');
set(h,'LineWidth',1);
set(h,'Color','Green');
set(h,'Marker','o');
set(h,'MarkerSize',0.5);
set(h,'MarkerEdgeColor','Green');
set(h,'MarkerFaceColor',[1,1,1]);
% Plotting data
h = plot(Data.B);
set(h,'Visible','On');
set(gca,'Visible','On');
set(gca,'XLim',[0,t.DurationInSeconds]);
set(h,'LineStyle','-');
set(h,'LineWidth',1);
set(h,'Color','Red');
set(h,'Marker','o');
set(h,'MarkerSize',0.5);
set(h,'MarkerEdgeColor','Red');
set(h,'MarkerFaceColor',[1,1,1]);
hold off;
% Plotting data
figure(3);
hold on;
h = plot(Data.C);
set(h,'Visible','On');
set(gca,'Visible','On');
set(gca,'XLim',[0,t.DurationInSeconds]);
set(gca,'YLim',[-max(Data.C)/5,max(Data.C)*6/5]);
set(h,'LineStyle','-');
set(h,'LineWidth',1);
set(h,'Color','Black');
set(h,'Marker','o');
set(h,'MarkerSize',0.5);
set(h,'MarkerEdgeColor','Black');
set(h,'MarkerFaceColor',[1,1,1]);
% Plotting data
h = plot(Data.F);
set(h,'Visible','On');
set(gca,'Visible','On');
set(gca,'XLim',[0,t.DurationInSeconds]);
set(gca,'YLim',[-max(Data.D)/5,max(Data.D)*6/5]);
set(h,'LineStyle','-');
set(h,'LineWidth',1);
set(h,'Color','Blue');
set(h,'Marker','o');
set(h,'MarkerSize',0.5);
set(h,'MarkerEdgeColor','Blue');
set(h,'MarkerFaceColor',[1,1,1]);
% Deleting measurement session
delete(l);
delete(m);
s.stop;
t.stop;
s.release;
t.release;
end
But it didn't worked either. Data.B stays at 0 all the time. Anyone with a new idea ?
Thanks,
Csaba

Community Treasure Hunt

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

Start Hunting!

Translated by