Hello friends,
some time ago, I did a digital speedometer for my car using the following code to count pulses (written by Tim_B for Proton Basic)
==============================================
Define LCD_DREG PORTA
Define LCD_DBIT 0
Define LCD_RSREG PORTB
Define LCD_RSBIT 4
Define LCD_EREG PORTB
Define LCD_EBIT 5
REM Variables
TMR0_POSTCOUNT1 var WORD ' POSTSCALER COUNTERS
COUNT_RESULT var WORD ' THE RESULT OF THE COUNT
REFRESHED var BIT ' FLAG TO SAY COUNT REFRESHED
'-------------------------'
ON INTERRUPT GOTO PULSE_COUNT ' DEFINE WHERE TO JUMP TO ON AN INTERRUPT
'-------------------------'
GOTO INITIALIZE ' JUMP ALL INT CODE
'----- INTERRUPT CODE -------------------
Disable
PULSE_COUNT:
TMR0 = TMR0 + 7 ' RELOAD THE TIMER
TMR0_POSTCOUNT1 = TMR0_POSTCOUNT1 - 1
IF TMR0_POSTCOUNT1 = 0 THEN
TMR0_POSTCOUNT1 = 500 ' 1/4 sec (may need some adjust)
T1CON.0 = 0 ' TURN OFF THE TMR1
COUNT_RESULT.lowbyte = TMR1L ' GET THE COUNT
COUNT_RESULT.Highbyte = TMR1H ' GET THE COUNT
TMR1L = 0
TMR1H = 0
T1CON.0 = 1
REFRESHED = 1 ' SET FLAG TO SAY COUNT READ
ENDIF
INTCON.2 = 0 ' CLEAR INTTERUPT FLAG
Resume
enable ' RELOAD THE SYSTEM VARS
'------ END OF INTERRUPTS CODE ----------
'------ INTIALIzE ALL REGS --------------
INITIALIZE:
TMR0_POSTCOUNT1 = 500 ' INITIALZE THE POST SCALERS
OPTION_REG.0 = 0 ' SET THE PRESCALER TO 1:1
OPTION_REG.1 = 0
OPTION_REG.2 = 0
OPTION_REG.5 = 0 ' TMR0 CLOCK FROM MAIN OSC
OPTION_REG.3 = 0 ' IN THIS INSTANCE PRESCALER IS ASSINED TO TMR0
INTCON.2 = 0 ' CLEAR INTERRUPT FLAG
T1CON = %00000110
T1CON.0 = 1 ' TURN TIMER 1 ON
TMR0 = 7 ' LOAD THE TIMER
INTCON.5 = 1 ' ENABLE TMR0 INTERRUPTS
REFRESHED = 0 ' DONT MAKE FIRST READ UNTIL MAIN INT HAS OCCURED
INTCON.7 = 1 ' START THE WHOLE THING RUNNING
COUNT_RESULT = 0
pause 500
lcdout $FE,1
'------ MAIN CODE BELOW HERE -------------
LOOP:
IF REFRESHED = 1 THEN
lcdout $fe,1,$fe,2, "Freq = ", dec (COUNT_RESULT * 4) ' Show results in pulses / Sec
REFRESHED = 0 ' PREVENT A RE-READ UNTIL NEXT MAIN INTERRUPT
ENDIF
GOTO LOOP
END
===========================================
Well, I bought a new car (used, but newer than the other one). I had do modify a lot my circuit to make it working due to the Car´s Hall sensor strange bahavior. Now, it´s fixed.
But now, I would like to measure my instat fuel consumption, reading the Injector´s "on" time and the engine´s RPM (please, see http://www.eelkevisser.nl/fuel.htm )
I was reading the 16F877A datasheet and I noticed that CCP1 and CCP2 uses Timer1.
Is it possible to measure those two other parameters (engine´s RPM and Injector "on"-time) using the CCP1 and CCP2 without messing my interrupts ?
Sorry for my bad english !
Regards.
Sérgio
Bookmarks