The PIC18F1320 would be my choice only given the 2 you offered. It easily can handle 2 Interrupts, and offers an internal Oscillator.
- I would run the OSC at 4 MHz.
- I would use INT0 (RB0) for the driveshaft trigger input. The Interrupt Handler should increment your counter variable every time the driveshaft makes another pass.
- I would use TMR1 to create the 1 second timer (actually 1/2 second timer).
> T1CON = %0011000X; .7 = TMR1H & TMR1L written to independently, <5-4> = 1:8 Prescale, .1 = Clock source is Fosc/4, .0 = On/Off
> Preload TMR1 = 3035 (T1 will tick at 0.000008 seconds, times 62500 (65535 - 3035) = 0.5 seconds); TMR1H = $0B, TMR1L = $DB
Since your TMR1_INT will occur every half second, it would probably be easiest to calculate your vehicle's speed by running the math around that. Say for instance your counter variable = 35 when your TMR1_INT overflows. You double it and get 70 driveshaft pulses per second. If you need better resolution, you could create a variable that will count 1/2 second TMR1 Interrupts and calculate vehicle speed only after 10 have occurred; which is 5 seconds. Be sure to clear your counter variable after using it in your calculation.
There is some detail here, and some things left ambiguous. Hopefully this guides you to a working piece.
Bookmarks