From e755e4bcc4201cde89320b023bca722ece1c037e Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Sat, 31 Aug 2024 02:05:22 -0700 Subject: [PATCH] wow, it's easy to support odd-fire too --- firmware/controllers/algo/engine_state.h | 2 ++ firmware/controllers/engine_cycle/spark_logic.cpp | 9 ++++----- firmware/controllers/math/engine_math.cpp | 15 ++++++++++++++- .../test_ignition_scheduling.cpp | 1 + 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/firmware/controllers/algo/engine_state.h b/firmware/controllers/algo/engine_state.h index 5235be96dd..48bd305cce 100644 --- a/firmware/controllers/algo/engine_state.h +++ b/firmware/controllers/algo/engine_state.h @@ -24,6 +24,8 @@ public: */ angle_t engineCycle; + bool useOddFireWastedSpark = false; + /** * this is based on sensorChartMode and sensorSnifferRpmThreshold settings */ diff --git a/firmware/controllers/engine_cycle/spark_logic.cpp b/firmware/controllers/engine_cycle/spark_logic.cpp index 142cf89f21..2ecb6f924b 100644 --- a/firmware/controllers/engine_cycle/spark_logic.cpp +++ b/firmware/controllers/engine_cycle/spark_logic.cpp @@ -105,10 +105,10 @@ static void prepareCylinderIgnitionSchedule(angle_t dwellAngleDuration, floatms_ auto ignitionMode = getCurrentIgnitionMode(); - // On an odd cylinder wasted spark engine, map outputs as if in sequential. + // On an odd cylinder (or odd fire) wasted spark engine, map outputs as if in sequential. // During actual scheduling, the events just get scheduled every 360 deg instead // of every 720 deg. - if (ignitionMode == IM_WASTED_SPARK && (engineConfiguration->cylindersCount % 2 == 1)) { + if (ignitionMode == IM_WASTED_SPARK && engine->engineState.useOddFireWastedSpark) { ignitionMode = IM_INDIVIDUAL_COILS; } @@ -475,9 +475,8 @@ void onTriggerEventSparkLogic(int rpm, efitick_t edgeTimestamp, float currentPha // - current mode is wasted spark // - four stroke bool enableOddCylinderWastedSpark = - (engineConfiguration->cylindersCount % 2 == 1) - && getCurrentIgnitionMode() == IM_WASTED_SPARK - && engine->engineState.engineCycle == 720; + engine->engineState.useOddFireWastedSpark + && getCurrentIgnitionMode() == IM_WASTED_SPARK; if (engine->ignitionEvents.isReady) { for (size_t i = 0; i < engineConfiguration->cylindersCount; i++) { diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index 4786f32af8..e1dd4bda7d 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -404,7 +404,20 @@ ignition_mode_e getCurrentIgnitionMode() { * This heavy method is only invoked in case of a configuration change or initialization. */ void prepareOutputSignals() { - getEngineState()->engineCycle = getEngineCycle(getEngineRotationState()->getOperationMode()); + auto operationMode = getEngineRotationState()->getOperationMode(); + getEngineState()->engineCycle = getEngineCycle(operationMode); + + bool isOddFire = false; + for (size_t i = 0; i < engineConfiguration->cylindersCount; i++) { + if (engineConfiguration->timing_offset_cylinder[i] != 0) { + isOddFire = true; + break; + } + } + + // Use odd fire wasted spark logic if not two stroke, and an odd fire or odd cylinder # engine + getEngineState()->useOddFireWastedSpark = operationMode != TWO_STROKE + && (isOddFire | (engineConfiguration->cylindersCount % 2 == 1)); #if EFI_UNIT_TEST if (verboseMode) { diff --git a/unit_tests/tests/ignition_injection/test_ignition_scheduling.cpp b/unit_tests/tests/ignition_injection/test_ignition_scheduling.cpp index 65a30566e8..3ee4f9eac8 100644 --- a/unit_tests/tests/ignition_injection/test_ignition_scheduling.cpp +++ b/unit_tests/tests/ignition_injection/test_ignition_scheduling.cpp @@ -193,6 +193,7 @@ TEST(ignition, oddCylinderWastedSpark) { // dwell should start at 15 degrees ATDC and firing at 25 deg ATDC engine->ignitionState.dwellAngle = 10; engine->engineState.timingAdvance[0] = -25; + engine->engineState.useOddFireWastedSpark = true; engineConfiguration->minimumIgnitionTiming = -25; // expect to schedule the on-phase dwell and spark (not the wasted spark copy)