diff --git a/firmware/config/engines/test_engine.cpp b/firmware/config/engines/test_engine.cpp index db8cfd425a..269c7d9d5d 100644 --- a/firmware/config/engines/test_engine.cpp +++ b/firmware/config/engines/test_engine.cpp @@ -13,11 +13,13 @@ EXTERN_ENGINE; void setTestEngineConfiguration(DECLARE_ENGINE_PARAMETER_F) { - engineConfiguration->trigger.type = TT_TOOTHED_WHEEL; +// engineConfiguration->trigger.type = TT_TOOTHED_WHEEL; + engineConfiguration->trigger.type = TT_ONE_PLUS_ONE; trigger_config_s *triggerConfig = &engineConfiguration->trigger; triggerConfig->customTotalToothCount = 60; triggerConfig->customSkippedToothCount = 0; + engineConfiguration->useOnlyFrontForTrigger = true; setOperationMode(engineConfiguration, FOUR_STROKE_CRANK_SENSOR); diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index c46912e41a..9ddddc7cd5 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -782,6 +782,9 @@ static void enableOrDisable(const char *param, bool isEnabled) { boardConfiguration->isFastAdcEnabled = isEnabled; } else if (strEqualCaseInsensitive(param, "stepperidle")) { boardConfiguration->useStepperIdle = isEnabled; + } else if (strEqualCaseInsensitive(param, "trigger_only_front")) { + engineConfiguration->useOnlyFrontForTrigger = isEnabled; + incrementGlobalConfigurationVersion(); } else if (strEqualCaseInsensitive(param, "two_wire_batch")) { engineConfiguration->twoWireBatch = isEnabled; incrementGlobalConfigurationVersion(); diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index b07078b53c..b921961088 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -43,7 +43,6 @@ EXTERN_ENGINE // todo: better name for this constant #define HELPER_PERIOD 100000 - #define NO_LEFT_FILTER -1 #define NO_RIGHT_FILTER 1000 @@ -122,7 +121,6 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, uint64_t now eventCount[triggerWheel]++; eventCountExt[signal]++; - uint64_t currentDurationLong = getCurrentGapDuration(nowNt); /** @@ -183,7 +181,8 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, uint64_t now /** * in case of noise the counter could be above the expected number of events */ - isSynchronizationPoint = !shaft_is_synchronized || (current_index >= TRIGGER_SHAPE(size) - 1); + int d = engineConfiguration->useOnlyFrontForTrigger ? 2 : 1; + isSynchronizationPoint = !shaft_is_synchronized || (current_index >= TRIGGER_SHAPE(size) - d); } @@ -235,8 +234,7 @@ float getEngineCycle(operation_mode_e operationMode) { } void addSkippedToothTriggerEvents(trigger_wheel_e wheel, TriggerShape *s, int totalTeethCount, int skippedCount, - float offset, - float engineCycle, float filterLeft, float filterRight) { + float offset, float engineCycle, float filterLeft, float filterRight) { float toothWidth = 0.5; for (int i = 0; i < totalTeethCount - skippedCount - 1; i++) { @@ -255,7 +253,6 @@ void initializeSkippedToothTriggerShapeExt(TriggerShape *s, int totalTeethCount, operation_mode_e operationMode) { efiAssertVoid(totalTeethCount > 0, "totalTeethCount is zero"); - s->totalToothCount = totalTeethCount; s->skippedToothCount = skippedCount; @@ -265,7 +262,8 @@ void initializeSkippedToothTriggerShapeExt(TriggerShape *s, int totalTeethCount, efiAssertVoid(s != NULL, "TriggerShape is NULL"); s->reset(operationMode, false); - addSkippedToothTriggerEvents(T_PRIMARY, s, totalTeethCount, skippedCount, 0, getEngineCycle(operationMode), NO_LEFT_FILTER, NO_RIGHT_FILTER); + addSkippedToothTriggerEvents(T_PRIMARY, s, totalTeethCount, skippedCount, 0, getEngineCycle(operationMode), + NO_LEFT_FILTER, NO_RIGHT_FILTER); } static void configureOnePlusOne(TriggerShape *s, operation_mode_e operationMode) { @@ -293,7 +291,8 @@ static void configureOnePlus60_2(TriggerShape *s, operation_mode_e operationMode s->addEvent(20, T_PRIMARY, TV_LOW); addSkippedToothTriggerEvents(T_SECONDARY, s, totalTeethCount, skippedCount, 0, 360, 20, NO_RIGHT_FILTER); - addSkippedToothTriggerEvents(T_SECONDARY, s, totalTeethCount, skippedCount, 360, 360, NO_LEFT_FILTER, NO_RIGHT_FILTER); + addSkippedToothTriggerEvents(T_SECONDARY, s, totalTeethCount, skippedCount, 360, 360, NO_LEFT_FILTER, + NO_RIGHT_FILTER); s->isSynchronizationNeeded = false; } @@ -398,21 +397,25 @@ void initializeTriggerShape(Logging *logger, engine_configuration_s const *engin } TriggerStimulatorHelper::TriggerStimulatorHelper() { - primaryWheelState = false; - secondaryWheelState = false; - thirdWheelState = false; } void TriggerStimulatorHelper::nextStep(TriggerState *state, TriggerShape * shape, int i, trigger_config_s const*triggerConfig DECLARE_ENGINE_PARAMETER_S) { int stateIndex = i % shape->getSize(); + int prevIndex = (stateIndex + shape->getSize() - 1 ) % shape->getSize(); + int loopIndex = i / shape->getSize(); int time = (int) (HELPER_PERIOD * (loopIndex + shape->wave.getSwitchTime(stateIndex))); + bool_t primaryWheelState = shape->wave.getChannelState(0, prevIndex); bool newPrimaryWheelState = shape->wave.getChannelState(0, stateIndex); + + bool_t secondaryWheelState = shape->wave.getChannelState(1, prevIndex); bool newSecondaryWheelState = shape->wave.getChannelState(1, stateIndex); + + bool_t thirdWheelState = shape->wave.getChannelState(2, prevIndex); bool new3rdWheelState = shape->wave.getChannelState(2, stateIndex); if (primaryWheelState != newPrimaryWheelState) { @@ -460,7 +463,7 @@ static uint32_t doFindTrigger(TriggerStimulatorHelper *helper, TriggerShape * sh * This function finds the index of synchronization event within TriggerShape */ uint32_t findTriggerZeroEventIndex(TriggerShape * shape, trigger_config_s const*triggerConfig - DECLARE_ENGINE_PARAMETER_S) { +DECLARE_ENGINE_PARAMETER_S) { // todo: should this variable be declared 'static' to reduce stack usage? TriggerState state; @@ -482,8 +485,13 @@ uint32_t findTriggerZeroEventIndex(TriggerShape * shape, trigger_config_s const* * todo: add a comment why are we doing '2 * shape->getSize()' here? */ state.cycleCallback = onFindIndex; - for (uint32_t i = index + 1; i <= index + 2 * shape->getSize(); i++) { + + int startIndex = engineConfiguration->useOnlyFrontForTrigger ? index + 2 : index + 1; + + for (uint32_t i = startIndex; i <= index + 2 * shape->getSize(); i++) { helper.nextStep(&state, shape, i, triggerConfig PASS_ENGINE_PARAMETER); + if (engineConfiguration->useOnlyFrontForTrigger) + i++; } efiAssert(state.getTotalRevolutionCounter() == 3, "totalRevolutionCounter2", EFI_ERROR_CODE); diff --git a/firmware/controllers/trigger/trigger_decoder.h b/firmware/controllers/trigger/trigger_decoder.h index 136dd53dd0..7691ca3e48 100644 --- a/firmware/controllers/trigger/trigger_decoder.h +++ b/firmware/controllers/trigger/trigger_decoder.h @@ -83,10 +83,6 @@ class TriggerStimulatorHelper { public: TriggerStimulatorHelper(); void nextStep(TriggerState *state, TriggerShape * shape, int i, trigger_config_s const*triggerConfig DECLARE_ENGINE_PARAMETER_S); -private: - bool primaryWheelState; - bool secondaryWheelState; - bool thirdWheelState; }; float getEngineCycle(operation_mode_e operationMode); diff --git a/unit_tests/test_trigger_decoder.cpp b/unit_tests/test_trigger_decoder.cpp index 62a3c01371..a7ea86ee85 100644 --- a/unit_tests/test_trigger_decoder.cpp +++ b/unit_tests/test_trigger_decoder.cpp @@ -516,7 +516,7 @@ void testTriggerDecoder(void) { test1995FordInline6TriggerDecoder(); testMazdaMianaNbDecoder(); - testTriggerDecoder2("test engine", TEST_ENGINE, 0, 0.5000, 0.0); + testTriggerDecoder2("test engine", TEST_ENGINE, 0, 0.0, 0.0); testTriggerDecoder2("testGY6_139QMB", GY6_139QMB, 0, 0.4375, 0.0); testTriggerDecoder2("testSubary", SUBARU_2003_WRX, 0, 0.4000, 0.0);