Data Logging at regular interval. Rpm calculation from Encoder data
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!