since we're on the idea of full disclosure here... heres the code i got from my friend and modified a bit for my project.
this code was written in picbasic pro version 2.5 and is to convert the RPM signal (since i have a v6 which is 1.5 times higher pulses than 4cyl). the code also further modifies the signal so that the RPMs will fill the entire s2k cluster... therefore i will take off the numbered scale and put my own scale on there (my redline is 7k)
the same code can be used for the speed conversion as well... just multiply the measured pulses SF by 39 instead of by 2/3 which is what i did here.
the device used here is a huggge 18f4550 pic since that was on hand but the code should work with anything. the LCD lines are not necessary... but the development board im working with has an LCD so it's useful for testing.
Define LOADER_USED 1
Define OSC 4
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1
define hpwm2_timer 1
define ccp2_reg portc
define ccp2_bit 2
X var word
y Var word
f var word
sf var long ;32 bit math
Trisa = 255
TRISB = 0
TRISC = %10100000 ;pins C0 and C2 output, C0 is reset for divider
ADCON1 = %00001010 ' Set PORTA to analog inputs
Low PORTE.2 ' LCD R/W line low (W)
Pause 100
LCDout $FE, $80
PULSOUT PORTC.0, 100 ;send 1m-sec pulse to pin 15 to RESET on counter
Cycle:
count PORTC.1,125,F ;count pulses for 1/8 second
sf = f * 8 ;multiply by 8 for a full second
sf = sf * 8 ; rpm * 4 * 2 ; multiply by 2 for rpm and 4 prescale for divide by 4 counter
sf = sf / 3 ; divide by 3 for rpm counter....now multiplied by 2/3
sf = sf * 1285
sf = sf / 1000 ; now multiplied by 1.323 to use full
ADCIN 0, X
Lcdout $fe, 1 ' Clear screen
y=X * 255
y = y / 4
Lcdout "ADCVAL=", #X, "PWM=", #y
lcdout $FE, $C0, "Count=", #sF
;Pause 500
hpwm 1,127, y
goto Cycle
pins: pin 15 - signal to reset divide by 4 counter. pin 16 - input, pin 17 - output signal to divide by 4 counter.