diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 5139306e98..7e4ac04f77 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -198,18 +198,6 @@ static void doPeriodicSlowCallback() { slowStartStopButtonCallback(); - - efitick_t nowNt = getTimeNowNt(); - for (int bankIndex = 0; bankIndex < BANKS_COUNT; bankIndex++) { - for (int camIndex = 0; camIndex < CAMS_PER_BANK; camIndex++) { - if (nowNt - engine->triggerCentral.vvtSyncTimeNt[bankIndex][camIndex] >= NT_PER_SECOND) { - // loss of VVT sync - // todo: this code would get simpler if we convert vvtSyncTimeNt to Timer - engine->triggerCentral.vvtSyncTimeNt[bankIndex][camIndex] = 0; - } - } - } - engine->rpmCalculator.onSlowCallback(); if (engine->directSelfStimulation || engine->rpmCalculator.isStopped()) { diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index 3d033a9533..8514ba0ca0 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -351,7 +351,8 @@ static bool noFiringUntilVvtSync(vvt_mode_e vvtMode) { void mainTriggerCallback(uint32_t trgEventIndex, efitick_t edgeTimestamp) { ScopePerf perf(PE::MainTriggerCallback); - if (noFiringUntilVvtSync(engineConfiguration->vvtMode[0]) && engine->triggerCentral.vvtSyncTimeNt[0][0] == 0) { + if (noFiringUntilVvtSync(engineConfiguration->vvtMode[0]) + && !engine->triggerCentral.vvtState[0][0].getShaftSynchronized()) { // Any engine that requires cam-assistance for a full crank sync (symmetrical crank) can't schedule until we have cam sync // examples: // NB2, Nissan VQ/MR: symmetrical crank wheel and we need to make sure no spark happens out of sync diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index 669277302f..2e9f540ccf 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -41,8 +41,7 @@ static scheduling_s debugToggleScheduling; TriggerCentral::TriggerCentral() : vvtEventRiseCounter(), vvtEventFallCounter(), - vvtPosition(), - vvtSyncTimeNt() + vvtPosition() { memset(&hwEventCounters, 0, sizeof(hwEventCounters)); triggerState.resetTriggerState(); @@ -264,14 +263,8 @@ void hwHandleVvtCamSignal(trigger_value_e front, efitick_t nowNt, int index) { logFront(isImportantFront, nowNt, index); - - auto currentPhase = tc->getCurrentEnginePhase(nowNt); - if (!currentPhase) { - // todo: this code branch is slowing NB2 cranking since we require RPM sync for VVT sync! - // todo: smarter code - // - // we are here if we are getting VVT position signals while engine is not running - // for example if crank position sensor is broken :) + // If the main trigger is not synchronized, don't decode VVT yet + if (!tc->triggerState.getShaftSynchronized()) { return; } @@ -291,6 +284,13 @@ void hwHandleVvtCamSignal(trigger_value_e front, efitick_t nowNt, int index) { tc->vvtCamCounter++; + auto currentPhase = tc->getCurrentEnginePhase(nowNt); + if (!currentPhase) { + // If we couldn't resolve engine speed (yet primary trigger is sync'd), this + // probably means that we have partial crank sync, but not RPM information yet + return; + } + angle_t currentPosition = currentPhase.Value; // convert engine cycle angle into trigger cycle angle currentPosition -= tdcPosition(); @@ -332,8 +332,6 @@ void hwHandleVvtCamSignal(trigger_value_e front, efitick_t nowNt, int index) { break; } - tc->vvtSyncTimeNt[bankIndex][camIndex] = nowNt; - auto vvtPosition = engineConfiguration->vvtOffsets[bankIndex * CAMS_PER_BANK + camIndex] - currentPosition; if (index != 0) { diff --git a/firmware/controllers/trigger/trigger_central.h b/firmware/controllers/trigger/trigger_central.h index 9edf6061a4..55681209e0 100644 --- a/firmware/controllers/trigger/trigger_central.h +++ b/firmware/controllers/trigger/trigger_central.h @@ -93,9 +93,6 @@ public: // synchronization event position angle_t vvtPosition[BANKS_COUNT][CAMS_PER_BANK]; - // todo: convert to Timer! - efitick_t vvtSyncTimeNt[BANKS_COUNT][CAMS_PER_BANK]; - TriggerStateWithRunningStatistics triggerState; TriggerWaveform triggerShape;