Determining time elapsed in between two successive pulses of a signal
8 views (last 30 days)
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;
encoder_signal(i)= readVoltage(a, 'A2');
if encoder_signal == 4.5;
x(i) = toc;
Engine_RPM (i) = (1/x)*60 ;
Pat Gipper on 27 Mar 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.