Pulsin has an inherent problem that the duty cycle has to be constant, and often it is not. A cycle is both a "low" time plus a "high" time. It is also a blocking command. While you can do a

PULSIN pin,0,lowtime
PULSIN pin,1,hightime

Period = lowtime + hightime

Speed (or RPM, etc) = constant/Period

To get the correct period even if the duty cycle varies somewhat, you should know that PULSIN can't read the hightime immediately following the lowtime.
It reads the lowtime, misses the next hightime, skips the following lowtime, and then reads the hightime.

If your sensor puts out a good clean signal, then the PULSIN method is the easiest. But also remember, that at very slow speeds, your code will be sitting around for a long time waiting for the next transition.


The good thing about my routine is that it runs in the background and averages over the sample period (I usually use about 0.5 sec), so the results are very stable, even with noisy inputs.

And... There is nothing that keeps you from writing your ISR in PBP. Use Darrel Taylor's Instant Interrupts.

Just -

read the port bit on a timer interrupt
compare it with the last read of that bit
if it has changed, increment a counter
do the above for a fixed amount of time
read the counter.