diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index 092ab6e9e3..425b7ca614 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -357,7 +357,9 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta // That's easy - trigger cycle matches engine cycle triggerIndexForListeners = triggerState.getCurrentIndex(); } else { - int crankDivider = operationMode == FOUR_STROKE_CRANK_SENSOR ? 2 : 4; + // 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 crankInternalIndex = triggerState.getTotalRevolutionCounter() % crankDivider; diff --git a/unit_tests/tests/test_cam_vtt_input.cpp b/unit_tests/tests/test_cam_vtt_input.cpp index 222810e024..396cb5152c 100644 --- a/unit_tests/tests/test_cam_vtt_input.cpp +++ b/unit_tests/tests/test_cam_vtt_input.cpp @@ -110,3 +110,21 @@ TEST(sensors, testCamInput) { ASSERT_EQ(0, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testCamInput #3"; } + +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); + + ASSERT_EQ( 0, GET_RPM()) << "testNB2CamInput RPM"; + for (int i = 0; i < 5;i++) { + eth.fireRise(50); + } + ASSERT_EQ(1200, GET_RPM()) << "testNB2CamInput RPM"; + + hwHandleVvtCamSignal(TV_FALL, getTimeNowNt() PASS_ENGINE_PARAMETER_SUFFIX); + eth.moveTimeForwardUs(MS2US(20)); + hwHandleVvtCamSignal(TV_RISE, getTimeNowNt() PASS_ENGINE_PARAMETER_SUFFIX); +}