Don't have example code, but start a timer, set portb interrupt, get the value of the timer in the interrupt service routine,
reset the timer for the next pulse.