Quantcast
Channel: MEL PICBASIC Forum
Viewing all articles
Browse latest Browse all 4793

RPM Sensing

$
0
0
This works but is much too slow to use with a gas engine 6,100 rpm

Main:
' clear the variables and timer
t1_count = 0
TMR1 = 0 : TMR1 = 0 ' not sure why I have to clear it twice
PIR1.0 = 0


' start the timer and let it count for 1 second
T1CON.0 = 1
PAUSE 1000 ' this has to be shorter than 131072 counts
T1CON.0 = 0 ' Stop the timer
' read the variables and check for an overflow
t1_count = TMR1
IF PIR1.0 = 1 THEN t1_count = t1_count + 65536
' send serial message with count, RPM
HSEROUT ["Count = ", DEC t1_count, " RPM = ", DEC (t1_count * 15 ) , 10,13]
GOTO main

This works but a lot of Jitter

'Each Pulse in Tick = 625nS.
'RPM = 60 / (Ticker * 625nS)
'60 / 625nS = 96000000
'RPM_In = 96000000 / Ticker
Tick = 0 ' Set Var to Zero
D_Tick = 0 ' Set Var to Zero
Ticker = 0 ' Set Var to Zero
Pulsin PortB.0 ,1, Tick ' Measure Pulse Time High Per Rev.
RCTIME PortB.0 ,0, D_Tick ' Measure Pulse Time Low Per Rev.
Ticker = (Tick + D_Tick) ' Ticker = Pulse High + Pulse Low
RPM_IN = (96000000 / Ticker) ' 96,000,000 Devide by Ticker = RPM

HSEROUT " RPM = ", DEC RPM_IN , 10,13]

I know that an interrupt code would be much more accurate and more steady do not know how to start making an interrupt driven code
Help Please

Viewing all articles
Browse latest Browse all 4793