From f4b69659b962d211b4f03ec1e5b4d70e144ec0ce Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 13 Jul 2023 20:01:49 -0400 Subject: [PATCH] 3A92 not syncing (not happy Mitsubicha but another vehicle) #5401 --- .../trigger/decoders/trigger_mitsubishi.cpp | 30 ++++++++++++++----- .../trigger/decoders/trigger_mitsubishi.h | 1 + .../trigger/decoders/trigger_structure.cpp | 6 +++- .../trigger/decoders/trigger_structure.h | 8 +++++ .../controllers/trigger/trigger_decoder.cpp | 2 +- .../controllers/trigger/trigger_simulator.cpp | 2 +- 6 files changed, 38 insertions(+), 11 deletions(-) diff --git a/firmware/controllers/trigger/decoders/trigger_mitsubishi.cpp b/firmware/controllers/trigger/decoders/trigger_mitsubishi.cpp index a90787dd8d..b69961fb1c 100644 --- a/firmware/controllers/trigger/decoders/trigger_mitsubishi.cpp +++ b/firmware/controllers/trigger/decoders/trigger_mitsubishi.cpp @@ -59,17 +59,13 @@ void initializeMitsubishi4g63Cam(TriggerWaveform *s) { initializeMitsubishi4g9xCam(s); } -void initialize36_2_1_1(TriggerWaveform *s) { - s->initialize(FOUR_STROKE_CRANK_SENSOR, SyncEdge::RiseOnly); - s->tdcPosition = 90; - int totalTeethCount = 36; - - float engineCycle = FOUR_STROKE_ENGINE_CYCLE; +static void add36_2_1_1(TriggerWaveform *s, float engineCycle, float off) { float toothWidth = 0.5; - float oneTooth = 720 / totalTeethCount; + int totalTeethCount = 36; + float oneTooth = engineCycle / totalTeethCount; - float offset = (36 - 11 - 12 - 11) * oneTooth; + float offset = off + (36 - 11 - 12 - 11) * oneTooth; addSkippedToothTriggerEvents(TriggerWheel::T_PRIMARY, s, totalTeethCount, 0, toothWidth, /*offset*/offset, engineCycle, NO_LEFT_FILTER, offset + 11 * oneTooth + 1); @@ -84,6 +80,24 @@ void initialize36_2_1_1(TriggerWaveform *s) { addSkippedToothTriggerEvents(TriggerWheel::T_PRIMARY, s, totalTeethCount, 0, toothWidth, /*offset*/offset, engineCycle, NO_LEFT_FILTER, offset + 10 * oneTooth + 1); +} + +void initialize36_2_1_1(TriggerWaveform *s) { + s->initialize(FOUR_STROKE_CRANK_SENSOR, SyncEdge::RiseOnly); + s->tdcPosition = 90; + + add36_2_1_1(s, FOUR_STROKE_ENGINE_CYCLE, 0); + s->setTriggerSynchronizationGap(3); + s->setSecondTriggerSynchronizationGap(1); // redundancy +} + +void initialize36_2_1_1_3cyl(TriggerWaveform *s) { + s->initialize(FOUR_STROKE_CAM_SENSOR, SyncEdge::RiseOnly); + s->tdcPosition = 90; + s->isMitsubicha = true; + + add36_2_1_1(s, 360, 0); + add36_2_1_1(s, 360, 360); s->setTriggerSynchronizationGap(3); s->setSecondTriggerSynchronizationGap(1); // redundancy diff --git a/firmware/controllers/trigger/decoders/trigger_mitsubishi.h b/firmware/controllers/trigger/decoders/trigger_mitsubishi.h index 4bed667588..5be59342d3 100644 --- a/firmware/controllers/trigger/decoders/trigger_mitsubishi.h +++ b/firmware/controllers/trigger/decoders/trigger_mitsubishi.h @@ -17,6 +17,7 @@ void initializeMitsubishi4g9xCam(TriggerWaveform *s); void configureFordAspireTriggerWaveform(TriggerWaveform * s); void initialize36_2_1_1(TriggerWaveform *s); +void initialize36_2_1_1_3cyl(TriggerWaveform *s); void initialize36_2_1(TriggerWaveform *s); void initializeVvt3A92(TriggerWaveform *s); diff --git a/firmware/controllers/trigger/decoders/trigger_structure.cpp b/firmware/controllers/trigger/decoders/trigger_structure.cpp index 691723505b..37182db805 100644 --- a/firmware/controllers/trigger/decoders/trigger_structure.cpp +++ b/firmware/controllers/trigger/decoders/trigger_structure.cpp @@ -51,6 +51,7 @@ void TriggerWaveform::initialize(operation_mode_e operationMode, SyncEdge syncEd isSecondWheelCam = false; needSecondTriggerInput = false; shapeWithoutTdc = false; + isMitsubicha = false; // If RiseOnly, ignore falling edges completely. useOnlyRisingEdges = syncEdge == SyncEdge::RiseOnly; @@ -648,11 +649,14 @@ void TriggerWaveform::initializeTriggerWaveform(operation_mode_e triggerOperatio break; case trigger_type_e::TT_UNUSED_11: case trigger_type_e::TT_UNUSED_75: - case trigger_type_e::TT_UNUSED_78: case trigger_type_e::TT_MITSU_4G63_CAM: initializeMitsubishi4g63Cam(this); break; + case trigger_type_e::TT_UNUSED_78: + initialize36_2_1_1_3cyl(this); + break; + case trigger_type_e::TT_MITSU_4G9x_CAM: initializeMitsubishi4g9xCam(this); break; diff --git a/firmware/controllers/trigger/decoders/trigger_structure.h b/firmware/controllers/trigger/decoders/trigger_structure.h index 3ff8cc684f..29becb4ca0 100644 --- a/firmware/controllers/trigger/decoders/trigger_structure.h +++ b/firmware/controllers/trigger/decoders/trigger_structure.h @@ -82,6 +82,14 @@ public: * For example pick-up in distributor with mechanical ignition firing order control. */ bool shapeWithoutTdc = false; + + // 3 cylinder negatively affects sync on crank patter, let's handle it as a special kind of cam + bool isMitsubicha = false; + + int getMitsubichaMult() const { + return isMitsubicha ? 2 : 1; + } + /** * this flag tells us if we should ignore events on second input channel * that's the way to ignore noise from the disconnected wire diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index 6bef6e0592..382ff2e19a 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -304,7 +304,7 @@ bool TriggerDecoderBase::validateEventCounters(const TriggerWaveform& triggerSha // We can check if things are fine by comparing the number of events in a cycle with the expected number of event. bool isDecodingError = false; for (int i = 0;i < PWM_PHASE_MAX_WAVE_PER_PWM;i++) { - isDecodingError |= (currentCycle.eventCount[i] != triggerShape.getExpectedEventCount((TriggerWheel)i)); + isDecodingError |= (triggerShape.getMitsubichaMult() * currentCycle.eventCount[i] != triggerShape.getExpectedEventCount((TriggerWheel)i)); } #if EFI_UNIT_TEST diff --git a/firmware/controllers/trigger/trigger_simulator.cpp b/firmware/controllers/trigger/trigger_simulator.cpp index 223d3c5cae..870dd01322 100644 --- a/firmware/controllers/trigger/trigger_simulator.cpp +++ b/firmware/controllers/trigger/trigger_simulator.cpp @@ -107,7 +107,7 @@ void TriggerStimulatorHelper::assertSyncPosition( } int revolutionCounter = state.getCrankSynchronizationCounter(); - if (revolutionCounter != TEST_REVOLUTIONS) { + if (revolutionCounter != TEST_REVOLUTIONS * shape.getMitsubichaMult()) { warning(ObdCode::CUSTOM_OBD_TRIGGER_WAVEFORM, "sync failed/wrong gap parameters trigger=%s revolutionCounter=%d", getTrigger_type_e(triggerConfiguration.TriggerType.type), revolutionCounter);