Code Correction

IMHO you should first specify in more detail what you exactly need. How much precision, how much resolution and what is the maximum expected pulse width. What are you doing?