Rev counter problem

I would suggest looking into using interrupts. Unfortunately, I don't have any experience in using interrupts so, hopefully, someone who can provide some good knowledge will step in and add some details.