From e34b04bd46752a9d60f4bbf017edfef2f47fa615 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 3 Jul 2021 12:02:00 -0400 Subject: [PATCH] Nissan VVT trigger decoder #2887 --- firmware/config/engines/mazda_miata_custom_hunchback.cpp | 4 ++-- firmware/config/engines/mazda_miata_vvt.cpp | 4 ++-- firmware/controllers/settings.cpp | 2 +- firmware/controllers/trigger/trigger_central.cpp | 2 +- unit_tests/tests/trigger/test_cam_vvt_input.cpp | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/firmware/config/engines/mazda_miata_custom_hunchback.cpp b/firmware/config/engines/mazda_miata_custom_hunchback.cpp index 51fd248437..0ba2b21e9d 100644 --- a/firmware/config/engines/mazda_miata_custom_hunchback.cpp +++ b/firmware/config/engines/mazda_miata_custom_hunchback.cpp @@ -92,7 +92,7 @@ void setMazdaMiata2003EngineConfigurationNaFuelRail(DECLARE_CONFIG_PARAMETER_SIG copyArray(config->veLoadBins, mazda_miata_nb2_LoadBins); copyTable(config->veTable, mapBased18vvtVeTable_NA_fuel_rail); - engineConfiguration->vvtOffset = 83; // 2002 green car value + engineConfiguration->vvtOffsets[0] = 83; // 2002 green car value copyArray(config->lambdaRpmBins, mazda_miata_nb2_targetLambdaRpmBins); copyArray(config->lambdaLoadBins, mazda_miata_nb2_targetLambdaLoadBins); @@ -111,7 +111,7 @@ void setMazdaMiata2003EngineConfigurationNaFuelRail(DECLARE_CONFIG_PARAMETER_SIG engineConfiguration->ignitionDwellForCrankingMs = 8; - engineConfiguration->vvtOffset = 97; + engineConfiguration->vvtOffsets[0] = 97; engineConfiguration->rpmHardLimit = 7200; // we want to survive the race, but we also want some fun! diff --git a/firmware/config/engines/mazda_miata_vvt.cpp b/firmware/config/engines/mazda_miata_vvt.cpp index 0106a9ceed..c7bd97e7b3 100644 --- a/firmware/config/engines/mazda_miata_vvt.cpp +++ b/firmware/config/engines/mazda_miata_vvt.cpp @@ -313,7 +313,7 @@ static void setMazdaMiataEngineNB2Defaults(DECLARE_CONFIG_PARAMETER_SIGNATURE) { engineConfiguration->vvtCamSensorUseRise = true; // set vvt_mode 3 engineConfiguration->vvtMode[0] = VVT_MIATA_NB2; - engineConfiguration->vvtOffset = 98; // 2003 red car value + engineConfiguration->vvtOffsets[0] = 98; // 2003 red car value copyArray(config->veRpmBins, mazda_miata_nb2_RpmBins); copyArray(config->veLoadBins, mazda_miata_nb2_LoadBins); @@ -569,7 +569,7 @@ static void setMiataNB2_MRE_common(DECLARE_CONFIG_PARAMETER_SIGNATURE) { engineConfiguration->ignitionDwellForCrankingMs = 8; - engineConfiguration->vvtOffset = 97; + engineConfiguration->vvtOffsets[0] = 97; // # TLE8888 high current low side: VVT1 IN10 / OUT6 diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index 1deecb3e81..d814fbdfef 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -1214,7 +1214,7 @@ static void setValue(const char *paramStr, const char *valueStr) { setTriggerEmulatorRPM(valueI); #endif /* EFI_EMULATE_POSITION_SENSORS */ } else if (strEqualCaseInsensitive(paramStr, "vvt_offset")) { - engineConfiguration->vvtOffset = valueF; + engineConfiguration->vvtOffsets[0] = valueF; } else if (strEqualCaseInsensitive(paramStr, "vvt_mode")) { engineConfiguration->vvtMode[0] = (vvt_mode_e)valueI; } else if (strEqualCaseInsensitive(paramStr, "operation_mode")) { diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index cb2aa1b58c..3a9ee398cc 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -239,7 +239,7 @@ void hwHandleVvtCamSignal(trigger_value_e front, efitick_t nowNt, int index DECL // we do NOT clamp VVT position into the [0, engineCycle) range - we expect vvtOffset to be configured so that // it's not necessary - tc->vvtPosition[bankIndex][camIndex] = engineConfiguration->vvtOffset - currentPosition; + tc->vvtPosition[bankIndex][camIndex] = engineConfiguration->vvtOffsets[bankIndex * CAMS_PER_BANK + camIndex] - currentPosition; if (tc->vvtPosition[bankIndex][camIndex] < -ENGINE(engineCycle) / 2 || tc->vvtPosition[bankIndex][camIndex] > ENGINE(engineCycle) / 2) { warning(CUSTOM_ERR_VVT_OUT_OF_RANGE, "Please adjust vvtOffset since position %f", tc->vvtPosition); } diff --git a/unit_tests/tests/trigger/test_cam_vvt_input.cpp b/unit_tests/tests/trigger/test_cam_vvt_input.cpp index 351978c14e..4a765be527 100644 --- a/unit_tests/tests/trigger/test_cam_vvt_input.cpp +++ b/unit_tests/tests/trigger/test_cam_vvt_input.cpp @@ -86,7 +86,7 @@ TEST(trigger, testCamInput) { setOperationMode(engineConfiguration, FOUR_STROKE_CRANK_SENSOR); engineConfiguration->useOnlyRisingEdgeForTrigger = true; engineConfiguration->vvtMode[0] = VVT_FIRST_HALF; - engineConfiguration->vvtOffset = 360; + engineConfiguration->vvtOffsets[0] = 360; eth.setTriggerType(TT_ONE PASS_ENGINE_PARAMETER_SUFFIX); engineConfiguration->camInputs[0] = GPIOA_10; // we just need to indicate that we have CAM