diff --git a/unit_tests/tests/trigger/test_cam_vvt_input.cpp b/unit_tests/tests/trigger/test_cam_vvt_input.cpp index a169e87711..f1fa09ca69 100644 --- a/unit_tests/tests/trigger/test_cam_vvt_input.cpp +++ b/unit_tests/tests/trigger/test_cam_vvt_input.cpp @@ -121,9 +121,10 @@ TEST(sensors, testNB2CamInput) { WITH_ENGINE_TEST_HELPER(MAZDA_MIATA_2003); // this crank trigger would be easier to test, crank shape is less important for this test - engineConfiguration->useOnlyRisingEdgeForTrigger = true; eth.setTriggerType(TT_ONE PASS_ENGINE_PARAMETER_SUFFIX); + engineConfiguration->useOnlyRisingEdgeForTrigger = true; + ASSERT_EQ( 0, GET_RPM()) << "testNB2CamInput RPM"; for (int i = 0; i < 7;i++) { eth.fireRise(25); diff --git a/unit_tests/tests/trigger/test_quad_cam.cpp b/unit_tests/tests/trigger/test_quad_cam.cpp index 65c135dc02..03ad51dc91 100644 --- a/unit_tests/tests/trigger/test_quad_cam.cpp +++ b/unit_tests/tests/trigger/test_quad_cam.cpp @@ -10,14 +10,58 @@ TEST(trigger, testQuadCam) { WITH_ENGINE_TEST_HELPER(FORD_ESCORT_GT); // changing to 'ONE TOOTH' trigger on CRANK with CAM/VVT - setOperationMode(engineConfiguration, FOUR_STROKE_CRANK_SENSOR); +// setOperationMode(engineConfiguration, FOUR_STROKE_CRANK_SENSOR); engineConfiguration->useOnlyRisingEdgeForTrigger = true; - engineConfiguration->vvtMode = VVT_2JZ; - engineConfiguration->secondVvtMode = VVT_MIATA_NB2; +// engineConfiguration->vvtMode = VVT_2JZ; +// engineConfiguration->secondVvtMode = VVT_MIATA_NB2; + + engineConfiguration->vvtMode = VVT_MIATA_NB2; - eth.setTriggerType(TT_ONE PASS_ENGINE_PARAMETER_SUFFIX); engineConfiguration->camInputs[0] = GPIOA_10; // we just need to indicate that we have CAM - ASSERT_EQ( 0, GET_RPM()) << "testCamInput RPM"; + // this crank trigger would be easier to test, crank shape is less important for this test + eth.setTriggerType(TT_ONE PASS_ENGINE_PARAMETER_SUFFIX); + + engineConfiguration->useOnlyRisingEdgeForTrigger = true; + + ASSERT_EQ( 0, GET_RPM()) << "testQuadCam RPM no sync"; + for (int i = 0; i < 1;i++) { + eth.fireRise(25); + ASSERT_EQ( 0, GET_RPM()) << "testQuadCam RPM still no sync"; + } + eth.fireRise(25); + // first time we have RPM + ASSERT_EQ(4800, GET_RPM()) << "testQuadCam RPM"; + + int totalRevolutionCountBeforeVvtSync = 4; + // 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()); + + eth.moveTimeForwardUs(MS2US(3)); // shifting VVT phase a few angles + + float d = 4; + + // this would be ignored since we only consume the other kind of fronts here + hwHandleVvtCamSignal(TV_FALL, getTimeNowNt(), 0 PASS_ENGINE_PARAMETER_SUFFIX); + eth.moveTimeForwardUs(MS2US(20 / d)); + // this would be be first VVT signal - gap duration would be calculated against 'DEEP_IN_THE_PAST_SECONDS' initial value + hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), 0 PASS_ENGINE_PARAMETER_SUFFIX); + + eth.moveTimeForwardUs(MS2US(20 / d)); + // this second important front would give us first real VVT gap duration + hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), 0 PASS_ENGINE_PARAMETER_SUFFIX); + + ASSERT_FLOAT_EQ(0, engine->triggerCentral.getVVTPosition()); + ASSERT_EQ(totalRevolutionCountBeforeVvtSync, engine->triggerCentral.triggerState.getTotalRevolutionCounter()); + + eth.moveTimeForwardUs(MS2US(130 / d)); + // this third important front would give us first comparison between two real gaps + hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), 0 PASS_ENGINE_PARAMETER_SUFFIX); + + ASSERT_NEAR(-67.6 - 720 - 720 + 160.2, engine->triggerCentral.getVVTPosition(), EPS3D); + // actually position based on VVT! + ASSERT_EQ(totalRevolutionCountBeforeVvtSync, engine->triggerCentral.triggerState.getTotalRevolutionCounter()); }