Hi Leigh,
From your two values of 165 and 168, I calculate that the engine was running at 4504 RPM. So, the following formula may be what your looking for.
Code:
Pulse_High Var word
Pulse_Low Var word
Pulse_Total Var Word
RPM Var Word
Pulse_High = 165
Pulse_Low = 168
Pulse_Total = Pulse_High + Pulse_Low
RPM = 1000
RPM = RPM * RPM ' Preload internal registers with 1,000,000
RPM = DIV32 Pulse_Total ' 1,000,000 / Pulse_Total
RPM = RPM * 60 ' Per minute
RPM = Div32 40 ' 4 pulses per rev
lcdout $FE,1,dec RPM
In normal math it might look like this:
(1,000,000/(Pulse_High+Pulse_Low))*60/40
A better way to take the measurements might be to use the Capture mode of the CCP module. Set the prescaler to 2:1 and have it count 4 rising edges of the input and then generate an interrupt. The Timer value would contain 1/2 the number of uS it takes for 1 revolution, which should be fairly easy to convert to RPM. This way, the processor can continue doing other things while it's taking the measurement. This should work from 500-10,000 RPM
That's a bit more complicated, but may be worth looking into.
HTH,
Darrel
Bookmarks