diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index d16ef2b340..9528e01f91 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -264,11 +264,18 @@ static void doPeriodicSlowCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) { slowStartStopButtonCallback(PASS_ENGINE_PARAMETER_SIGNATURE); #endif /* EFI_PROD_CODE */ + efitick_t nowNt = getTimeNowNt(); + + if (nowNt - engine->triggerCentral.vvtSyncTimeNt >= NT_PER_SECOND) { + // loss of VVT sync + engine->triggerCentral.vvtSyncTimeNt = 0; + } + /** * Update engine RPM state if needed (check timeouts). */ - bool isSpinning = engine->rpmCalculator.checkIfSpinning(getTimeNowNt() PASS_ENGINE_PARAMETER_SUFFIX); + bool isSpinning = engine->rpmCalculator.checkIfSpinning(nowNt PASS_ENGINE_PARAMETER_SUFFIX); if (!isSpinning) { engine->rpmCalculator.setStopSpinning(PASS_ENGINE_PARAMETER_SIGNATURE); } @@ -746,6 +753,6 @@ int getRusEfiVersion(void) { if (initBootloader() != 0) return 123; #endif /* EFI_BOOTLOADER_INCLUDE_CODE */ - return 20200422; + return 20200426; } #endif /* EFI_UNIT_TEST */ diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index 5d1c2c9ed8..ecb999e941 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -358,6 +358,14 @@ static void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t trgEvent (void) ckpSignalType; + + if (engineConfiguration->vvtMode == MIATA_NB2 && engine->triggerCentral.vvtSyncTimeNt == 0) { + // this is a bit spaghetti code for sure + // do not spark & do not fuel until we have VVT sync. NB2 is a special case + // due to symmetrical crank wheel and we need to make sure no spark happens out of sync + return; + } + if (hasFirmwareError()) { /** * In case on a major error we should not process any more events. diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index c6b7dc2c80..902a87aa2a 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -135,6 +135,9 @@ void hwHandleVvtCamSignal(trigger_value_e front, efitick_t nowNt DECLARE_ENGINE_ floatus_t oneDegreeUs = engine->rpmCalculator.oneDegreeUs; if (cisnan(oneDegreeUs)) { + // 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 :) return; @@ -166,6 +169,7 @@ void hwHandleVvtCamSignal(trigger_value_e front, efitick_t nowNt DECLARE_ENGINE_ } } + tc->vvtSyncTimeNt = nowNt; efitick_t offsetNt = nowNt - tc->timeAtVirtualZeroNt; diff --git a/firmware/controllers/trigger/trigger_central.h b/firmware/controllers/trigger/trigger_central.h index 0587a3a023..d076f3c83d 100644 --- a/firmware/controllers/trigger/trigger_central.h +++ b/firmware/controllers/trigger/trigger_central.h @@ -56,6 +56,8 @@ public: */ efitick_t timeAtVirtualZeroNt = 0; + efitick_t vvtSyncTimeNt = 0; + TriggerWaveform triggerShape; efitick_t previousVvtCamTime = DEEP_IN_THE_PAST_SECONDS * NT_PER_SECOND;