First calculate gal/ms.

240cc injectors = 22.9 lbs/hr * 0.17 = 3.893 gal/hr / 60(min/hr) / 60(sec/min) / 1000 (ms/s) = 0.00000108138 gal/ms * 4 (injectors) = 0.00000432555 gal/ms.

Next we need to calculate how many ms of fuel we are consuming. To do this I taped into the pwm signal to injector one in PWM input 2 (1 in zero index). This signal is low (ground) when the injector is firing so I configured it in Period (ms) mode with the medium timer running at 10Hz. Because we are running at 10Hz we need to calculate the number of rotations in 10 Hz. The period of 10Hz is 100ms so the number of rotations is 100 / the ms period.

Code: Select all

```
setTickRate(10)
fuelFlowId = addChannel("FuelFlow", 10, 2, 0, 20, "gal/hr")
fuelConsumedId = addChannel("FuelUsed", 10, 10, 0,15,"gal")
fuelTimeId = addChannel("FuelTime", 10, 4, 0.0, 300.0, "ms")
fuelTimeSummer = 0
fuelConsumed = 0
fuelCounter = 0
function fuelConsumption()
local fuel_rpm = getTimerRpm(1)
local fuel_off = getTimerPeriodMs(1)
local period = 1000 * 60 / fuel_rpm
local fuel_time = (period - fuel_off) * (100 / period)
if fuel_rpm ~= 0 and fuel_time > 0 then
fuelTimeSummer = fuelTimeSummer + fuel_time
fuelCounter = fuelCounter + 1
if fuelCounter > 10 then
local fuel_gal = fuelTimeSummer * 0.00000432555
fuelConsumed = fuelConsumed + fuel_gal
setChannel(fuelFlowId, fuel_gal * 3600)
setChannel(fuelConsumedId, fuelConsumed)
setChannel(fuelTimeId, fuelTimeSummer)
fuelCounter = 0
fuelTimeSummer = 0
end
end
end
function onTick()
collectgarbage()
fuelConsumption()
end
```

References:

lbs/hr to gal/hr: https://www.traditionaloven.com/tutoria ... -hour.html