diff --git a/firmware/config/engines/ford_aspire.cpp b/firmware/config/engines/ford_aspire.cpp index eb3be02095..17deb42f22 100644 --- a/firmware/config/engines/ford_aspire.cpp +++ b/firmware/config/engines/ford_aspire.cpp @@ -118,6 +118,7 @@ void setFordAspireEngineConfiguration(DECLARE_ENGINE_PARAMETER_F) { setSingleCoilDwell(engineConfiguration); engineConfiguration->ignitionMode = IM_ONE_COIL; setOperationMode(engineConfiguration, FOUR_STROKE_CAM_SENSOR); + engineConfiguration->useOnlyFrontForTrigger = true; engineConfiguration->trigger.type = TT_FORD_ASPIRE; boardConfiguration->injectionPins[4] = GPIO_UNASSIGNED; diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index a5ca7622b6..b47cde1248 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -370,8 +370,10 @@ void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_F) { } for (int angle = 0; angle < CONFIG(engineCycle); angle++) { - int triggerIndex = findAngleIndex(angle PASS_ENGINE_PARAMETER); - TRIGGER_SHAPE(triggerIndexByAngle[angle])= engineConfiguration->useOnlyFrontForTrigger ? TRIGGER_SHAPE(frontOnlyIndexes[triggerIndex]) : triggerIndex; + int triggerShapeIndex = findAngleIndex(angle PASS_ENGINE_PARAMETER); + if (engineConfiguration->useOnlyFrontForTrigger) + triggerShapeIndex = triggerShapeIndex & 0xFFFFFFFE; // we need even index for front_only + TRIGGER_SHAPE(triggerIndexByAngle[angle]) = triggerShapeIndex; } engineConfiguration2->crankingInjectionEvents.addFuelEvents(&crankingInjectonSignals, diff --git a/firmware/controllers/trigger/trigger_structure.cpp b/firmware/controllers/trigger/trigger_structure.cpp index c39ccd871f..11ccac1f91 100644 --- a/firmware/controllers/trigger/trigger_structure.cpp +++ b/firmware/controllers/trigger/trigger_structure.cpp @@ -44,11 +44,10 @@ TriggerShape::TriggerShape() : tdcPosition = 0; skippedToothCount = totalToothCount = 0; syncRatioFrom = syncRatioTo = 0; + memset(eventAngles, 0, sizeof(eventAngles)); memset(frontOnlyIndexes, 0, sizeof(frontOnlyIndexes)); memset(isFrontEvent, 0, sizeof(isFrontEvent)); memset(triggerIndexByAngle, 0, sizeof(triggerIndexByAngle)); - - } int TriggerShape::getSize() const { @@ -74,15 +73,24 @@ void TriggerShape::calculateTriggerSynchPoint(DECLARE_ENGINE_PARAMETER_F) { if (eventIndex == 0) { // explicit check for zero to avoid issues where logical zero is not exactly zero due to float nature eventAngles[0] = 0; + // this value would be used in case of front-only + eventAngles[1] = 0; frontOnlyIndexes[0] = 0; } else { int triggerDefinitionCoordinate = (triggerShapeSynchPointIndex + eventIndex) % engine->engineCycleEventCount; int triggerDefinitionIndex = triggerDefinitionCoordinate >= size ? triggerDefinitionCoordinate - size : triggerDefinitionCoordinate; - if (isFrontEvent[triggerDefinitionIndex]) - frontOnlyIndex += 2; float angle = getAngle(triggerDefinitionCoordinate) - firstAngle; fixAngle(angle); - eventAngles[eventIndex] = angle; + if (engineConfiguration->useOnlyFrontForTrigger) { + if (isFrontEvent[triggerDefinitionIndex]) { + frontOnlyIndex += 2; + eventAngles[frontOnlyIndex] = angle; + eventAngles[frontOnlyIndex + 1] = angle; + } + } else { + eventAngles[eventIndex] = angle; + } + frontOnlyIndexes[eventIndex] = frontOnlyIndex; } } @@ -268,6 +276,7 @@ void TriggerShape::addEvent(float angle, trigger_wheel_e const waveIndex, trigge wave->pinStates[0] = initialState[i]; } + isFrontEvent[0] = TV_HIGH == stateParam; wave.setSwitchTime(0, angle); wave.waves[waveIndex].pinStates[0] = state; return; diff --git a/firmware/tunerstudio/rusefi.ini b/firmware/tunerstudio/rusefi.ini index 77de51f7d7..b3fc43a390 100644 --- a/firmware/tunerstudio/rusefi.ini +++ b/firmware/tunerstudio/rusefi.ini @@ -946,6 +946,7 @@ fileVersion = { 20150406 } field = "Firing Order", firingOrder field = "Injection Mode", injectionMode field = " Two wire batch", twoWireBatch, {injectionMode == 2} + field = " use only front", useOnlyFrontForTrigger field = "Ignition Mode", ignitionMode field = "Timing Mode", timingMode field = "" diff --git a/unit_tests/test_fuel_map.cpp b/unit_tests/test_fuel_map.cpp index d5a796f7c4..69fafca20a 100644 --- a/unit_tests/test_fuel_map.cpp +++ b/unit_tests/test_fuel_map.cpp @@ -171,14 +171,12 @@ void testAngleResolver(void) { assertTrue(engine->engineConfiguration2!=NULL); TriggerShape * ts = &engine->triggerShape; - confgiureFordAspireTriggerShape(ts); - ts->calculateTriggerSynchPoint(PASS_ENGINE_PARAMETER_F); - assertEqualsM("index 2", 228.0450, ts->eventAngles[3]); // this angle is relation to synch point + assertEqualsM("index 2", 52.76, ts->eventAngles[3]); // this angle is relation to synch point assertEqualsM("time 2", 0.3233, ts->wave.getSwitchTime(2)); - assertEqualsM("index 5", 413.7470, ts->eventAngles[6]); - assertEqualsM("time 5", 0.5692, ts->wave.getSwitchTime(5)); + assertEqualsM("index 5", 412.76, ts->eventAngles[6]); + assertEqualsM("time 5", 0.5733, ts->wave.getSwitchTime(5)); assertEquals(4, ts->getTriggerShapeSynchPointIndex()); @@ -190,40 +188,41 @@ void testAngleResolver(void) { printf("*************************************************** testAngleResolver 0\r\n"); findTriggerPosition(&ae.add()->injectionStart, -122 PASS_ENGINE_PARAMETER); assertEqualsM("size", 1, ae.size); -// assertEquals(0, ae.elements[0].injectionStart.eventIndex); -// assertEquals(53, ae.elements[0].injectionStart.angleOffset); - assertEquals(1, ae.elements[0].injectionStart.eventIndex); - assertEquals(3.1588, ae.elements[0].injectionStart.angleOffset); + assertEquals(2, ae.elements[0].injectionStart.eventIndex); + assertEquals(0.24, ae.elements[0].injectionStart.angleOffset); printf("*************************************************** testAngleResolver 0.1\r\n"); ae.reset(); findTriggerPosition(&ae.add()->injectionStart, -80 PASS_ENGINE_PARAMETER); - assertEquals(1, ae.elements[0].injectionStart.eventIndex); - assertEquals(45.1588, ae.elements[0].injectionStart.angleOffset); + assertEquals(2, ae.elements[0].injectionStart.eventIndex); + assertEquals(42.24, ae.elements[0].injectionStart.angleOffset); printf("*************************************************** testAngleResolver 0.2\r\n"); ae.reset(); findTriggerPosition(&ae.add()->injectionStart, -54 PASS_ENGINE_PARAMETER); - assertEquals(1, ae.elements[0].injectionStart.eventIndex); - assertEquals(71.1588, ae.elements[0].injectionStart.angleOffset); + assertEquals(2, ae.elements[0].injectionStart.eventIndex); + assertEquals(68.2400, ae.elements[0].injectionStart.angleOffset); printf("*************************************************** testAngleResolver 0.3\r\n"); ae.reset(); findTriggerPosition(&ae.add()->injectionStart, -53 PASS_ENGINE_PARAMETER); assertEquals(2, ae.elements[0].injectionStart.eventIndex); - assertEquals(3.3495, ae.elements[0].injectionStart.angleOffset); + assertEquals(69.24, ae.elements[0].injectionStart.angleOffset); printf("*************************************************** testAngleResolver 1\r\n"); ae.reset(); findTriggerPosition(&ae.add()->injectionStart, 0 PASS_ENGINE_PARAMETER); assertEquals(2, ae.elements[0].injectionStart.eventIndex); - assertEquals(56.3495, ae.elements[0].injectionStart.angleOffset); + assertEquals(122.24, ae.elements[0].injectionStart.angleOffset); printf("*************************************************** testAngleResolver 2\r\n"); ae.reset(); findTriggerPosition(&ae.add()->injectionStart, 56 PASS_ENGINE_PARAMETER); assertEquals(2, ae.elements[0].injectionStart.eventIndex); - assertEquals(112.3495, ae.elements[0].injectionStart.angleOffset); + assertEquals(178.24, ae.elements[0].injectionStart.angleOffset); + + TriggerShape t; + confgiureFordAspireTriggerShape(&t); } void testPinHelper(void) { diff --git a/unit_tests/test_trigger_decoder.cpp b/unit_tests/test_trigger_decoder.cpp index a7ea86ee85..818e718430 100644 --- a/unit_tests/test_trigger_decoder.cpp +++ b/unit_tests/test_trigger_decoder.cpp @@ -508,7 +508,7 @@ void testTriggerDecoder(void) { testFordAspire(); // lame duty cycle implementation! - testTriggerDecoder2("ford aspire", FORD_ASPIRE_1996, 4, 0.5, 0.3841); + testTriggerDecoder2("ford aspire", FORD_ASPIRE_1996, 4, 0.0, 0.5); //testTriggerDecoder2("bmw", BMW_E34, 0, 0.9750, 0.5167); testTriggerDecoder2("bmw", BMW_E34, 0, 0.4833, 0.0);