Keith-i
Well-Known Member
I have developed an Arduino gateway to get some engine data from the engine can-bus into N2K. So far all is good with rpm, temp and boost. What I'm struggling with is fuel consumption. Below is the crux of it; any help will be appreciated. I realise this is all a bit specialist but the likes of Vas, GHA, adwuk and others seem to have their heads round this stuff more than I do.
The challenge:
To take consecutive readings from bytes 2 and 3 of frame 0x480 of can bus and calculate average fuel consumption. Bytes 2 & 3 give a continuous incremental reading of fuel consumed in microlitres that resets when it reaches 7FFFFF. (Note: the first bit of data is just a marker bit so the data is only 15 bits long).
Requirements:
To get accurate timestamp of data.
To keep a rolling average to smooth out data.
To deal with rollover of time and fuel data. e.g. as fuel consumption data is 15 bit it reaches hex 7FFFFFF (dec 32767 ) before rolling back to zero. Time is 8 bit so it rolls over much sooner.
Managed so far:
To obtain continuous output from 0x480 with flexcan timestamp
Sample data:
Code theory:
Questions:
How do I get sequential readings from 0x480 so that I can obtain fuel1, fuel2, time1 & time 2 to then perform my calculation?
How do I keep a rolling average of the readings to smooth the data?
The challenge:
To take consecutive readings from bytes 2 and 3 of frame 0x480 of can bus and calculate average fuel consumption. Bytes 2 & 3 give a continuous incremental reading of fuel consumed in microlitres that resets when it reaches 7FFFFF. (Note: the first bit of data is just a marker bit so the data is only 15 bits long).
Requirements:
To get accurate timestamp of data.
To keep a rolling average to smooth out data.
To deal with rollover of time and fuel data. e.g. as fuel consumption data is 15 bit it reaches hex 7FFFFFF (dec 32767 ) before rolling back to zero. Time is 8 bit so it rolls over much sooner.
Managed so far:
To obtain continuous output from 0x480 with flexcan timestamp
Sample data:
Code:
Timestamp-- bin-- dec
31910-- 111111111101111-- 32751
41943-- 111111111110100-- 32756
51976-- 111111111111001-- 32761
62008-- 111111111111110-- 32766
6506-- 11-- 3
16537-- 1000-- 8
26569-- 1101-- 13
36602-- 10010-- 18
46636-- 10111-- 23
56668-- 11100-- 28
Code theory:
Code:
fuel = ((( inMsg.buf[3]&0b01111111)<<8)+inMsg.buf[2]);
if fuel2>fuel1
fuelused = fuel2-fuel1
else fuelused=((fuel2+32767)-fuel1)
if time2>time1
timediff = time2-time1
else timediff=((time2+65535)-time1)
fuelrate = (360/timediff)*fuelused
How do I get sequential readings from 0x480 so that I can obtain fuel1, fuel2, time1 & time 2 to then perform my calculation?
How do I keep a rolling average of the readings to smooth the data?