From bb15cb20fdacfaf16fb0718b23059c94eeb973c5 Mon Sep 17 00:00:00 2001 From: rusefi Date: Tue, 24 Jul 2018 20:40:44 -0400 Subject: [PATCH] #598 --- firmware/controllers/algo/engine.h | 2 +- firmware/controllers/engine_controller.cpp | 2 +- firmware/controllers/math/engine_math.cpp | 2 +- firmware/controllers/trigger/spark_logic.cpp | 22 ++++++++++++++------ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 129f6b71b1..c6b233f7a0 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -414,7 +414,7 @@ public: * pre-calculated offset for given sequence index within engine cycle * (not cylinder ID) */ - angle_t ignitionPositionWithEngineCycle[IGNITION_PIN_COUNT]; + angle_t ignitionPositionWithinEngineCycle[IGNITION_PIN_COUNT]; /** * pre-calculated reference to which output pin should be used for * given sequence index within engine cycle diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 05143f5333..359a79c4f5 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -733,5 +733,5 @@ int getRusEfiVersion(void) { if (initBootloader() != 0) return 123; #endif /* EFI_BOOTLOADER_INCLUDE_CODE */ - return 20180721; + return 20180722; } diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index 529b7d3f83..4d004deaed 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -537,7 +537,7 @@ void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_SIGNATURE) { #endif /* EFI_UNIT_TEST */ for (int i = 0; i < CONFIG(specs.cylindersCount); i++) { - ENGINE(ignitionPositionWithEngineCycle[i])= ENGINE(engineCycle) * i / CONFIG(specs.cylindersCount); + ENGINE(ignitionPositionWithinEngineCycle[i])= ENGINE(engineCycle) * i / CONFIG(specs.cylindersCount); } prepareIgnitionPinIndices(CONFIG(ignitionMode) PASS_ENGINE_PARAMETER_SUFFIX); diff --git a/firmware/controllers/trigger/spark_logic.cpp b/firmware/controllers/trigger/spark_logic.cpp index 1c2fa9ae87..7cfe9cf4c8 100644 --- a/firmware/controllers/trigger/spark_logic.cpp +++ b/firmware/controllers/trigger/spark_logic.cpp @@ -66,11 +66,15 @@ static void turnSparkPinLow2(IgnitionEvent *event, IgnitionOutputPin *output) { } \ } -void prepareCylinderIgnitionSchedule(IgnitionEvent *event DECLARE_ENGINE_PARAMETER_SUFFIX) { +static void prepareCylinderIgnitionSchedule(angle_t dwellAngle, IgnitionEvent *event DECLARE_ENGINE_PARAMETER_SUFFIX) { // todo: clean up this implementation? does not look too nice as is. // change of sign here from 'before TDC' to 'after TDC' - const angle_t localAdvance = -ENGINE(engineState.timingAdvance) + ENGINE(ignitionPositionWithEngineCycle[event->cylinderIndex]) + CONFIG(timing_offset_cylinder[event->cylinderIndex]); + angle_t ignitionPositionWithinEngineCycle = ENGINE(ignitionPositionWithinEngineCycle[event->cylinderIndex]); + assertAngleRange(ignitionPositionWithinEngineCycle, "aPWEC", CUSTOM_ERR_6566); + cfg_float_t_1f timing_offset_cylinder = CONFIG(timing_offset_cylinder[event->cylinderIndex]); + const angle_t localAdvance = -ENGINE(engineState.timingAdvance) + ignitionPositionWithinEngineCycle + timing_offset_cylinder; + efiAssertVoid(!cisnan(localAdvance), "localAdvance#1"); const int index = ENGINE(ignitionPin[event->cylinderIndex]); const int coilIndex = ID2INDEX(getCylinderId(index PASS_ENGINE_PARAMETER_SUFFIX)); @@ -85,7 +89,6 @@ void prepareCylinderIgnitionSchedule(IgnitionEvent *event DECLARE_ENGINE_PARAMET } else { secondOutput = NULL; } - angle_t dwellAngle = ENGINE(engineState.dwellAngle); assertPinAssigned(output); @@ -116,7 +119,13 @@ void turnSparkPinLow(IgnitionEvent *event) { EXPAND_Engine; #endif // now that we've just fired a coil let's prepare the new schedule for the next engine revolution - prepareCylinderIgnitionSchedule(event PASS_ENGINE_PARAMETER_SUFFIX); + + angle_t dwellAngle = ENGINE(engineState.dwellAngle); + if (cisnan(dwellAngle)) { + // we are here if engine has just stopped + return; + } + prepareCylinderIgnitionSchedule(dwellAngle, event PASS_ENGINE_PARAMETER_SUFFIX); } static void turnSparkPinHigh2(IgnitionEvent *event, IgnitionOutputPin *output) { @@ -257,7 +266,8 @@ static ALWAYS_INLINE void handleSparkEvent(bool limitedSpark, uint32_t trgEventI } static void initializeIgnitionActions(IgnitionEventList *list DECLARE_ENGINE_PARAMETER_SUFFIX) { - if (cisnan(ENGINE(engineState.timingAdvance))) { + angle_t dwellAngle = ENGINE(engineState.dwellAngle); + if (cisnan(ENGINE(engineState.timingAdvance)) || cisnan(dwellAngle)) { // error should already be reported // need to invalidate previous ignition schedule list->isReady = false; @@ -270,7 +280,7 @@ static void initializeIgnitionActions(IgnitionEventList *list DECLARE_ENGINE_PAR #if EFI_UNIT_TEST || defined(__DOXYGEN__) list->elements[cylinderIndex].engine = engine; #endif /* EFI_UNIT_TEST */ - prepareCylinderIgnitionSchedule(&list->elements[cylinderIndex] PASS_ENGINE_PARAMETER_SUFFIX); + prepareCylinderIgnitionSchedule(dwellAngle, &list->elements[cylinderIndex] PASS_ENGINE_PARAMETER_SUFFIX); } list->isReady = true; }