RPM with other inputs

PeterH:

dc42:
a better way is to measure and store the time interval between interrupts, and calculate the rpm from that interval.

It looks to me as if that is what the code aims to do (but timing twenty ish revolutions rather than one).

Yes, you are quite right. However, the code doesn't actually measure the time between one pulse and one 20 pulses later. It measures the length of an interval which is known to contain at least 20 pulses, but may start some time before the first pulse and end some time after the last one. Even if the code is corrected to calculate the RPM from the actual number of pulses recorded in that interval (rather than assuming it is 20), it will still be subject to sampling error because of this. Measuring the time between successive interrupts avoids most of this sampling error, as long as interrupt latency is low.