I belive your problem will not be on how to count the pulses in 5 seconds but more how you are going to be able to use your formula.
PIC are not good number crunchers.... PIC stands for Periperal Interface Controller..... and although it has math capability, it does not like floating point :shock: You are going to have to come with a way to use floating numbers, the easiest way is to deal with instead of 3.45 work with 345.
How exact has those 5 seconds have to be?
A simple loop that checks RB0 will do the trick. Something like:
Code:
Loop:
If PortB.0 = 1 then
Count = Count + 1
end if
If TimeisUp = X then ExitLoop
goto Loop.
It will do it fast enough that it would be difficult to miss a pulse. You can use the interrupt on the RB0 to make it more reliable.
To keep track of how long you do this, you set a timer and count how many times it overflows. You can calculate how many overflows have to occur to have 5 seconds.
Check out timers and interrupts tutorials.
Also you should think on having your equation look more like:
Speed = (#pulses in 5 sec) * 431
that is 100 ( 0.006/1.39E-3) = 431
And when it is time to display just break up the number.
Good Luck
Ivancho