PDA

View Full Version : RPM Sensing



lwindrem
- 11th May 2021, 12:37
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

mpgmike
- 11th May 2021, 16:45
TMR1 = 0 : TMR1 = 0 ' not sure why I have to clear it twice

I think you're supposed to:


TMR1H = 0
TMR1L = 0


Your "PAUSE 1000" means that at best, you can only update your t1_count (tachometer) value once every second. Is that sufficient?

I'd like to suggest reading Microchip's AN1980 Application Note (http://ww1.microchip.com/downloads/en/AppNotes/00001980C.pdf). It deals with the Angular Timer function on the PIC16F161x parts, but lots of practical information that should help you.

lwindrem
- 14th May 2021, 18:24
I have Complete Code for a Simple Ignition system 9 pages long -- it works well 100% accurate RPM Readout buut some what over kill for RPM readout
I can display it if someone would be interested helping me trim it.

richard
- 15th May 2021, 07:30
read this
http://www.picbasic.co.uk/forum/showthread.php?t=16153

what you have posted so far is unlikely to get much of a response.
the more info you provide the better, at least post your best attempt {in code tags} with chip type and config, pbp version ...
connection details better still a schematic even hand drawn along with some detail of the tacho input signal and how its been conditioned
to become a useful pic input will help

Acetronics2
- 16th May 2021, 09:08
Have a look here : http://support.melabs.com/forum/picbasic-pro-compiler-3-0-and-later/microcode-studio-ide/8240-trouble-writing-code#post8248

some similarities encountered ...

Alain