diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index e996112fc2..450678dc87 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -96,6 +96,8 @@ trigger_type_e getVvtTriggerType(vvt_mode_e vvtMode) { case VVT_MITSUBISHI_6G75: case VVT_NISSAN_MR: return TT_NISSAN_MR18_CAM_VVT; + case VVT_MITSUBISHI_4G63: + return TT_MITSU_ONLY_TOP_BOTH_FRONTS; default: firmwareError(OBD_PCM_Processor_Fault, "getVvtTriggerType for %s", getVvt_mode_e(vvtMode)); return TT_ONE; // we have to return something for the sake of -Werror=return-type diff --git a/firmware/controllers/algo/rusefi_enums.h b/firmware/controllers/algo/rusefi_enums.h index e1a90d4d50..8bdfe45482 100644 --- a/firmware/controllers/algo/rusefi_enums.h +++ b/firmware/controllers/algo/rusefi_enums.h @@ -107,6 +107,8 @@ typedef enum __attribute__ ((__packed__)) { */ VVT_HONDA_K_EXHAUST = 16, + VVT_MITSUBISHI_4G63 = 17, + } vvt_mode_e; /** diff --git a/firmware/controllers/trigger/decoders/trigger_mitsubishi.cpp b/firmware/controllers/trigger/decoders/trigger_mitsubishi.cpp index cf673f5dcc..21ec19073e 100644 --- a/firmware/controllers/trigger/decoders/trigger_mitsubishi.cpp +++ b/firmware/controllers/trigger/decoders/trigger_mitsubishi.cpp @@ -85,9 +85,13 @@ void initializeMitsubishi4g93_both_both(TriggerWaveform *s) { void initializeMitsubishi4g93_only_first_wheel_both_fronts(TriggerWaveform *s) { s->initialize(FOUR_STROKE_CAM_SENSOR, SyncEdge::Both); - s->setTriggerSynchronizationGap(3.2); + s->setSecondTriggerSynchronizationGap2(0.5, 2.3); + s->setTriggerSynchronizationGap2(0.1, 0.5); - addMitsu93(s, false); + s->addEvent720(180, TriggerValue::RISE, TriggerWheel::T_PRIMARY); + s->addEvent720(266, TriggerValue::FALL, TriggerWheel::T_PRIMARY); + s->addEvent720(641, TriggerValue::RISE, TriggerWheel::T_PRIMARY); + s->addEvent720(720, TriggerValue::FALL, TriggerWheel::T_PRIMARY); } void initialize36_2_1_1(TriggerWaveform *s) { diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index f224121d0e..fa246de63e 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -170,6 +170,7 @@ static angle_t adjustCrankPhase(int camIndex) { switch (vvtMode) { case VVT_FIRST_HALF: case VVT_MAP_V_TWIN: + case VVT_MITSUBISHI_4G63: return tc->syncAndReport(getCrankDivider(operationMode), 1); case VVT_SECOND_HALF: case VVT_NISSAN_VQ: diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 825b43fc14..6d22b868e0 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -307,8 +307,8 @@ custom debug_mode_e 1 bits, U08, @OFFSET@, [0:5], @@debug_mode_e_enum@@ #define VM_VVT_INACTIVE 0 -#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", "vvt17" -custom vvt_mode_e 1 bits, U08, @OFFSET@, [0:4], @@vvt_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", "Mitsu 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 ! todo: as of ChibiOS3, only channels 1 & 2 are allowed to capture input, that's a ChibiOS driver limitation diff --git a/unit_tests/tests/tests.mk b/unit_tests/tests/tests.mk index 7ac91e5737..aee55f9c7d 100644 --- a/unit_tests/tests/tests.mk +++ b/unit_tests/tests/tests.mk @@ -14,6 +14,7 @@ TESTS_SRC_CPP = \ tests/trigger/test_real_cranking_nissan_vq40.cpp \ tests/trigger/test_trigger_skipped_wheel.cpp \ tests/trigger/test_real_4b11.cpp \ + tests/trigger/test_real_4g63.cpp \ tests/trigger/test_real_volkswagen.cpp \ tests/trigger/test_real_nb2_cranking.cpp \ tests/trigger/test_real_gm_24x.cpp \ diff --git a/unit_tests/tests/trigger/resources/4g63-cranking.csv b/unit_tests/tests/trigger/resources/4g63-cranking.csv new file mode 100755 index 0000000000..17e57b3fc4 --- /dev/null +++ b/unit_tests/tests/trigger/resources/4g63-cranking.csv @@ -0,0 +1,199 @@ +Time[s], crank, cam +0.000000000000000, 1, 0 +1.494753000000000, 0, 0 +1.506921750000000, 1, 0 +1.612318250000000, 0, 0 +1.681612750000000, 0, 1 +1.732877500000000, 1, 1 +1.806291750000000, 0, 1 +1.861951000000000, 0, 0 +1.902313000000000, 1, 0 +1.970729250000000, 0, 0 +2.022872250000000, 0, 1 +2.059014000000000, 1, 1 +2.085412750000000, 1, 0 +2.119538000000000, 0, 0 +2.206066250000000, 1, 0 +2.266987500000000, 0, 0 +2.316638500000000, 0, 1 +2.352118750000000, 1, 1 +2.412216500000000, 0, 1 +2.460772750000000, 0, 0 +2.497370750000000, 1, 0 +2.559245750000000, 0, 0 +2.607990000000000, 0, 1 +2.642810000000000, 1, 1 +2.667487000000000, 1, 0 +2.700186500000000, 0, 0 +2.785114250000000, 1, 0 +2.844329000000000, 0, 0 +2.893034750000000, 0, 1 +2.927807250000000, 1, 1 +2.986567000000000, 0, 1 +3.034370750000000, 0, 0 +3.070484750000000, 1, 0 +3.131379250000000, 0, 0 +3.179887750000000, 0, 1 +3.214613250000000, 1, 1 +3.239370500000000, 1, 0 +3.271715250000000, 0, 0 +3.356859250000000, 1, 0 +3.415756750000000, 0, 0 +3.464241500000000, 0, 1 +3.498965250000000, 1, 1 +3.557156500000000, 0, 1 +3.604547500000000, 0, 0 +3.640645750000000, 1, 0 +3.701006250000000, 0, 0 +3.749165500000000, 0, 1 +3.783702750000000, 1, 1 +3.808099750000000, 1, 0 +3.840262750000000, 0, 0 +3.925541500000000, 1, 0 +3.984426500000000, 0, 0 +4.032156250000000, 0, 1 +4.066623000000000, 1, 1 +4.124483000000000, 0, 1 +4.171811000000000, 0, 0 +4.207782750000000, 1, 0 +4.267835499999999, 0, 0 +4.315820000000000, 0, 1 +4.350302000000000, 1, 1 +4.374738250000000, 1, 0 +4.406492249999999, 0, 0 +4.490840500000000, 1, 0 +4.549222750000000, 0, 0 +4.597310500000000, 0, 1 +4.631872500000000, 1, 1 +4.689966500000000, 0, 1 +4.737363750000000, 0, 0 +4.773538250000000, 1, 0 +4.834032500000000, 0, 0 +4.881681749999999, 0, 1 +4.915958000000000, 1, 1 +4.940247250000000, 1, 0 +4.972271000000000, 0, 0 +5.056390749999999, 1, 0 +5.114432250000000, 0, 0 +5.163234750000000, 0, 1 +5.198098000000000, 1, 1 +5.255806250000000, 0, 1 +5.303640000000000, 0, 0 +5.339906750000000, 1, 0 +5.399754499999999, 0, 0 +5.447633000000000, 0, 1 +5.482216250000000, 1, 1 +5.506672500000000, 1, 0 +5.538245750000000, 0, 0 +5.622610750000000, 1, 0 +5.680819250000000, 0, 0 +5.727998250000000, 0, 1 +5.761973250000000, 1, 1 +5.818899500000000, 0, 1 +5.865582499999999, 0, 0 +5.901025250000000, 1, 0 +5.960164750000000, 0, 0 +6.007168249999999, 0, 1 +6.041088999999999, 1, 1 +6.065072499999999, 1, 0 +6.096412000000000, 0, 0 +6.180311250000000, 1, 0 +6.237890500000000, 0, 0 +6.285459500000000, 0, 1 +6.319601250000000, 1, 1 +6.376443750000000, 0, 1 +6.422967250000000, 0, 0 +6.458396000000000, 1, 0 +6.517242749999999, 0, 0 +6.563905750000000, 0, 1 +6.597798999999999, 1, 1 +6.621518500000000, 1, 0 +6.652881499999999, 0, 0 +6.736140750000000, 1, 0 +6.793416250000000, 0, 0 +6.840612999999999, 0, 1 +6.874703250000000, 1, 1 +6.931303750000000, 0, 1 +6.977859250000000, 0, 0 +7.013473500000000, 1, 0 +7.072443750000000, 0, 0 +7.118917499999999, 0, 1 +7.152824250000000, 1, 1 +7.176675250000000, 1, 0 +7.207953250000000, 0, 0 +7.291758499999999, 1, 0 +7.349159750000000, 0, 0 +7.396515249999999, 0, 1 +7.430614250000000, 1, 1 +7.487187250000000, 0, 1 +7.533847000000000, 0, 0 +7.569177499999999, 1, 0 +7.627891999999999, 0, 0 +7.674611250000000, 0, 1 +7.708475999999999, 1, 1 +7.732335999999999, 1, 0 +7.763510500000000, 0, 0 +7.845901749999999, 1, 0 +7.902759250000000, 0, 0 +7.949735500000000, 0, 1 +7.983770000000000, 1, 1 +8.040103000000000, 0, 1 +8.086273000000000, 0, 0 +8.121497750000000, 1, 0 +8.179841000000000, 0, 0 +8.226068999999999, 0, 1 +8.259755999999999, 1, 1 +8.283215750000000, 1, 0 +8.314324250000000, 0, 0 +8.396975500000000, 1, 0 +8.453863750000000, 0, 0 +8.501026000000000, 0, 1 +8.534975500000000, 1, 1 +8.591211249999999, 0, 1 +8.637514749999999, 0, 0 +8.672692500000000, 1, 0 +8.731024750000000, 0, 0 +8.777467000000000, 0, 1 +8.811156499999999, 1, 1 +8.834794250000000, 1, 0 +8.865860500000000, 0, 0 +8.948499750000000, 1, 0 +9.005370500000000, 0, 0 +9.052408500000000, 0, 1 +9.086271750000000, 1, 1 +9.142514250000000, 0, 1 +9.188700250000000, 0, 0 +9.223915750000000, 1, 0 +9.282259500000000, 0, 0 +9.328291000000000, 0, 1 +9.361782500000000, 1, 1 +9.385013749999999, 1, 0 +9.416155000000000, 0, 0 +9.498853499999999, 1, 0 +9.555615749999999, 0, 0 +9.602765750000000, 0, 1 +9.636807250000000, 1, 1 +9.693013499999999, 0, 1 +9.739416250000000, 0, 0 +9.774776500000000, 1, 0 +9.833094250000000, 0, 0 +9.879419499999999, 0, 1 +9.913084500000000, 1, 1 +9.936648750000000, 1, 0 +9.967679250000000, 0, 0 +10.049862250000000, 1, 0 +10.106634500000000, 0, 0 +10.153670499999999, 0, 1 +10.187534749999999, 1, 1 +10.243663000000000, 0, 1 +10.289702499999999, 0, 0 +10.324709250000000, 1, 0 +10.382712500000000, 0, 0 +10.428939999999999, 0, 1 +10.462404249999999, 1, 1 +10.485657750000000, 1, 0 +10.573481749999999, 1, 1 +10.601926499999999, 0, 1 +12.630424750000000, 1, 1 +12.630433499999999, 0, 1 +12.630445499999999, 1, 1 diff --git a/unit_tests/tests/trigger/test_real_4g63.cpp b/unit_tests/tests/trigger/test_real_4g63.cpp new file mode 100644 index 0000000000..e19ccf16ee --- /dev/null +++ b/unit_tests/tests/trigger/test_real_4g63.cpp @@ -0,0 +1,55 @@ +// Mitsubishi 4G63 trigger pattern +// Crank: 2 teeth per rev (4 teeth per cycle) +// Cam: 4G63 pattern (big tooth - small tooth) + +#include "pch.h" + +#include "logicdata_csv_reader.h" + +TEST(real4g63, cranking) { + CsvReader reader(1, /* vvtCount */ 1); + + reader.open("tests/trigger/resources/4g63-cranking.csv"); + EngineTestHelper eth(TEST_ENGINE); + engineConfiguration->isFasterEngineSpinUpEnabled = true; + engineConfiguration->alwaysInstantRpm = true; + + engineConfiguration->isPhaseSyncRequiredForIgnition = true; + + engineConfiguration->vvtMode[0] = VVT_MITSUBISHI_4G63; + + engineConfiguration->trigger.customTotalToothCount = 2; + engineConfiguration->trigger.customSkippedToothCount = 0; + engineConfiguration->skippedWheelOnCam = false; + eth.setTriggerType(TT_TOOTHED_WHEEL); + + int eventCount = 0; + bool gotRpm = false; + bool gotSync = false; + + while (reader.haveMore()) { + reader.processLine(ð); + eventCount++; + engine->rpmCalculator.onSlowCallback(); + + // Expect that all teeth are in the correct spot + + auto rpm = Sensor::getOrZero(SensorType::Rpm); + if (!gotRpm && rpm) { + gotRpm = true; + + // We should get first RPM on exactly the first sync point - this means the instant RPM pre-sync event copy all worked OK + EXPECT_EQ(eventCount, 6); + EXPECT_NEAR(rpm, 132.77f, 0.1); + } + + if (!gotSync && engine->triggerCentral.triggerState.hasSynchronizedPhase()) { + gotSync = true; + + EXPECT_EQ(eventCount, 13); + EXPECT_NEAR(rpm, 191.45f, 0.1); + } + } + + ASSERT_EQ(0, eth.recentWarnings()->getCount()); +}