Here’s an app note from Microchip describing various methods for measuring pulse in periodic and non-periodic waveforms. Calculating duty cycle in periodic waveforms is also described.
Many times it is desirable to quantify the pulse width of a periodic signal, such as that of a servo motor or duty cycle of a pulse-width modulated signal. There are other instances where a pulse that is non-periodic needs to be measured, such as those commonly found in a Capacitive Discharge ignition circuit. This application note describes six different strategies to measure a pulse of both periodic and non-periodic waveforms as well as six methods for calculating a duty cycle of a periodic waveform using an 8-bit PIC device.