diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index d342c184ed..681be57c2a 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -530,10 +530,6 @@ static void updateFuelInfo() { } static void updateIgnition(int rpm) { - float timing = engine->engineState.timingAdvance[0]; - // that's weird logic. also seems broken for two stroke? - engine->outputChannels.ignitionAdvance = timing > FOUR_STROKE_CYCLE_DURATION / 2 ? timing - FOUR_STROKE_CYCLE_DURATION : timing; - engine->outputChannels.coilDutyCycle = getCoilDutyCycle(rpm); engine->outputChannels.knockCount = engine->module()->getKnockCount(); diff --git a/firmware/controllers/algo/engine2.cpp b/firmware/controllers/algo/engine2.cpp index 920a03ec26..c8d5120391 100644 --- a/firmware/controllers/algo/engine2.cpp +++ b/firmware/controllers/algo/engine2.cpp @@ -160,6 +160,9 @@ void EngineState::periodicFastCallback() { float ignitionLoad = getIgnitionLoad(); float advance = getAdvance(rpm, ignitionLoad) * engine->ignitionState.luaTimingMult + engine->ignitionState.luaTimingAdd; + // that's weird logic. also seems broken for two stroke? + engine->outputChannels.ignitionAdvance = (float)(advance > FOUR_STROKE_CYCLE_DURATION / 2 ? advance - FOUR_STROKE_CYCLE_DURATION : advance); + // compute per-bank fueling for (size_t i = 0; i < STFT_BANK_COUNT; i++) { float corr = clResult.banks[i]; diff --git a/firmware/controllers/engine_cycle/spark_logic.cpp b/firmware/controllers/engine_cycle/spark_logic.cpp index d70327d3ff..504449b36b 100644 --- a/firmware/controllers/engine_cycle/spark_logic.cpp +++ b/firmware/controllers/engine_cycle/spark_logic.cpp @@ -80,23 +80,30 @@ static void prepareCylinderIgnitionSchedule(angle_t dwellAngleDuration, floatms_ // let's save planned duration so that we can later compare it with reality event->sparkDwell = sparkDwell; + // Compute the final ignition timing including all "late" adjustments + angle_t finalIgnitionTiming = getEngineState()->timingAdvance[event->cylinderNumber] + // Pull any extra timing for knock retard + - engine->module()->getKnockRetard(); + + // TODO: Log "true" per-cylinder timing here #76 + //engine->outputChannels......[event->cylinderNumber] = finalIgnitionTiming; + angle_t sparkAngle = // Negate because timing *before* TDC, and we schedule *after* TDC - - getEngineState()->timingAdvance[event->cylinderNumber] + - finalIgnitionTiming // Offset by this cylinder's position in the cycle - + getCylinderAngle(event->cylinderIndex, event->cylinderNumber) - // Pull any extra timing for knock retard - + engine->module()->getKnockRetard(); + + getCylinderAngle(event->cylinderIndex, event->cylinderNumber); efiAssertVoid(ObdCode::CUSTOM_SPARK_ANGLE_1, !cisnan(sparkAngle), "sparkAngle#1"); + wrapAngle2(sparkAngle, "findAngle#2", ObdCode::CUSTOM_ERR_6550, getEngineCycle(getEngineRotationState()->getOperationMode())); + event->sparkAngle = sparkAngle; auto ignitionMode = getCurrentIgnitionMode(); engine->outputChannels.currentIgnitionMode = static_cast(ignitionMode); const int index = getIgnitionPinForIndex(event->cylinderIndex, ignitionMode); const int coilIndex = ID2INDEX(getCylinderId(index)); - IgnitionOutputPin *output = &enginePins.coils[coilIndex]; - + event->outputs[0] = &enginePins.coils[coilIndex]; IgnitionOutputPin *secondOutput; // If wasted spark, find the paired coil in addition to "main" output for this cylinder @@ -108,11 +115,8 @@ static void prepareCylinderIgnitionSchedule(angle_t dwellAngleDuration, floatms_ secondOutput = nullptr; } - event->outputs[0] = output; event->outputs[1] = secondOutput; - wrapAngle2(sparkAngle, "findAngle#2", ObdCode::CUSTOM_ERR_6550, getEngineCycle(getEngineRotationState()->getOperationMode())); - event->sparkAngle = sparkAngle; // Stash which cylinder we're scheduling so that knock sensing knows which // cylinder just fired event->cylinderNumber = coilIndex; diff --git a/firmware/integration/rusefi_config_shared.txt b/firmware/integration/rusefi_config_shared.txt index 688d1aafe4..7d1e0f1105 100644 --- a/firmware/integration/rusefi_config_shared.txt +++ b/firmware/integration/rusefi_config_shared.txt @@ -163,7 +163,7 @@ #define GAUGE_NAME_LAMBDA2 "Lambda 2" #define GAUGE_NAME_IAC "Idle: Position" -#define GAUGE_NAME_TIMING_ADVANCE "Ign: Timing" +#define GAUGE_NAME_TIMING_ADVANCE "Ign: Timing Base" #define GAUGE_NAME_DWELL_DUTY "Ign: Coil duty cycle" #define GAUGE_COIL_DWELL_TIME "Ign: Dwell" #define GAUGE_NAME_IGNITION_LOAD "Ign: Load"