diff --git a/firmware/controllers/algo/engine2.cpp b/firmware/controllers/algo/engine2.cpp index b3e0d0323b..612ce8e17b 100644 --- a/firmware/controllers/algo/engine2.cpp +++ b/firmware/controllers/algo/engine2.cpp @@ -164,7 +164,14 @@ void EngineState::periodicFastCallback() { injectionOffset = getInjectionOffset(rpm, fuelLoad); float ignitionLoad = getIgnitionLoad(); - float advance = getAdvance(rpm, ignitionLoad) * engine->ignitionState.luaTimingMult + engine->ignitionState.luaTimingAdd; + float baseAdvance = getAdvance(rpm, ignitionLoad) * engine->ignitionState.luaTimingMult + engine->ignitionState.luaTimingAdd; + float correctedIgnitionAdvance = baseAdvance + // Pull any extra timing for knock retard + + engine->module()->getKnockRetard(); + // these fields are scaled_channel so let's only use for observability, with a local variables holding value while it matters locally + engine->ignitionState.baseIgnitionAdvance = baseAdvance; + engine->ignitionState.correctedIgnitionAdvance = correctedIgnitionAdvance; + // compute per-bank fueling for (size_t i = 0; i < STFT_BANK_COUNT; i++) { @@ -181,7 +188,7 @@ void EngineState::periodicFastCallback() { // Apply both per-bank and per-cylinder trims engine->engineState.injectionMass[i] = injectionMass * bankTrim * cylinderTrim; - timingAdvance[i] = advance + getCombinedCylinderIgnitionTrim(i, rpm, ignitionLoad); + timingAdvance[i] = correctedIgnitionAdvance + getCombinedCylinderIgnitionTrim(i, rpm, ignitionLoad); } // TODO: calculate me from a table! diff --git a/firmware/controllers/engine_cycle/spark_logic.cpp b/firmware/controllers/engine_cycle/spark_logic.cpp index 5fe8fd61da..0b907f68dd 100644 --- a/firmware/controllers/engine_cycle/spark_logic.cpp +++ b/firmware/controllers/engine_cycle/spark_logic.cpp @@ -101,8 +101,6 @@ static void prepareCylinderIgnitionSchedule(angle_t dwellAngleDuration, floatms_ angle_t correctedSparkAngle = // Negate because timing *before* TDC, and we schedule *after* TDC - getEngineState()->timingAdvance[event->cylinderNumber] - // Pull any extra timing for knock retard - + engine->module()->getKnockRetard() // Degrees of timing REMOVED from actual timing during soft RPM limit window + getLimpManager()->getLimitingTimingRetard();