Data Logging at regular interval. Rpm calculation from Encoder data
    5 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
Program is Calculating rpm through encoder data which is in the form of series of binary data. Encoder resolution is 20 pulses/rev.
N=1000;                            %No.of data samples
encdata=zeros(1,N);                %array to store encoder data
rpm=0;
rpmdata=zeros(1,N);                %array to store rpm data
tic;                               %Start Timer
for i = 2:N;                     
  encdata(1,i)= ->coming from the encoder
    if xor(data(i-1),data(i))==1     %Detects change in state
       sum=sum+1;                    %Counts no. of pulses.
    end
    if mod(round(toc),60)== 0;       %Every 60 seconds
        rpm=sum/20;                  %since 20 pulses per rev
        sum=0;
    end
   rpmdata(1,i)=rpm;
end
This code is not working the way I am expecting it to. Sum calculations are correct so I know the code works for that 'if' loop. Although, the rpm loop does not work right, I presume it has something to do with toc.
It works if I replace
 if mod(round(toc),60)== 0;
with
 if mod(i,100)== 0; %Every 100th sample.
Please suggest if you have a better way to solve this problem :)
0 comentarios
Respuestas (0)
Ver también
Categorías
				Más información sobre Logical en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
