diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 2aa0d96e54..b3774e5652 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -843,6 +843,6 @@ int getRusEfiVersion(void) { if (initBootloader() != 0) return 123; #endif /* EFI_BOOTLOADER_INCLUDE_CODE */ - return 201200211; + return 201200214; } #endif /* EFI_UNIT_TEST */ diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index 4cbd508835..09654f64ce 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -361,9 +361,7 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta // That's easy - trigger cycle matches engine cycle triggerIndexForListeners = triggerState.getCurrentIndex(); } else { - // todo: should this logic reuse getCycleDuration? - bool isCrankDriven = operationMode == FOUR_STROKE_CRANK_SENSOR || operationMode == FOUR_STROKE_SYMMETRICAL_CRANK_SENSOR; - int crankDivider = isCrankDriven ? 2 : 4; + int crankDivider = operationMode == FOUR_STROKE_CRANK_SENSOR ? 2 : SYMMETRICAL_CRANK_SENSOR_DIVIDER; int crankInternalIndex = triggerState.getTotalRevolutionCounter() % crankDivider; diff --git a/firmware/controllers/trigger/trigger_central.h b/firmware/controllers/trigger/trigger_central.h index c3c578bca7..0587a3a023 100644 --- a/firmware/controllers/trigger/trigger_central.h +++ b/firmware/controllers/trigger/trigger_central.h @@ -12,6 +12,8 @@ #include "trigger_decoder.h" #include "trigger_central_generated.h" + + class Engine; typedef void (*ShaftPositionListener)(trigger_event_e signal, uint32_t index, efitick_t edgeTimestamp DECLARE_ENGINE_PARAMETER_SUFFIX); @@ -79,3 +81,4 @@ void onConfigurationChangeTriggerCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE); bool checkIfTriggerConfigChanged(DECLARE_ENGINE_PARAMETER_SIGNATURE); bool isTriggerConfigChanged(DECLARE_ENGINE_PARAMETER_SIGNATURE); +#define SYMMETRICAL_CRANK_SENSOR_DIVIDER 4 diff --git a/unit_tests/tests/test_cam_vtt_input.cpp b/unit_tests/tests/test_cam_vtt_input.cpp index fddfeb1c3e..1add03ace1 100644 --- a/unit_tests/tests/test_cam_vtt_input.cpp +++ b/unit_tests/tests/test_cam_vtt_input.cpp @@ -123,12 +123,24 @@ TEST(sensors, testNB2CamInput) { eth.setTriggerType(TT_ONE PASS_ENGINE_PARAMETER_SUFFIX); ASSERT_EQ( 0, GET_RPM()) << "testNB2CamInput RPM"; - for (int i = 0; i < 5;i++) { - eth.fireRise(50); + for (int i = 0; i < 7;i++) { + eth.fireRise(25); + ASSERT_EQ( 0, GET_RPM()) << "testNB2CamInput RPM"; } + eth.fireRise(25); + // first time we have RPM ASSERT_EQ(1200, GET_RPM()) << "testNB2CamInput RPM"; - // this would be ignored since we only consude one kind the other kind of fronts here + int totalRevolutionCountBeforeVvtSync = 10; + // need to be out of VVT sync to see VVT sync in action + eth.fireRise(25); + eth.fireRise(25); + ASSERT_EQ(totalRevolutionCountBeforeVvtSync, engine->triggerCentral.triggerState.getTotalRevolutionCounter()); + ASSERT_TRUE((totalRevolutionCountBeforeVvtSync % SYMMETRICAL_CRANK_SENSOR_DIVIDER) != 0); + + eth.moveTimeForwardUs(MS2US(3)); // shifting VVT phase a few anlges + + // this would be ignored since we only consume the other kind of fronts here hwHandleVvtCamSignal(TV_FALL, getTimeNowNt() PASS_ENGINE_PARAMETER_SUFFIX); eth.moveTimeForwardUs(MS2US(20)); // this would be be first VVT signal - gap duration would be calculated against 'DEEP_IN_THE_PAST_SECONDS' initial value @@ -139,13 +151,13 @@ TEST(sensors, testNB2CamInput) { hwHandleVvtCamSignal(TV_RISE, getTimeNowNt() PASS_ENGINE_PARAMETER_SUFFIX); ASSERT_FLOAT_EQ(0, engine->triggerCentral.getVVTPosition()); - ASSERT_EQ(5, engine->triggerCentral.triggerState.getTotalRevolutionCounter()); + ASSERT_EQ(totalRevolutionCountBeforeVvtSync, engine->triggerCentral.triggerState.getTotalRevolutionCounter()); eth.moveTimeForwardUs(MS2US(130)); // this third important front would give us first comparison between two real gaps hwHandleVvtCamSignal(TV_RISE, getTimeNowNt() PASS_ENGINE_PARAMETER_SUFFIX); - ASSERT_NEAR(-46, engine->triggerCentral.getVVTPosition(), EPS3D); + ASSERT_NEAR(-67.6, engine->triggerCentral.getVVTPosition(), EPS3D); // actually position based on VVT! - ASSERT_EQ(8, engine->triggerCentral.triggerState.getTotalRevolutionCounter()); + ASSERT_EQ(totalRevolutionCountBeforeVvtSync + 2, engine->triggerCentral.triggerState.getTotalRevolutionCounter()); }