I thought just counting the the speed pulses to 32 (about 17.5 yards) would be adequate then at that point measuring the injector pulse width.
That should give me enough info to go on.
Could be, but I know if I were doing it I'd be hankering for knowing the journey MPG rate just for curiosity.
I got into trying to track accurate distance travelled and that may be of some use anyway, even if not necessary here.
If there are 3210 pulses per mile, the distance in miles per pulse is about -
0.00031152647975077883
Assuming we may want a 'journey average' in the future we need a data item able to hold say a 1,000 miles of travel, and just after 1,000 miles we should see -
1000.00031152647975077883
Split into 4-digit chunks we get -
1000 . 0003 1152 6479 7507 7883
We use 4-digit chunks because it means each chunk can be held in a 16-bit word variable, handling carry from adding two chunks together is pretty easy, and they are decimals so easy to print and use without having to convert from binary to decimal.
In fact, our most significant integer part can be 5-digit, allowing up to 65,537 miles to be stored.
The code for updating and reporting distance travelled is, not trivial, but not hard -
Code:
AddDistancePulse:
; 5 4 3 2 1 0
; Add 0 . 0003 1152 6479 7507 7883
miles0 = miles0 + 7883
miles1 = miles0 / 10000 + miles1 + 7507 : miles0 = miles0 // 10000
miles2 = miles1 / 10000 + miles2 + 6479 : miles1 = miles1 // 10000
miles3 = miles2 / 10000 + miles3 + 1152 : miles2 = miles2 // 10000
miles4 = miles3 / 10000 + miles4 + 0003 : miles3 = miles3 // 10000
miles5 = miles4 / 10000 + miles5 + 0 : miles4 = miles4 // 10000
Return
Code:
ShowDistanceTravelled:
SerTxd( #miles5, "." )
w0 = miles4 : Gosub ShowChunk
w0 = miles3 : Gosub ShowChunk
w0 = miles2 : Gosub ShowChunk
w0 = miles1 : Gosub ShowChunk
w0 = miles0 : Gosub ShowChunk
SerTxd( CR, LF )
Return
ShowChunk:
BinToAscii w0, d5, d4, d3, d2, d1
SerTxd( d4, d3, d2, d1 )
Return
We can do similar for 'gallons' as well as 'miles', though the numbers added will be different.
Here's a test program to simulate distance travelled -
Code:
#Picaxe 20X2
#Terminal 38400
#No_Table
#No_Data
Symbol reserveW0 = w0 ; b1:b0
Symbol reserveW1 = w1 ; b3:b2
Symbol miles0 = w2 ; b5:b4
Symbol miles1 = w3 ; b7:b6
Symbol miles2 = w4 ; b9:b8
Symbol miles3 = w5 ; b11:b10
Symbol miles4 = w6 ; b13:b12
Symbol miles5 = w7 ; b15:b14
Symbol d1 = b21
Symbol d2 = b22
Symbol d3 = b23
Symbol d4 = b24
Symbol d5 = b25
PowerOnReset:
SetFreq M32
Pause 8000
SerTxd( "Started MPG-001.bas", CR, LF )
MainLoop:
Do
For w0 = 1 To 3210 ; 3210 pulses is a mile travelled
Gosub AddDistancePulse
Next
Gosub ShowDistanceTravelled ; Report distance travelled
Loop
AddDistancePulse:
; 5 4 3 2 1 0
; Add 0 . 0003 1152 6479 7507 7883
miles0 = miles0 + 7883
miles1 = miles0 / 10000 + miles1 + 7507 : miles0 = miles0 // 10000
miles2 = miles1 / 10000 + miles2 + 6479 : miles1 = miles1 // 10000
miles3 = miles2 / 10000 + miles3 + 1152 : miles2 = miles2 // 10000
miles4 = miles3 / 10000 + miles4 + 0003 : miles3 = miles3 // 10000
miles5 = miles4 / 10000 + miles5 + 0 : miles4 = miles4 // 10000
Return
ShowDistanceTravelled:
SerTxd( #miles5, "." )
w0 = miles4 : Gosub ShowChunk
w0 = miles3 : Gosub ShowChunk
w0 = miles2 : Gosub ShowChunk
w0 = miles1 : Gosub ShowChunk
w0 = miles0 : Gosub ShowChunk
SerTxd( CR, LF )
Return
ShowChunk:
BinToAscii w0, d5, d4, d3, d2, d1
SerTxd( d4, d3, d2, d1 )
Return
Code:
Started MPG-001.bas
1.00000000000000004430
2.00000000000000008860
3.00000000000000013290
4.00000000000000017720
5.00000000000000022150
6.00000000000000026580
7.00000000000000031010
8.00000000000000035440
9.00000000000000039870
10.00000000000000044300
As can be seen there's some discrepancy but that can be improved by adding more least significant digits to the data, having a more accurate calculation of 1/3210. But on the other hand it's so insignificant that, even over 100 miles, the data resolution could be reduced, less words used.
I should also add the usual caveats about interfacing with vehicle electronics, the risks and potential insurance issues involved. It's not something we would recommend without appropriate experience and understanding but, with that said, can take it as read that you will make a sensible and informed decision and we don't need to argue those issues here.