diff --git a/firmware/controllers/algo/obd_error_codes.h b/firmware/controllers/algo/obd_error_codes.h index d6b5834356..70517a2e42 100644 --- a/firmware/controllers/algo/obd_error_codes.h +++ b/firmware/controllers/algo/obd_error_codes.h @@ -2083,7 +2083,7 @@ typedef enum { CUSTOM_NO_ETB_FOR_IDLE = 6723, CUSTOM_ERR_6724 = 6724, CUSTOM_ERR_6725 = 6725, - CUSTOM_ERR_6726 = 6726, + CUSTOM_ERR_VVT_OUT_OF_RANGE = 6726, CUSTOM_ERR_6727 = 6727, CUSTOM_ERR_6728 = 6728, CUSTOM_ERR_6729 = 6729, diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index 1a3650330f..149a052436 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -208,9 +208,12 @@ void hwHandleVvtCamSignal(trigger_value_e front, efitick_t nowNt DECLARE_ENGINE_ tc->vvtSyncTimeNt = nowNt; - float vvtPosition = engineConfiguration->vvtOffset - currentPosition; - fixAngle(vvtPosition, "vvtPosition", CUSTOM_ERR_6556); - tc->vvtPosition = vvtPosition; + // we do NOT clamp VVT position into the [0, engineCycle) range - we expect vvtOffset to be configured so that + // it's not necessary + tc->vvtPosition = engineConfiguration->vvtOffset - currentPosition; + if (tc->vvtPosition < 0 || tc->vvtPosition > ENGINE(engineCycle)) { + warning(CUSTOM_ERR_VVT_OUT_OF_RANGE, "Please adjust vvtOffset since position %f", tc->vvtPosition); + } switch (engineConfiguration->vvtMode) { case VVT_FIRST_HALF: diff --git a/unit_tests/tests/trigger/test_cam_vvt_input.cpp b/unit_tests/tests/trigger/test_cam_vvt_input.cpp index 5e6588fa2f..dec3da07e2 100644 --- a/unit_tests/tests/trigger/test_cam_vvt_input.cpp +++ b/unit_tests/tests/trigger/test_cam_vvt_input.cpp @@ -83,6 +83,7 @@ TEST(sensors, testCamInput) { setOperationMode(engineConfiguration, FOUR_STROKE_CRANK_SENSOR); engineConfiguration->useOnlyRisingEdgeForTrigger = true; engineConfiguration->vvtMode = VVT_FIRST_HALF; + engineConfiguration->vvtOffset = 720; eth.setTriggerType(TT_ONE PASS_ENGINE_PARAMETER_SUFFIX); engineConfiguration->camInputs[0] = GPIOA_10; // we just need to indicate that we have CAM @@ -113,7 +114,7 @@ TEST(sensors, testCamInput) { // asserting that error code has cleared ASSERT_EQ(0, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testCamInput #3"; - ASSERT_NEAR(-181, engine->triggerCentral.getVVTPosition(), EPS3D); + ASSERT_NEAR(720 - 181, engine->triggerCentral.getVVTPosition(), EPS3D); } TEST(sensors, testNB2CamInput) {