From 70424ac7b5390ff925ce5b4583219207fedbb291 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 5 Jul 2021 23:15:44 -0400 Subject: [PATCH] Nissan VVT trigger decoder #2887 another bug - improper handling of three-times-symmetrical --- firmware/config/engines/nissan_vq.h | 4 ++-- firmware/controllers/trigger/trigger_central.cpp | 13 ++++++++++--- unit_tests/tests/trigger/test_nissan_vq_vvt.cpp | 11 ++++++----- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/firmware/config/engines/nissan_vq.h b/firmware/config/engines/nissan_vq.h index 59fa2cf825..906232382d 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 -577.5 -#define NISSAN_VQ_CAM_OFFSET 360 +#define NISSAN_VQ_VVT_OFFSET -610 +#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 c7e94956ac..d3a4ef2cc0 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -501,11 +501,18 @@ bool TriggerNoiseFilter::noiseFilter(efitick_t nowNt, * todo: why is this method NOT reciprocal to getRpmMultiplier?! */ int getCrankDivider(operation_mode_e operationMode) { - if (operationMode == FOUR_STROKE_CAM_SENSOR || operationMode == TWO_STROKE) { + switch (operationMode) { + case FOUR_STROKE_CRANK_SENSOR: + return 2; + case FOUR_STROKE_SYMMETRICAL_CRANK_SENSOR: + return SYMMETRICAL_CRANK_SENSOR_DIVIDER; + case FOUR_STROKE_THREE_TIMES_CRANK_SENSOR: + return SYMMETRICAL_THREE_TIMES_CRANK_SENSOR_DIVIDER; + default: + case FOUR_STROKE_CAM_SENSOR: + case TWO_STROKE: // That's easy - trigger cycle matches engine cycle return 1; - } else { - return operationMode == FOUR_STROKE_CRANK_SENSOR ? 2 : SYMMETRICAL_CRANK_SENSOR_DIVIDER; } } diff --git a/unit_tests/tests/trigger/test_nissan_vq_vvt.cpp b/unit_tests/tests/trigger/test_nissan_vq_vvt.cpp index 0b209e2fd9..81677b1a15 100644 --- a/unit_tests/tests/trigger/test_nissan_vq_vvt.cpp +++ b/unit_tests/tests/trigger/test_nissan_vq_vvt.cpp @@ -82,7 +82,7 @@ TEST(nissan, vq_vvt) { } float vvtTimeScale = 1; - angle_t testVvtOffset = 19; + angle_t testVvtOffset = 13; { static TriggerWaveform vvt; @@ -113,7 +113,7 @@ TEST(nissan, vq_vvt) { eth.setTimeAndInvokeEventsUs(head->momentX); } - ASSERT_EQ(250, GET_RPM()); + ASSERT_EQ(167, GET_RPM()); TriggerCentral *tc = &engine->triggerCentral; @@ -121,8 +121,9 @@ TEST(nissan, vq_vvt) { ASSERT_TRUE(tc->vvtState[0][0].getShaftSynchronized()); ASSERT_TRUE(tc->vvtState[1][0].getShaftSynchronized()); - ASSERT_NEAR(-testVvtOffset * 1.5, tc->vvtPosition[0][0], EPS2D); -// ASSERT_NEAR(-testVvtOffset * 1.5, tc->vvtPosition[1][0], EPS2D); + ASSERT_NEAR(-testVvtOffset, tc->vvtPosition[0][0], EPS2D); + ASSERT_NEAR(-testVvtOffset, tc->vvtPosition[1][0], EPS2D); -//todo EXPECT_EQ(0, eth.recentWarnings()->getCount()); +// todo: reducing warning here is a separate story + EXPECT_EQ(1, eth.recentWarnings()->getCount()); }