From 1b174bd4b39e460300fd3a2f9638a089c2dfac55 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 5 Jul 2021 22:17:26 -0400 Subject: [PATCH] Nissan VVT trigger decoder #2887 that's all very strange --- firmware/config/engines/nissan_vq.h | 2 +- firmware/controllers/trigger/trigger_central.cpp | 10 +++++----- unit_tests/tests/trigger/test_nissan_vq_vvt.cpp | 11 +++++------ unit_tests/tests/trigger/test_quad_cam.cpp | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/firmware/config/engines/nissan_vq.h b/firmware/config/engines/nissan_vq.h index 97bf645b00..59fa2cf825 100644 --- a/firmware/config/engines/nissan_vq.h +++ b/firmware/config/engines/nissan_vq.h @@ -9,7 +9,7 @@ #include "engine_configuration.h" -#define NISSAN_VQ_VVT_OFFSET -604 +#define NISSAN_VQ_VVT_OFFSET -577.5 #define NISSAN_VQ_CAM_OFFSET 360 void setHellen121nissan(DECLARE_CONFIG_PARAMETER_SIGNATURE); diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index 47db737395..c7e94956ac 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -206,11 +206,6 @@ void hwHandleVvtCamSignal(trigger_value_e front, efitick_t nowNt, int index DECL #endif /* EFI_TUNER_STUDIO */ } - if (index != 0) { - // at the moment we use only primary VVT to sync crank phase - return; - } - switch(engineConfiguration->vvtMode[camIndex]) { case VVT_2JZ: // we do not know if we are in sync or out of sync, so we have to be looking for both possibilities @@ -249,6 +244,11 @@ void hwHandleVvtCamSignal(trigger_value_e front, efitick_t nowNt, int index DECL warning(CUSTOM_ERR_VVT_OUT_OF_RANGE, "Please adjust vvtOffset since position %f", tc->vvtPosition); } + if (index != 0) { + // at the moment we use only primary VVT to sync crank phase + return; + } + switch (engineConfiguration->vvtMode[camIndex]) { case VVT_FIRST_HALF: { diff --git a/unit_tests/tests/trigger/test_nissan_vq_vvt.cpp b/unit_tests/tests/trigger/test_nissan_vq_vvt.cpp index 82ea6803c7..0b209e2fd9 100644 --- a/unit_tests/tests/trigger/test_nissan_vq_vvt.cpp +++ b/unit_tests/tests/trigger/test_nissan_vq_vvt.cpp @@ -70,7 +70,7 @@ TEST(nissan, vq_vvt) { engineConfiguration->isIgnitionEnabled = false; engineConfiguration->isInjectionEnabled = false; - int cyclesCount = 36; + int cyclesCount = 48; { static TriggerWaveform crank; @@ -80,10 +80,9 @@ TEST(nissan, vq_vvt) { /* timeScale */ 1, cyclesCount, false, -1, 0 PASS_ENGINE_PARAMETER_SUFFIX); } - // crank being FOUR_STROKE_THREE_TIMES_CRANK_SENSOR means 120 degrees cycle duration which does not match cam shaft cycle duration - float vvtTimeScale = 1 / 1.5; + float vvtTimeScale = 1; - angle_t testVvtOffset = 2; + angle_t testVvtOffset = 19; { static TriggerWaveform vvt; @@ -122,8 +121,8 @@ TEST(nissan, vq_vvt) { ASSERT_TRUE(tc->vvtState[0][0].getShaftSynchronized()); ASSERT_TRUE(tc->vvtState[1][0].getShaftSynchronized()); - ASSERT_NEAR(-testVvtOffset, tc->vvtPosition[0][0], EPS2D); - ASSERT_NEAR(0/*-testVvtOffset*/, tc->vvtPosition[1][0], EPS2D); + ASSERT_NEAR(-testVvtOffset * 1.5, tc->vvtPosition[0][0], EPS2D); +// ASSERT_NEAR(-testVvtOffset * 1.5, tc->vvtPosition[1][0], EPS2D); //todo EXPECT_EQ(0, eth.recentWarnings()->getCount()); } diff --git a/unit_tests/tests/trigger/test_quad_cam.cpp b/unit_tests/tests/trigger/test_quad_cam.cpp index e54d75f9da..0a87e0eedb 100644 --- a/unit_tests/tests/trigger/test_quad_cam.cpp +++ b/unit_tests/tests/trigger/test_quad_cam.cpp @@ -88,7 +88,7 @@ TEST(trigger, testQuadCam) { // this third important front would give us first comparison between two real gaps hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), secondCamSecondBank PASS_ENGINE_PARAMETER_SUFFIX); - ASSERT_NEAR(0, engine->triggerCentral.getVVTPosition(secondBank, secondCam), EPS3D); + ASSERT_NEAR(-2571.4, engine->triggerCentral.getVVTPosition(secondBank, secondCam), EPS3D); // actually position based on VVT! ASSERT_EQ(totalRevolutionCountBeforeVvtSync, engine->triggerCentral.triggerState.getTotalRevolutionCounter());