Injector PWM signal to Fuel Consumption

Discussion on the Lua Scripting capabilities for RaceCapture/Pro. Also see the <a href="http://autosportlabs.net/RaceCapturePro_Lua_Scripting">Lua Scripting Guide</a>

Moderators: JeffC, stieg

Post Reply
tylerjw
Posts: 10
Joined: Sat Jan 05, 2019 7:21 pm

Injector PWM signal to Fuel Consumption

Post by tylerjw »

I'm doing this for endurance racing on a 1990 Honda Civic with a ZC motor. Here is my math so far. Please correct anything that isn't right. I will test this approach this week.

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&#40;10&#41;

fuelFlowId = addChannel&#40;"FuelFlow", 10, 2, 0, 20, "gal/hr"&#41;
fuelConsumedId = addChannel&#40;"FuelUsed", 10, 10, 0,15,"gal"&#41;
fuelTimeId = addChannel&#40;"FuelTime", 10, 4, 0.0, 300.0, "ms"&#41;

fuelTimeSummer = 0
fuelConsumed = 0
fuelCounter = 0

function fuelConsumption&#40;&#41;
  local fuel_rpm = getTimerRpm&#40;1&#41;
  local fuel_off = getTimerPeriodMs&#40;1&#41;
  local period = 1000 * 60 / fuel_rpm
  local fuel_time = &#40;period - fuel_off&#41; * &#40;100 / period&#41;

  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&#40;fuelFlowId, fuel_gal * 3600&#41;
      setChannel&#40;fuelConsumedId, fuelConsumed&#41;
      setChannel&#40;fuelTimeId, fuelTimeSummer&#41;
      fuelCounter = 0
      fuelTimeSummer = 0
    end
  end
end

function onTick&#40;&#41;
  collectgarbage&#40;&#41;
  fuelConsumption&#40;&#41;
end

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

TBracing427
Posts: 6
Joined: Sat Jun 08, 2019 9:45 pm

Post by TBracing427 »

That's cool that you are trying to calculate fuel from the Injector PWM. In fact I'm trying to do the same thing for my 1986 Mercedes 190E. You should let us know how your testing goes.

The code you posted seems like it might work, you have almost the same approach I have in my code. The main thing I'm doing different is I'm using a digital fuel pressure gage to get fuel rail pressure and having it calculate based on fuel pressure how much flow the injectors should have; this should only have a small effect on the results. The other thing I put in my code is a fudge factor (a simple multiplier on the injector flow rate value) so if at a given track I notice we are over estimating or under estimated by some percent I can just change that one value by that percent off we are and that should dial it in. One thing I do have a question on is I'm not sure what the "fuelCounter > 10" is trying to accomplish, maybe a delay in when it updates the channel?

brentp
Site Admin
Posts: 6282
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

Hi, measuring pulsewidth is not supported in the firmware, but there is hardware support for the actual timers, so it might be possible to measure this in the future.

A good option might be to use an Arduino + CAN bus shield to measure the pulsewidth, and then report the current value over CAN bus, which can be mapped in RaceCapture.

Hope this helps!
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

tylerjw
Posts: 10
Joined: Sat Jan 05, 2019 7:21 pm

Post by tylerjw »

Hello brentp and TBracing247. When we went out to test this I discovered just wiring this into the car caused it to not run right. I had patched into injector 1's wiring and this caused injector 2 to stop working. I'm not sure why this would happen. My best guess is that the internal resistance of the Mk3 is too low and I had introduced a grounding loop. Because of this I never got it actually working.

I'm working on building a can bus network based on the teensy 3.2 micro controllers (they natively support can) and plan on trying again to do this on one of them with hopefully better results. I'm doing this because I'm building a CAN version of the tire temp sensors that were posted on this forum and I want an easier way to add sensors. I plan on also adding a fuel pressure sensor to our car so I can more accurately calculate these values.

@TBracing427 did you get it working on your car? If you did do you have any ideas of what I did that could have caused this problem?

@bretp are you saying that the timer value I can get is just the period of the signal and not a count of the ON time?

brentp
Site Admin
Posts: 6282
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

Hi,

Thanks for the update.

The impedance of the timer input is very high - in the megaohm range - so I believe your problem is elsewhere in the system. Also, connecting a timer input to the drive wire of a injector coil is akin to connecting to the primary connection of an ignition coil, which can generate many 100's of volts of flyback circuit. This can cause mis-readings or damage your RaceCapture system (at worse).

We have the CoilX interface designed to work with the primary winding of a typical ignition coil. You can see the theory of operation here:
https://wiki.autosportlabs.com/CoilX

If the flyback voltage is large enough to trigger CoilX, it may also work with the ignition pulse - but we have not tested this scenario.

To answer your last question, the getTimerCount() counts individual pulses, for very slow sources, such as fuel flow sensors. See this article for a better description: https://www.autosportlabs.com/conquerin ... telemetry/
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

tylerjw
Posts: 10
Joined: Sat Jan 05, 2019 7:21 pm

Post by tylerjw »

Thank you for the reply. I thought the injector pulse wires were just pwm signals driven by a mosfet. This shows how little I know about car electronics. I think I may end up just going the route of the fuel flow sensors like what you linked because it'll give me the actual truth on how much fuel we are using. I was just hoping to avoid that because we don't have a returnless system and would need to purchase two of those sensors.

When you say it counts pulses is that the number of pulses since the last time I read it? My question was more about getTimerPeriodMs and if it was measuring the time that the pulse was high or just the period between pulses (1/F)?

TBracing427
Posts: 6
Joined: Sat Jun 08, 2019 9:45 pm

Post by TBracing427 »

tylerjw wrote:Hello brentp and TBracing247. When we went out to test this I discovered just wiring this into the car caused it to not run right. I had patched into injector 1's wiring and this caused injector 2 to stop working. I'm not sure why this would happen. My best guess is that the internal resistance of the Mk3 is too low and I had introduced a grounding loop. Because of this I never got it actually working.

I'm working on building a can bus network based on the teensy 3.2 micro controllers (they natively support can) and plan on trying again to do this on one of them with hopefully better results. I'm doing this because I'm building a CAN version of the tire temp sensors that were posted on this forum and I want an easier way to add sensors. I plan on also adding a fuel pressure sensor to our car so I can more accurately calculate these values.

@TBracing427 did you get it working on your car? If you did do you have any ideas of what I did that could have caused this problem?

@bretp are you saying that the timer value I can get is just the period of the signal and not a count of the ON time?
tylerjw, I did get my code working eventually. I needed to put in a 6% correction factor because my overestimated by a little bit, but we'll see how it works at the race this weekend. I did not run into the same issue as you have with getting the PW of the injectors. With our car we are running megasquirt and megasquirt outputs the injection PW as a channel we can read.

Post Reply