# Determining time elapsed in between two successive pulses of a signal

5 visualizaciones (últimos 30 días)
Senal Perera el 26 de Mzo. de 2021
Comentada: Pat Gipper el 29 de Mzo. de 2021
I have a voltage signal from a rotary encoder which gives 1 pulse (4.5v) per revolution. I need to calculate the time elapsed between two successive peaks to get the speed of rotation. Can someone guide me please. My code is attached below. Thanks in advance.
a = arduino;
for i=1:inf
tic;
figure(1);
plot(encoder_signal);
ylabel('Encoder signal');
hold on;
pause(0.001);
if encoder_signal == 4.5;
x(i) = toc;
Engine_RPM (i) = (1/x)*60 ;
end
end
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Pat Gipper el 26 de Mzo. de 2021
How likely is it that the voltage is going to be exactly 4.5 Volts? I would think that you should trigger on the value exceeding a good threshold value (e.g. encoder_signal > 4).

Iniciar sesión para comentar.

Pat Gipper el 27 de Mzo. de 2021
I updated your code a bit and fed in an artificial signal. It works but has a slight error due to loop delays running on my computer. You may need to adjust the threshold from 4.5 V depending on your actual encoder signal. If there is a lot of noise then the edge trigger would need hysteresis added to prevent double triggering.
##### 2 comentariosMostrar NingunoOcultar Ninguno
Senal Perera el 29 de Mzo. de 2021
Thank you so much Pat!!! It works.
Pat Gipper el 29 de Mzo. de 2021
No problem Senal. I hadn't tried TicToc before, so it was a good learning experience.

Iniciar sesión para comentar.

### Categorías

Más información sobre Pulse and Transition Metrics en Help Center y File Exchange.

R2015a

### Community Treasure Hunt

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

Start Hunting!

Translated by