From 94c29d4cfbfa4e4940e4c58c18bc3893a4a3ab8f Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Thu, 3 Aug 2023 00:52:19 -0700 Subject: [PATCH] simplify cam input single tooth modes (#178) --- .github/workflows/hw-ci/build_for_hw_ci.sh | 1 + firmware/CHANGELOG.md | 3 +++ .../hellen154hyundai/board_configuration.cpp | 4 ++-- firmware/config/engines/bmw_m73.cpp | 2 +- firmware/config/engines/test_engine.cpp | 2 +- firmware/controllers/algo/engine.cpp | 3 +-- firmware/controllers/algo/rusefi_enums.h | 8 ++------ firmware/controllers/trigger/trigger_central.cpp | 6 ++---- firmware/integration/rusefi_config.txt | 2 +- unit_tests/tests/trigger/test_cam_vvt_input.cpp | 14 +++++++------- unit_tests/tests/trigger/test_quad_cam.cpp | 6 +++--- .../tests/trigger/test_real_cas_24_plus_1.cpp | 2 +- 12 files changed, 25 insertions(+), 28 deletions(-) diff --git a/.github/workflows/hw-ci/build_for_hw_ci.sh b/.github/workflows/hw-ci/build_for_hw_ci.sh index a7372816c6..dcdf1dbb6b 100755 --- a/.github/workflows/hw-ci/build_for_hw_ci.sh +++ b/.github/workflows/hw-ci/build_for_hw_ci.sh @@ -13,6 +13,7 @@ echo "HW CI build [$HW_FOLDER][$HW_TARGET]" cd firmware ./gen_live_documentation.sh +./gen_enum_to_string.sh ./gen_config_board.sh $HW_FOLDER $HW_TARGET echo "We aren't guaranteed a clean machine every time, so manually clean the output." diff --git a/firmware/CHANGELOG.md b/firmware/CHANGELOG.md index 323e1d0be8..33d78786d7 100644 --- a/firmware/CHANGELOG.md +++ b/firmware/CHANGELOG.md @@ -28,6 +28,9 @@ Release template (copy/paste this for new release): ## Unreleased +### Breaking Changes + - Simplified VVT single tooth cam modes. "Single tooth second half" and "single tooth first half" have been replaced by simply "single tooth". This may require re-setting your trigger and VVT timing offsets if you used "single tooth first half" prior to this change. #178 + ### Added - Log per-cylinder true ignition timing (includes trim, knock retard, etc) #76 - Add mode for CLT/IAT sensors that are installed "high side" instead of typical "low side" #116 diff --git a/firmware/config/boards/hellen/hellen154hyundai/board_configuration.cpp b/firmware/config/boards/hellen/hellen154hyundai/board_configuration.cpp index a65db11661..1117ccaf4f 100644 --- a/firmware/config/boards/hellen/hellen154hyundai/board_configuration.cpp +++ b/firmware/config/boards/hellen/hellen154hyundai/board_configuration.cpp @@ -43,8 +43,8 @@ static void setupVbatt() { } static void setupDefaultSensorInputs() { - engineConfiguration->vvtMode[0] = VVT_SECOND_HALF; - engineConfiguration->vvtMode[1] = VVT_SECOND_HALF; + engineConfiguration->vvtMode[0] = VVT_SINGLE_TOOTH; + engineConfiguration->vvtMode[1] = VVT_SINGLE_TOOTH; engineConfiguration->vehicleSpeedSensorInputPin = H144_IN_VSS; diff --git a/firmware/config/engines/bmw_m73.cpp b/firmware/config/engines/bmw_m73.cpp index 33bc38f431..77821ed96e 100644 --- a/firmware/config/engines/bmw_m73.cpp +++ b/firmware/config/engines/bmw_m73.cpp @@ -97,7 +97,7 @@ void m73engine() { engineConfiguration->fuelAlgorithm = LM_ALPHA_N; engineConfiguration->canNbcType = CAN_BUS_NBC_NONE; - engineConfiguration->vvtMode[0] = VVT_FIRST_HALF; + engineConfiguration->vvtMode[0] = VVT_SINGLE_TOOTH; engineConfiguration->globalTriggerAngleOffset = 90; setCrankOperationMode(); diff --git a/firmware/config/engines/test_engine.cpp b/firmware/config/engines/test_engine.cpp index d8d2b561fc..9fd06cd62f 100644 --- a/firmware/config/engines/test_engine.cpp +++ b/firmware/config/engines/test_engine.cpp @@ -89,7 +89,7 @@ void setTestVVTEngineConfiguration() { // set global_trigger_offset_angle 0 engineConfiguration->globalTriggerAngleOffset = 0; - engineConfiguration->vvtMode[0] = VVT_SECOND_HALF; + engineConfiguration->vvtMode[0] = VVT_SINGLE_TOOTH; } #if EFI_UNIT_TEST diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index aad3ce0e90..7d83683426 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -76,8 +76,7 @@ trigger_type_e getVvtTriggerType(vvt_mode_e vvtMode) { case VVT_HONDA_K_EXHAUST: return trigger_type_e::TT_HONDA_K_CAM_4_1; case VVT_HONDA_K_INTAKE: - case VVT_FIRST_HALF: - case VVT_SECOND_HALF: + case VVT_SINGLE_TOOTH: case VVT_MAP_V_TWIN: return trigger_type_e::TT_ONE; case VVT_FORD_ST170: diff --git a/firmware/controllers/algo/rusefi_enums.h b/firmware/controllers/algo/rusefi_enums.h index aaff3d9563..be13f9e1c0 100644 --- a/firmware/controllers/algo/rusefi_enums.h +++ b/firmware/controllers/algo/rusefi_enums.h @@ -46,9 +46,9 @@ typedef enum __attribute__ ((__packed__)) { VVT_INACTIVE = 0, /** - * Single-tooth cam sensor mode where TDC and cam signal happen in opposite 360 degree of 720 degree engine cycle + * Single tooth on the camshaft anywhere in the 720 degree cycle */ - VVT_SECOND_HALF = 1, + VVT_SINGLE_TOOTH = 1, /** * Toyota 2JZ has three cam tooth. We pick one of these three tooth to synchronize based on the expected angle position of the event */ @@ -59,10 +59,6 @@ typedef enum __attribute__ ((__packed__)) { */ VVT_MIATA_NB = 3, - /** - * Single-tooth cam sensor mode where TDC and cam signal happen in the same 360 degree of 720 degree engine cycle - */ - VVT_FIRST_HALF = 4, /** * @see TT_VVT_BOSCH_QUICK_START */ diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index 2719d78d6b..868b6e57c1 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -112,8 +112,7 @@ static bool vvtWithRealDecoder(vvt_mode_e vvtMode) { && vvtMode != VVT_2JZ && vvtMode != VVT_HONDA_K_INTAKE && vvtMode != VVT_MAP_V_TWIN - && vvtMode != VVT_SECOND_HALF - && vvtMode != VVT_FIRST_HALF; + && vvtMode != VVT_SINGLE_TOOTH; } angle_t TriggerCentral::syncAndReport(int divider, int remainder) { @@ -165,12 +164,11 @@ static angle_t adjustCrankPhase(int camIndex) { vvt_mode_e vvtMode = engineConfiguration->vvtMode[camIndex]; switch (vvtMode) { - case VVT_FIRST_HALF: case VVT_MAP_V_TWIN: case VVT_MITSUBISHI_4G63: case VVT_MITSUBISHI_4G9x: return tc->syncAndReport(crankDivider, 1); - case VVT_SECOND_HALF: + case VVT_SINGLE_TOOTH: case VVT_NISSAN_VQ: case VVT_BOSCH_QUICK_START: case VVT_MIATA_NB: diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 5ad43a660a..dd62678e5f 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -270,7 +270,7 @@ end_struct #define debug_mode_e_enum "INVALID", "TPS acceleration enrichment", "INVALID", "Stepper Idle Control", "Engine Load accl enrich", "Trigger Counters", "Soft Spark Cut", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "SD card", "sr5", "Knock", "INVALID", "Electronic Throttle", "Executor", "Bench Test / TS commands", "INVALID", "Analog inputs #1", "INSTANT_RPM", "INVALID", "Status", "INVALID", "INVALID", "MAP", "Metrics", "INVALID", "Ion Sense", "TLE8888", "Analog inputs #2", "Dwell Metric", "INVALID", "INVALID", "Boost Control", "INVALID", "INVALID", "ETB Autotune", "Composite Log", "INVALID", "INVALID", "INVALID", "Dyno_View", "Logic_Analyzer", "INVALID", "TCU", "Lua" custom debug_mode_e 1 bits, U08, @OFFSET@, [0:5], @@debug_mode_e_enum@@ -#define vvt_mode_e_enum "Inactive", "Single Tooth Second Half", "2JZ", "Miata NB2", "Single Tooth First Half", "Bosch Quick Start", "4/1", "ST 170", "Ford Barra 3+1", "Nissan VQ", "Honda K Intake", "Nissan MR18", "Mitsu 3A92", "VTwin by MAP", "Mitsu 6G75", "Mazda Skyactiv", "Honda K Exhaust", "Mitsubishi 4G92/93/94", "Mitsubishi 4G63" +#define vvt_mode_e_enum "Inactive", "Single Tooth", "2JZ", "Miata NB2", "INVALID", "Bosch Quick Start", "4/1", "ST 170", "Ford Barra 3+1", "Nissan VQ", "Honda K Intake", "Nissan MR18", "Mitsu 3A92", "VTwin by MAP", "Mitsu 6G75", "Mazda Skyactiv", "Honda K Exhaust", "Mitsubishi 4G92/93/94", "Mitsubishi 4G63" custom vvt_mode_e 1 bits, U08, @OFFSET@, [0:5], @@vvt_mode_e_enum@@ ! At the moment TIM1, TIM2, TIM3 and TIM9 are configured as ICU diff --git a/unit_tests/tests/trigger/test_cam_vvt_input.cpp b/unit_tests/tests/trigger/test_cam_vvt_input.cpp index 58f99cc055..dee9bbabdd 100644 --- a/unit_tests/tests/trigger/test_cam_vvt_input.cpp +++ b/unit_tests/tests/trigger/test_cam_vvt_input.cpp @@ -84,7 +84,7 @@ TEST(trigger, testCamInput) { // changing to 'ONE TOOTH' trigger on CRANK with CAM/VVT setCrankOperationMode(); - engineConfiguration->vvtMode[0] = VVT_FIRST_HALF; + engineConfiguration->vvtMode[0] = VVT_SINGLE_TOOTH; engineConfiguration->vvtOffsets[0] = 360; eth.setTriggerType(trigger_type_e::TT_ONE); engineConfiguration->camInputs[0] = Gpio::A10; // we just need to indicate that we have CAM @@ -110,11 +110,6 @@ TEST(trigger, testCamInput) { unitTestWarningCodeState.recentWarnings.clear(); for (int i = 0; i < 600;i++) { - eth.moveTimeForwardUs(MS2US(25)); - - eth.firePrimaryTriggerRise(); - EXPECT_EQ(1200, round(Sensor::getOrZero(SensorType::Rpm))); - eth.moveTimeForwardUs(MS2US(10)); // cam comes every other crank rev @@ -123,12 +118,17 @@ TEST(trigger, testCamInput) { } eth.moveTimeForwardUs(MS2US(15)); + + eth.firePrimaryTriggerRise(); + EXPECT_EQ(1200, round(Sensor::getOrZero(SensorType::Rpm))); + + eth.moveTimeForwardUs(MS2US(25)); eth.firePrimaryTriggerFall(); } // asserting that error code has cleared ASSERT_EQ(0, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testCamInput #3"; - EXPECT_NEAR_M3(-109, engine->triggerCentral.getVVTPosition(0, 0)); + EXPECT_NEAR_M3(71, engine->triggerCentral.getVVTPosition(0, 0)); } TEST(trigger, testNB2CamInput) { diff --git a/unit_tests/tests/trigger/test_quad_cam.cpp b/unit_tests/tests/trigger/test_quad_cam.cpp index c4c1c5bf55..272afe7e5e 100644 --- a/unit_tests/tests/trigger/test_quad_cam.cpp +++ b/unit_tests/tests/trigger/test_quad_cam.cpp @@ -14,8 +14,8 @@ TEST(trigger, testQuadCam) { setCrankOperationMode(); // changing to 'ONE TOOTH' trigger on CRANK with CAM/VVT - engineConfiguration->vvtMode[0] = VVT_FIRST_HALF; - engineConfiguration->vvtMode[1] = VVT_FIRST_HALF; + engineConfiguration->vvtMode[0] = VVT_SINGLE_TOOTH; + engineConfiguration->vvtMode[1] = VVT_SINGLE_TOOTH; engineConfiguration->camInputs[0] = Gpio::A10; // we just need to indicate that we have CAM @@ -68,7 +68,7 @@ TEST(trigger, testQuadCam) { float basePos = -80.2f; // All four cams should now have the same position - EXPECT_NEAR_M3(360 + basePos, engine->triggerCentral.getVVTPosition(firstBank, firstCam)); + EXPECT_NEAR_M3(basePos, engine->triggerCentral.getVVTPosition(firstBank, firstCam)); EXPECT_NEAR_M3(basePos, engine->triggerCentral.getVVTPosition(firstBank, secondCam)); EXPECT_NEAR_M3(basePos, engine->triggerCentral.getVVTPosition(secondBank, firstCam)); EXPECT_NEAR_M3(basePos, engine->triggerCentral.getVVTPosition(secondBank, secondCam)); diff --git a/unit_tests/tests/trigger/test_real_cas_24_plus_1.cpp b/unit_tests/tests/trigger/test_real_cas_24_plus_1.cpp index 18185ad436..7dc4f97cd7 100644 --- a/unit_tests/tests/trigger/test_real_cas_24_plus_1.cpp +++ b/unit_tests/tests/trigger/test_real_cas_24_plus_1.cpp @@ -19,7 +19,7 @@ TEST(realCas24Plus1, spinningOnBench) { // 24 teeth at cam speed + 1 tooth // AKA 12 teeth at crank speed + 1 cam tooth - engineConfiguration->vvtMode[0] = VVT_SECOND_HALF; + engineConfiguration->vvtMode[0] = VVT_SINGLE_TOOTH; eth.setTriggerType(trigger_type_e::TT_12_TOOTH_CRANK); int eventCount = 0;