From 2f45ed205ca05481b1c4bd53dc1edbd32035ed4f Mon Sep 17 00:00:00 2001 From: rusefillc Date: Sun, 5 Dec 2021 14:25:13 -0500 Subject: [PATCH] MAP phase sensing #3544 option to look for high and low peaks --- .../engine_cycle/map_averaging.cpp | 2 +- .../controllers/trigger/trigger_central.h | 8 +++-- firmware/integration/rusefi_config.txt | 2 +- firmware/tunerstudio/rusefi.input | 1 + unit_tests/tests/trigger/test_map_cam.cpp | 33 +++++++++++++++---- 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/firmware/controllers/engine_cycle/map_averaging.cpp b/firmware/controllers/engine_cycle/map_averaging.cpp index 048de73ee6..b5f98931d4 100644 --- a/firmware/controllers/engine_cycle/map_averaging.cpp +++ b/firmware/controllers/engine_cycle/map_averaging.cpp @@ -111,7 +111,7 @@ void mapAveragingAdcCallback(adcsample_t adcValue) { if (engineConfiguration->vvtMode[0] == VVT_MAP_V_TWIN && ((fastMapCounter++ % engineConfiguration->mapCamSkipFactor) == 0)) { engine->triggerCentral.mapState.add(instantMap); - bool isPeak = engine->triggerCentral.mapState.isPeak(); + bool isPeak = engine->triggerCentral.mapState.isPeak(engineConfiguration->mapCamLookForLowPeaks); #if EFI_TUNER_STUDIO tsOutputChannels.TEMPLOG_map_length = MAP_CAM_BUFFER; tsOutputChannels.TEMPLOG_MAP_INSTANT_AVERAGE = engine->triggerCentral.mapState.current; diff --git a/firmware/controllers/trigger/trigger_central.h b/firmware/controllers/trigger/trigger_central.h index 1f1ff9f24f..fdf79ee995 100644 --- a/firmware/controllers/trigger/trigger_central.h +++ b/firmware/controllers/trigger/trigger_central.h @@ -48,8 +48,12 @@ struct MapState { current = mapBuffer.sum(engineConfiguration->mapCamAveragingLength); } - bool isPeak() { - return previous > prevPrevious && previous >= current; + bool isPeak(bool lookForLowPeak) { + if (lookForLowPeak) { + return previous < prevPrevious && previous <= current; + } else { + return previous > prevPrevious && previous >= current; + } } }; diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index ceb12602f9..14590e4c41 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -893,7 +893,7 @@ custom maf_sensor_type_e 4 bits, S32, @OFFSET@, [0:1], @@maf_sensor_type_e_enum@ bit enableInnovateLC2 bit showHumanReadableWarning bit stftIgnoreErrorMagnitude;+If enabled, adjust at a constant rate instead of a rate proportional to the current lambda error. This mode may be easier to tune, and more tolerant of sensor noise. Use of this mode is required if you have a narrowband O2 sensor. - bit unused976b11 + bit mapCamLookForLowPeaks bit enableSoftwareKnock bit verboseVVTDecoding;enable vvt_details bit invertCamVVTSignal;get invertCamVVTSignal diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index 477e0b3134..b346ce53f2 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -3401,6 +3401,7 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00" field = "mapCamDetectionThreshold", mapCamDetectionThreshold field = "mapCamAveragingLength", mapCamAveragingLength field = "mapCamSkipFactor", mapCamSkipFactor + field = "mapCamLookForLowPeaks", mapCamLookForLowPeaks field = "#System hacks" field = "Global fuel correction", globalFuelCorrection field = "MAP Averaging Logic @", mapAveragingSchedulingAtIndex diff --git a/unit_tests/tests/trigger/test_map_cam.cpp b/unit_tests/tests/trigger/test_map_cam.cpp index 476abd4fce..15d3e9c4d8 100644 --- a/unit_tests/tests/trigger/test_map_cam.cpp +++ b/unit_tests/tests/trigger/test_map_cam.cpp @@ -29,22 +29,43 @@ TEST(trigger, map_cam) { MapState state; int i = 0; - for (;i<404;i++) { + for (;i<403;i++) { state.add(getZigZag(i)); if (state.mapBuffer.getCount() > engineConfiguration->mapCamAveragingLength) { - ASSERT_FALSE(state.isPeak()) << "At " << i; + ASSERT_FALSE(state.isPeak(false)) << "high At " << i; + ASSERT_FALSE(state.isPeak(true)) << "low At " << i; } } state.add(getZigZag(i)); - ASSERT_TRUE(state.isPeak()) << "At " << i; + ASSERT_FALSE(state.isPeak(false)) << "high At " << i; + ASSERT_FALSE(state.isPeak(true)) << "low At " << i; + i++; - for (;i<604;i++) { + + state.add(getZigZag(i)); + ASSERT_TRUE(state.isPeak(false)) << "high At " << i; + ASSERT_FALSE(state.isPeak(true)) << "low At " << i; + + for (;i<504;i++) { state.add(getZigZag(i)); - ASSERT_FALSE(state.isPeak()) << "At " << i; + ASSERT_FALSE(state.isPeak(false)) << "high At " << i; + ASSERT_FALSE(state.isPeak(true)) << "low At " << i; } state.add(getZigZag(i)); - ASSERT_TRUE(state.isPeak()) << "At " << i; + ASSERT_FALSE(state.isPeak(false)) << "high At " << i; + ASSERT_TRUE(state.isPeak(true)) << "low At " << i; + i++; + + for (;i<604;i++) { + state.add(getZigZag(i)); + ASSERT_FALSE(state.isPeak(false)) << "high At " << i; + ASSERT_FALSE(state.isPeak(true)) << "low At " << i; + } + + state.add(getZigZag(i)); + ASSERT_TRUE(state.isPeak(false)) << "high At " << i; + ASSERT_TRUE(state.isPeak(false)) << "low At " << i; }