diff --git a/firmware/console/binary/output_channels.txt b/firmware/console/binary/output_channels.txt index 3fce177625..1bb0ff4a83 100644 --- a/firmware/console/binary/output_channels.txt +++ b/firmware/console/binary/output_channels.txt @@ -310,9 +310,6 @@ uint8_t unusedWat uint8_t autoscale boostControllerOutput;@@GAUGE_NAME_BOOST_OUTPUT@@;"%", 0.5, 0, 0, 100, 1 uint8_t autoscale boostControllerOpenLoopPart;@@GAUGE_NAME_BOOST_OPEN_LOOP@@;"%", 0.5, 0, 0, 100, 1 - - float autoscale triggerSyncGapRatio;@@GAUGE_NAME_TRG_GAP@@;"", 1, 0, -10000, 10000, 3 - uint16_t autoscale fallbackMap;;"kPa", 0.1, 0, 0, 1000, 1 int8_t autoscale boostControllerClosedLoopPart;@@GAUGE_NAME_BOOST_CLOSED_LOOP@@;"%", 0.5, 0, -50, 50, 1 diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index 2fc696ffd6..f002953048 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -115,7 +115,7 @@ static angle_t syncAndReport(TriggerCentral *tc, int divider, int remainder) { angle_t offset = tc->triggerState.syncSymmetricalCrank(divider, remainder, engineCycle); if (offset > 0) { - engine->outputChannels.vvtSyncCounter++; + tc->triggerState.vvtSyncCounter++; } return offset; } @@ -292,8 +292,8 @@ void hwHandleVvtCamSignal(trigger_value_e front, efitick_t nowNt, int index) { engine->vvtTriggerConfiguration[camIndex], front == TV_RISE ? SHAFT_PRIMARY_RISING : SHAFT_PRIMARY_FALLING, nowNt); // yes we log data from all VVT channels into same fields for now - engine->outputChannels.vvtSyncGapRatio = vvtState->currentGap; - engine->outputChannels.vvtStateIndex = vvtState->currentCycle.current_index; + tc->triggerState.vvtSyncGapRatio = vvtState->triggerSyncGapRatio; + tc->triggerState.vvtStateIndex = vvtState->currentCycle.current_index; } tc->vvtCamCounter++; @@ -314,9 +314,7 @@ void hwHandleVvtCamSignal(trigger_value_e front, efitick_t nowNt, int index) { tc->currentVVTEventPosition[bankIndex][camIndex] = currentPosition; #endif // EFI_UNIT_TEST -#if EFI_TUNER_STUDIO - engine->outputChannels.vvtCurrentPosition = currentPosition; -#endif /* EFI_TUNER_STUDIO */ + tc->triggerState.vvtCurrentPosition = currentPosition; if (isVvtWithRealDecoder && tc->vvtState[bankIndex][camIndex].currentCycle.current_index != 0) { // this is not sync tooth - exiting @@ -337,9 +335,7 @@ void hwHandleVvtCamSignal(trigger_value_e front, efitick_t nowNt, int index) { break; } -#if EFI_TUNER_STUDIO - engine->outputChannels.vvtCounter++; -#endif /* EFI_TUNER_STUDIO */ + tc->triggerState.vvtCounter++; auto vvtPosition = engineConfiguration->vvtOffsets[bankIndex * CAMS_PER_BANK + camIndex] - currentPosition; @@ -627,10 +623,8 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta engine->primaryTriggerConfiguration, signal, timestamp); -#if EFI_TUNER_STUDIO - engine->outputChannels.triggerSyncGapRatio = triggerState.currentGap; - engine->outputChannels.triggerStateIndex = triggerState.currentCycle.current_index; -#endif /* EFI_TUNER_STUDIO */ + + triggerState.triggerStateIndex = triggerState.currentCycle.current_index; /** diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index f9d784cac5..749aef53c2 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -561,7 +561,7 @@ void TriggerState::decodeTriggerEvent( bool wasSynchronized = getShaftSynchronized(); if (triggerShape.isSynchronizationNeeded) { - currentGap = (float)toothDurations[0] / toothDurations[1]; + triggerSyncGapRatio = (float)toothDurations[0] / toothDurations[1]; isSynchronizationPoint = isSyncPoint(triggerShape, triggerConfiguration.TriggerType); if (isSynchronizationPoint) { @@ -576,7 +576,7 @@ void TriggerState::decodeTriggerEvent( bool silentTriggerError = triggerShape.getSize() > 40 && engineConfiguration->silentTriggerError; #if EFI_UNIT_TEST - actualSynchGap = currentGap; + actualSynchGap = triggerSyncGapRatio; #endif /* EFI_UNIT_TEST */ #if EFI_PROD_CODE || EFI_SIMULATOR @@ -718,7 +718,7 @@ bool TriggerState::isSyncPoint(const TriggerWaveform& triggerShape, trigger_type if (triggerType == TT_MIATA_VVT) { auto secondGap = (float)toothDurations[1] / toothDurations[2]; - bool currentGapOk = isInRange(triggerShape.syncronizationRatioFrom[0], currentGap, triggerShape.syncronizationRatioTo[0]); + bool currentGapOk = isInRange(triggerShape.syncronizationRatioFrom[0], triggerSyncGapRatio, triggerShape.syncronizationRatioTo[0]); bool secondGapOk = isInRange(triggerShape.syncronizationRatioFrom[1], secondGap, triggerShape.syncronizationRatioTo[1]); // One or both teeth was impossible range, this is not the sync point @@ -728,7 +728,7 @@ bool TriggerState::isSyncPoint(const TriggerWaveform& triggerShape, trigger_type // If both teeth are in the range of possibility, return whether this gap is // shorter than the last or not. If it is, this is the sync point. - return currentGap < secondGap; + return triggerSyncGapRatio < secondGap; } for (int i = 0; i < triggerShape.gapTrackingLength; i++) { diff --git a/firmware/controllers/trigger/trigger_decoder.h b/firmware/controllers/trigger/trigger_decoder.h index 9dbccc9a6b..5867143299 100644 --- a/firmware/controllers/trigger/trigger_decoder.h +++ b/firmware/controllers/trigger/trigger_decoder.h @@ -174,6 +174,7 @@ private: bool isFirstEvent; bool m_hasSynchronizedSymmetrical = false; + Timer synchronizedSymmetrical; }; // we only need 90 degrees of events so /4 or maybe even /8 should work? diff --git a/firmware/controllers/trigger/trigger_state.txt b/firmware/controllers/trigger/trigger_state.txt index 5442e5f2d2..5f22eb4167 100644 --- a/firmware/controllers/trigger/trigger_state.txt +++ b/firmware/controllers/trigger/trigger_state.txt @@ -1,8 +1,9 @@ struct_no_prefix trigger_state_s - float currentGap; uint32_t totalRevolutionCounter;Crank revolution counter float autoscale vvtSyncGapRatio;;"", 1, 0, -10000, 10000, 3 float autoscale vvtCurrentPosition;;"", 1, 0, -10000, 10000, 3 + float autoscale triggerSyncGapRatio;@@GAUGE_NAME_TRG_GAP@@;"", 1, 0, -10000, 10000, 3 + float triggerActualSyncGapRatio; uint8_t triggerStateIndex uint8_t vvtCounter diff --git a/firmware/controllers/trigger/trigger_state_generated.h b/firmware/controllers/trigger/trigger_state_generated.h index 7c107acb5c..b608f1622b 100644 --- a/firmware/controllers/trigger/trigger_state_generated.h +++ b/firmware/controllers/trigger/trigger_state_generated.h @@ -8,7 +8,7 @@ struct trigger_state_s { /** * offset 0 */ - float currentGap = (float)0; + float triggerSyncGapRatio = (float)0; /** * Crank revolution counter * offset 4 diff --git a/unit_tests/tests/trigger/test_map_cam.cpp b/unit_tests/tests/trigger/test_map_cam.cpp index 31679a1e6e..ac581a99b0 100644 --- a/unit_tests/tests/trigger/test_map_cam.cpp +++ b/unit_tests/tests/trigger/test_map_cam.cpp @@ -25,7 +25,7 @@ TEST(trigger, map_cam_by_magic_point) { ASSERT_EQ(150, Sensor::getOrZero(SensorType::Rpm)) << "RPM"; ASSERT_EQ(1, engine->triggerCentral.mapVvt_map_peak); - ASSERT_EQ(0, engine->outputChannels.vvtSyncCounter); + ASSERT_EQ(0, engine->triggerCentral.triggerState.vvtSyncCounter); // Nothing should have been scheduled yet ASSERT_EQ(1, engine->executor.size()); @@ -36,7 +36,7 @@ TEST(trigger, map_cam_by_magic_point) { eth.smartFireTriggerEvents2(/*count*/4, /*delayMs*/200); ASSERT_EQ(2, engine->triggerCentral.mapVvt_map_peak); - ASSERT_EQ(1, engine->outputChannels.vvtSyncCounter); + ASSERT_EQ(1, engine->triggerCentral.triggerState.vvtSyncCounter); ASSERT_EQ(10, engine->triggerCentral.mapVvt_MAP_AT_CYCLE_COUNT); ASSERT_EQ(ClearReason::None, eth.engine.limpManager.allowIgnition().reason); diff --git a/unit_tests/tests/trigger/test_real_nb2_cranking.cpp b/unit_tests/tests/trigger/test_real_nb2_cranking.cpp index bee0d42b8e..145f86c3b2 100644 --- a/unit_tests/tests/trigger/test_real_nb2_cranking.cpp +++ b/unit_tests/tests/trigger/test_real_nb2_cranking.cpp @@ -24,7 +24,7 @@ TEST(realCrankingNB2, normalCranking) { // Check the number of times VVT information was used to adjust crank phase // This should happen exactly once: once we sync, we shouldn't lose it. - EXPECT_EQ(engine->outputChannels.vvtSyncCounter, 1); + EXPECT_EQ(engine->triggerCentral.triggerState.vvtSyncCounter, 1); ASSERT_EQ(942, round(Sensor::getOrZero(SensorType::Rpm)));