From 28bde6f084a94f68fb3c42af0e4d71200a0edf22 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 20 Jan 2019 11:33:40 -0500 Subject: [PATCH] better method name and docs related to improved craking logic --- .../algo/engine_configuration_generated_structures.h | 7 +++++-- firmware/controllers/math/engine_math.cpp | 8 ++++++-- firmware/controllers/math/engine_math.h | 2 +- firmware/controllers/trigger/rpm_calculator.cpp | 6 ++++-- firmware/controllers/trigger/spark_logic.cpp | 8 ++++---- firmware/integration/rusefi_config.txt | 4 ++-- firmware/tunerstudio/rusefi.ini | 4 +++- unit_tests/tests/test_fasterEngineSpinningUp.cpp | 8 ++++---- 8 files changed, 29 insertions(+), 18 deletions(-) diff --git a/firmware/controllers/algo/engine_configuration_generated_structures.h b/firmware/controllers/algo/engine_configuration_generated_structures.h index 36d6780c5c..9cf2052765 100644 --- a/firmware/controllers/algo/engine_configuration_generated_structures.h +++ b/firmware/controllers/algo/engine_configuration_generated_structures.h @@ -1,4 +1,4 @@ -// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Thu Jan 10 17:03:36 EST 2019 +// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Sun Jan 20 11:24:01 EST 2019 // begin #ifndef ENGINE_CONFIGURATION_GENERATED_H_ #define ENGINE_CONFIGURATION_GENERATED_H_ @@ -658,6 +658,8 @@ typedef struct { offset 376 bit 19 */ bool stepperForceParkingEveryRestart : 1; /** + * Smarter cranking logic. + * See also startOfCrankingPrimingPulse offset 376 bit 20 */ bool isFasterEngineSpinUpEnabled : 1; /** @@ -1722,6 +1724,7 @@ typedef struct { float alternatorOffAboveTps; /** * Prime pulse duration in ms + * See also isFasterEngineSpinUpEnabled * set cranking_priming_pulse X * offset 2148 */ @@ -2475,4 +2478,4 @@ typedef struct { #endif // end -// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Thu Jan 10 17:03:36 EST 2019 +// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Sun Jan 20 11:24:01 EST 2019 diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index 86c325dbc4..cc35733cfa 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -422,7 +422,7 @@ int getCylinderId(int index DECLARE_ENGINE_PARAMETER_SUFFIX) { } static int getIgnitionPinForIndex(int i DECLARE_ENGINE_PARAMETER_SUFFIX) { - switch (getIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE)) { + switch (getCurrentIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE)) { case IM_ONE_COIL: return 0; break; @@ -451,7 +451,11 @@ void prepareIgnitionPinIndices(ignition_mode_e ignitionMode DECLARE_ENGINE_PARAM } } -ignition_mode_e getIgnitionMode(DECLARE_ENGINE_PARAMETER_SIGNATURE) { +/** + * @return IM_WASTED_SPARK if in SPINNING mode and IM_INDIVIDUAL_COILS setting + * @return CONFIG(ignitionMode) otherwise + */ +ignition_mode_e getCurrentIgnitionMode(DECLARE_ENGINE_PARAMETER_SIGNATURE) { ignition_mode_e ignitionMode = CONFIG(ignitionMode); // In spin-up cranking mode we don't have full phase sync. info yet, so wasted spark mode is better if (ignitionMode == IM_INDIVIDUAL_COILS && ENGINE(rpmCalculator.isSpinningUp(PASS_ENGINE_PARAMETER_SIGNATURE))) diff --git a/firmware/controllers/math/engine_math.h b/firmware/controllers/math/engine_math.h index 0ac08b7a64..05726cf54f 100644 --- a/firmware/controllers/math/engine_math.h +++ b/firmware/controllers/math/engine_math.h @@ -47,7 +47,7 @@ float getEngineLoadT(DECLARE_ENGINE_PARAMETER_SIGNATURE); floatms_t getSparkDwell(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX); -ignition_mode_e getIgnitionMode(DECLARE_ENGINE_PARAMETER_SIGNATURE); +ignition_mode_e getCurrentIgnitionMode(DECLARE_ENGINE_PARAMETER_SIGNATURE); /** * This lightweight method is invoked in case of a configuration change or initialization. diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index 113d6742f3..ae6da75ca4 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -200,8 +200,10 @@ void RpmCalculator::setSpinningUp(efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFI if (isSpinningUp(PASS_ENGINE_PARAMETER_SIGNATURE)) { engine->triggerCentral.triggerState.setLastEventTimeForInstantRpm(nowNt PASS_ENGINE_PARAMETER_SUFFIX); } - // Update ignition pin indices if needed - prepareIgnitionPinIndices(getIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX); + /** + * Update ignition pin indices if needed. Here we potentially switch to wasted spark temporarily. + */ + prepareIgnitionPinIndices(getCurrentIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX); } /** diff --git a/firmware/controllers/trigger/spark_logic.cpp b/firmware/controllers/trigger/spark_logic.cpp index b44abdd4f3..75577eb242 100644 --- a/firmware/controllers/trigger/spark_logic.cpp +++ b/firmware/controllers/trigger/spark_logic.cpp @@ -81,7 +81,7 @@ static void prepareCylinderIgnitionSchedule(angle_t dwellAngle, IgnitionEvent *e IgnitionOutputPin *output = &enginePins.coils[coilIndex]; IgnitionOutputPin *secondOutput; - if (getIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE) == IM_WASTED_SPARK && CONFIG(twoWireBatchIgnition)) { + if (getCurrentIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE) == IM_WASTED_SPARK && CONFIG(twoWireBatchIgnition)) { int secondIndex = index + CONFIG(specs.cylindersCount) / 2; int secondCoilIndex = ID2INDEX(getCylinderId(secondIndex PASS_ENGINE_PARAMETER_SUFFIX)); secondOutput = &enginePins.coils[secondCoilIndex]; @@ -133,7 +133,7 @@ static void turnSparkPinHigh2(IgnitionEvent *event, IgnitionOutputPin *output) { #if ! EFI_UNIT_TEST || defined(__DOXYGEN__) if (GET_RPM() > 2 * engineConfiguration->cranking.rpm) { const char *outputName = output->name; - if (prevSparkName == outputName && getIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE) != IM_ONE_COIL) { + if (prevSparkName == outputName && getCurrentIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE) != IM_ONE_COIL) { warning(CUSTOM_OBD_SKIPPED_SPARK, "looks like skipped spark event %d %s", getRevolutionCounter(), outputName); } prevSparkName = outputName; @@ -315,7 +315,7 @@ static ALWAYS_INLINE void prepareIgnitionSchedule(DECLARE_ENGINE_PARAMETER_SIGNA */ float maxAllowedDwellAngle = (int) (getEngineCycle(engineConfiguration->operationMode) / 2); // the cast is about making Coverity happy - if (getIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE) == IM_ONE_COIL) { + if (getCurrentIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE) == IM_ONE_COIL) { maxAllowedDwellAngle = getEngineCycle(engineConfiguration->operationMode) / engineConfiguration->specs.cylindersCount / 1.1; } @@ -408,7 +408,7 @@ int getNumberOfSparks(ignition_mode_e mode DECLARE_ENGINE_PARAMETER_SUFFIX) { * @see getInjectorDutyCycle */ percent_t getCoilDutyCycle(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) { - floatms_t totalPerCycle = 1/**getInjectionDuration(rpm PASS_ENGINE_PARAMETER_SUFFIX)*/ * getNumberOfSparks(getIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX); + floatms_t totalPerCycle = 1/**getInjectionDuration(rpm PASS_ENGINE_PARAMETER_SUFFIX)*/ * getNumberOfSparks(getCurrentIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX); floatms_t engineCycleDuration = getCrankshaftRevolutionTimeMs(rpm) * (engineConfiguration->operationMode == TWO_STROKE ? 1 : 2); return 100 * totalPerCycle / engineCycleDuration; } diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 07e27e113b..4981b818b4 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -552,7 +552,7 @@ bit is_enabled_spi_2 bit vvtCamSensorUseRise;+Use rise or fall signal front bit measureMapOnlyInOneCylinder;+Useful for individual intakes bit stepperForceParkingEveryRestart - bit isFasterEngineSpinUpEnabled + bit isFasterEngineSpinUpEnabled;+Smarter cranking logic.\nSee also startOfCrankingPrimingPulse bit coastingFuelCutEnabled bit useIacTableForCoasting bit useNoiselessTriggerDecoder @@ -789,7 +789,7 @@ custom pin_mode_e 4 bits, U32, @OFFSET@, [0:5], @@pin_mode_e_enum@@ float targetVBatt;set targetvbatt VOLTS;"Volts", 1, 0, 0,30, 1 float alternatorOffAboveTps;Turn off alternator output above specified TPS;"%", 1, 0, 0, 200, 2 - float startOfCrankingPrimingPulse;Prime pulse duration in ms\nset cranking_priming_pulse X;"ms", 1, 0, 0, 200, 1 + float startOfCrankingPrimingPulse;+Prime pulse duration in ms\nSee also isFasterEngineSpinUpEnabled\nset cranking_priming_pulse X;"ms", 1, 0, 0, 200, 1 int16_t afterCrankingIACtaperDuration;;"cycles", 1, 0, 0, 5000, 0 int16_t iacByTpsTaper;Extra IAC, in percent between 0 and 100, tapered between zero and idle deactivation TPS value;"percent", 1, 0, 0, 500, 0 diff --git a/firmware/tunerstudio/rusefi.ini b/firmware/tunerstudio/rusefi.ini index 7daa8169d4..ed1e196c66 100644 --- a/firmware/tunerstudio/rusefi.ini +++ b/firmware/tunerstudio/rusefi.ini @@ -63,7 +63,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Mon Jan 14 08:57:20 EST 2019 +; this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Sun Jan 20 11:24:01 EST 2019 pageSize = 20000 page = 1 @@ -900,6 +900,7 @@ page = 1 tachOutputPin = "This implementation produces one pulse per engine cycle. See also dizzySparkOutputPin." vvtCamSensorUseRise = "Use rise or fall signal front" measureMapOnlyInOneCylinder = "Useful for individual intakes" + isFasterEngineSpinUpEnabled = "Smarter cranking logic.\nSee also startOfCrankingPrimingPulse" sensorChartMode = "rusEfi console Sensor Sniffer mode" isVerboseIAC = "Print details into rusEfi console" isInjectionEnabled = "enable injection" @@ -915,6 +916,7 @@ page = 1 tachPulseTriggerIndex = "Trigger cycle index at which we start tach pulse (performance consideration)" throttlePedalWOTVoltage = "Pedal in the floor" startUpFuelPumpDuration = "on ECU start turn fuel pump on to build fuel pressure" + startOfCrankingPrimingPulse = "Prime pulse duration in ms\nSee also isFasterEngineSpinUpEnabled\nset cranking_priming_pulse X" slowAdcAlpha = "ExpAverage alpha coefficient" dizzySparkOutputPin = "This implementation makes a pulse every time one of the coils is charged, using coil dwell for pulse width. See also tachOutputPin" camInput = "Camshaft input could be used either just for engine phase detection if your trigger shape does not include cam sensor as 'primary' channel, or it could be used for Variable Valve timing on one of the camshafts.\nTODO #660" diff --git a/unit_tests/tests/test_fasterEngineSpinningUp.cpp b/unit_tests/tests/test_fasterEngineSpinningUp.cpp index d01958d907..3d6eabd8b4 100644 --- a/unit_tests/tests/test_fasterEngineSpinningUp.cpp +++ b/unit_tests/tests/test_fasterEngineSpinningUp.cpp @@ -24,7 +24,7 @@ TEST(sensors, testFasterEngineSpinningUp) { // check if it's true ASSERT_EQ(IM_SEQUENTIAL, engine->getCurrentInjectionMode(PASS_ENGINE_PARAMETER_SIGNATURE)); - ASSERT_EQ(IM_INDIVIDUAL_COILS, getIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE)); + ASSERT_EQ(IM_INDIVIDUAL_COILS, getCurrentIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE)); // check if the engine has the right state ASSERT_EQ(STOPPED, engine->rpmCalculator.getState()); // check RPM @@ -46,8 +46,8 @@ TEST(sensors, testFasterEngineSpinningUp) { ASSERT_EQ(4, engine->executor.size()) << "plain#2"; // test if they are simultaneous ASSERT_EQ(IM_SIMULTANEOUS, engine->getCurrentInjectionMode(PASS_ENGINE_PARAMETER_SIGNATURE)); - // test if ignition mode is temporary changed to wasted spark, if set to ind.coils - ASSERT_EQ(IM_WASTED_SPARK, getIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE)); + // test if ignition mode is temporary changed to wasted spark, if set to individual coils + ASSERT_EQ(IM_WASTED_SPARK, getCurrentIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE)); // check real events eth.assertEvent5(&engine->executor, "inj start#1", 0, (void*)startSimultaniousInjection, timeStartUs, MS2US(200) + 97975); eth.assertEvent5(&engine->executor, "inj end#1", 1, (void*)endSimultaniousInjection, timeStartUs, MS2US(200) + 100000); @@ -67,7 +67,7 @@ TEST(sensors, testFasterEngineSpinningUp) { // test if they are simultaneous in cranking mode too ASSERT_EQ(IM_SIMULTANEOUS, engine->getCurrentInjectionMode(PASS_ENGINE_PARAMETER_SIGNATURE)); // test if ignition mode is restored to ind.coils - ASSERT_EQ(IM_INDIVIDUAL_COILS, getIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE)); + ASSERT_EQ(IM_INDIVIDUAL_COILS, getCurrentIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE)); // two simultaneous injections ASSERT_EQ( 4, engine->executor.size()) << "plain#2"; // check real events