diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 2147c0f5bf..3e3bf56312 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -523,7 +523,7 @@ static void showFuelInfo2(float rpm, float engineLoad) { scheduleMsg(&logger2, "iatCorrection=%f cltCorrection=%f injectorLag=%f", iatCorrection, cltCorrection, injectorLag); - float value = getRunningFuel(baseFuelMs, (int) rpm PASS_ENGINE_PARAMETER); + float value = getRunningFuel(baseFuelMs PASS_ENGINE_PARAMETER); scheduleMsg(&logger2, "injection pulse width: %f", value); } #endif diff --git a/firmware/controllers/algo/fuel_math.cpp b/firmware/controllers/algo/fuel_math.cpp index 285fcff808..28642f1a25 100644 --- a/firmware/controllers/algo/fuel_math.cpp +++ b/firmware/controllers/algo/fuel_math.cpp @@ -127,16 +127,18 @@ percent_t getInjectorDutyCycle(int rpm DECLARE_ENGINE_PARAMETER_S) { */ floatms_t getInjectionDuration(int rpm DECLARE_ENGINE_PARAMETER_S) { float theoreticalInjectionLength; - if (isCrankingR(rpm)) { - int numberOfCylinders = getNumberOfInjections(engineConfiguration->crankingInjectionMode PASS_ENGINE_PARAMETER); - efiAssert(numberOfCylinders > 0, "cranking numberOfCylinders", 0); - theoreticalInjectionLength = getCrankingFuel(PASS_ENGINE_PARAMETER_F) - / numberOfCylinders; + bool isCranking = isCrankingR(rpm); + int numberOfCylinders = getNumberOfInjections(isCranking ? + engineConfiguration->crankingInjectionMode : + engineConfiguration->injectionMode PASS_ENGINE_PARAMETER); + if (numberOfCylinders == 0) { + return 0; // we can end up here during configuration reset + } + if (isCranking) { + theoreticalInjectionLength = getCrankingFuel(PASS_ENGINE_PARAMETER_F) / numberOfCylinders; } else { floatms_t baseFuel = getBaseFuel(rpm PASS_ENGINE_PARAMETER); - floatms_t fuelPerCycle = getRunningFuel(baseFuel, rpm PASS_ENGINE_PARAMETER); - int numberOfCylinders = getNumberOfInjections(engineConfiguration->injectionMode PASS_ENGINE_PARAMETER); - efiAssert(numberOfCylinders > 0, "running numberOfCylinders", 0); + floatms_t fuelPerCycle = getRunningFuel(baseFuel PASS_ENGINE_PARAMETER); theoreticalInjectionLength = fuelPerCycle / numberOfCylinders; #if EFI_PRINTF_FUEL_DETAILS || defined(__DOXYGEN__) printf("baseFuel=%f fuelPerCycle=%f theoreticalInjectionLength=%f\t\n", @@ -146,7 +148,7 @@ floatms_t getInjectionDuration(int rpm DECLARE_ENGINE_PARAMETER_S) { return theoreticalInjectionLength + ENGINE(engineState.injectorLag); } -floatms_t getRunningFuel(floatms_t baseFuel, int rpm DECLARE_ENGINE_PARAMETER_S) { +floatms_t getRunningFuel(floatms_t baseFuel DECLARE_ENGINE_PARAMETER_S) { float iatCorrection = ENGINE(engineState.iatFuelCorrection); float cltCorrection = ENGINE(engineState.cltFuelCorrection); diff --git a/firmware/controllers/algo/fuel_math.h b/firmware/controllers/algo/fuel_math.h index 3755a218b5..03673536b4 100644 --- a/firmware/controllers/algo/fuel_math.h +++ b/firmware/controllers/algo/fuel_math.h @@ -20,7 +20,7 @@ floatms_t getBaseFuel(int rpm DECLARE_ENGINE_PARAMETER_S); /** * @return baseFuel with CLT and IAT corrections */ -floatms_t getRunningFuel(floatms_t baseFuel, int rpm DECLARE_ENGINE_PARAMETER_S); +floatms_t getRunningFuel(floatms_t baseFuel DECLARE_ENGINE_PARAMETER_S); floatms_t getRealMafFuel(float airMass, int rpm DECLARE_ENGINE_PARAMETER_S); diff --git a/unit_tests/test_fuel_map.cpp b/unit_tests/test_fuel_map.cpp index f3f67ce75b..62c83343f7 100644 --- a/unit_tests/test_fuel_map.cpp +++ b/unit_tests/test_fuel_map.cpp @@ -71,7 +71,7 @@ void testFuelMap(void) { printf("*************************************************** getRunningFuel 1\r\n"); eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_F); float baseFuel = getBaseTableFuel(eth.engine.engineConfiguration, 5, getEngineLoadT(PASS_ENGINE_PARAMETER_F)); - assertEqualsM("base fuel", 5.05, getRunningFuel(baseFuel, 5 PASS_ENGINE_PARAMETER)); + assertEqualsM("base fuel", 5.05, getRunningFuel(baseFuel PASS_ENGINE_PARAMETER)); printf("*************************************************** setting IAT table\r\n"); for (int i = 0; i < IAT_CURVE_SIZE; i++) { @@ -103,7 +103,7 @@ void testFuelMap(void) { printf("*************************************************** getRunningFuel 2\r\n"); eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_F); baseFuel = getBaseTableFuel(eth.engine.engineConfiguration, 5, getEngineLoadT(PASS_ENGINE_PARAMETER_F)); - assertEqualsM("v1", 30150, getRunningFuel(baseFuel, 5 PASS_ENGINE_PARAMETER)); + assertEqualsM("v1", 30150, getRunningFuel(baseFuel PASS_ENGINE_PARAMETER)); testMafValue = 0;