I think voltage out of the alternator is probably not an accurate measure. What if the battery is discharged?
PRELOAD is simply a var I load into TMR0 on every interrupt to get the interrupt period to be what I want. If you are running 7000 RPM and your tach signal is a square wave that has one cycle per revolution, then the period is 8.5 mSec, and a half-cycle is 4.25mSec. In order to make certain that you don't miss a pulse, your interrupt rate (period) would need to be 4mSec. At 4Mhz, PRELOAD would be 0xF067 (PRELOADH = 0xF0, PRELOADL = 0x67). Directly from MisterE's PIC MultiCalc.
Measuring the time between two pulses is OK if your signal is not "noisy". But the signals I had to measure were very noisy. Sometimes the time between two pulses was 1.5 mSec, sometimes it was 5mSec. That really screwed up my program. In order to get an accurate reading, I had to average a large number of pulses. Then my "quick and dirty" routine wasn't so quick anymore. And the slower the input signal, the longer my routine took.
Timer interrupts to the rescue. I run an interrupt at 500uSec. Now, I can measure any number of signals simultaneously - on any pin. I count transitions over a time interval - say half a second, and I automatically get the average number of pulses over that time interval. The best part is, it all takes place entirely in the background. I can read a variable anywhere in my program, and it has the latest RPM value. The accuracy is limited only by the sampling time.





Bookmarks