I am reading a tacho out line from an engine ECU with pulsin, scaling it, then displaying it on an LCD screen. I have had it working with the following code...
Code:
PULSIN PORTD.6,1,rlow
PULSIN PORTD.6,0,rhigh
rpm = rhigh + rlow
rpm = rpm / 50
rpm = 60000 / rpm
if rpm = 65535 then
rpm = 0
endif
...
lcdout $fe,$ca,dec rpm,"rpm "
in the higher RPM, the resolution drops, so I figured if I was to change my calculations to be ... rpm = 3000000 / rpm ... then the resolution would increase.
However when I make it ...
Code:
PULSIN PORTD.6,1,rlow
PULSIN PORTD.6,0,rhigh
rpm = rhigh + rlow
tbase = 50 * 60000
rpm = div32 rpm
if rpm = 65535 then
rpm = 0
endif
The result is roughly 32370rpm
when the revs are increasing, the displayed rpm decreases, and visa-versa... but when the rpm is steady (at idle, or held steady at any RPM) the displayed rpm settles back to 32370
Is there something I am missing here? I am successfully using DIV32 many more times in my code for other functions.
Also I thought I might be overflowing the DIV32 integer (but according to my manual I am not) so I thought I would try....
Code:
PULSIN PORTD.6,1,rlow
PULSIN PORTD.6,0,rhigh
rpm = (rhigh + rlow) / 10
tbase = 500 * 600
rpm = div32 rpm
if rpm = 65535 then
rpm = 0
endif
This results in 0 being displayed all the time.
At idle, rlow, and rhigh (which are identical) read approximately 1400 each, which when I do my maths on paper, (either method I have shown) comes out to approximately 1071rpm which would be correct
Could somebody more intelligent or more observant than I please help me? 
Also might add I'm using a 16F877A
Bookmarks