From 237703a49dcabfb409689c027d71c4f43fd70950 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Thu, 6 Nov 2014 09:06:08 -0600 Subject: [PATCH] auto-sync --- firmware/config/engines/bmw_e34.cpp | 4 ++++ firmware/console/status_loop.cpp | 4 +--- firmware/controllers/algo/advance_map.cpp | 2 +- firmware/controllers/algo/engine_configuration.cpp | 1 + firmware/controllers/algo/engine_configuration.h | 5 ++++- firmware/controllers/math/engine_math.cpp | 10 +++++++--- firmware/controllers/math/engine_math.h | 5 +---- firmware/controllers/trigger/trigger_structure.cpp | 10 +++++----- firmware/controllers/trigger/trigger_structure.h | 4 ++-- firmware/emulation/wave_analyzer.cpp | 2 +- firmware/rusefi.cpp | 2 +- firmware/tunerstudio/rusefi.ini | 7 ++++--- unit_tests/test_fuel_map.cpp | 2 +- 13 files changed, 33 insertions(+), 25 deletions(-) diff --git a/firmware/config/engines/bmw_e34.cpp b/firmware/config/engines/bmw_e34.cpp index 71b170f3d3..ff687a1fa7 100644 --- a/firmware/config/engines/bmw_e34.cpp +++ b/firmware/config/engines/bmw_e34.cpp @@ -24,6 +24,10 @@ void setBmwE43(engine_configuration_s *engineConfiguration) { engineConfiguration->injectionMode = IM_SIMULTANEOUS; engineConfiguration->ignitionMode = IM_WASTED_SPARK; + setConstantDwell(engineConfiguration, 3); // a bit shorter dwell + engineConfiguration->useConstantDwellDuringCranking = true; + engineConfiguration->ignitionDwellForCrankingMs = 5; + // todo: check the digital sniffer while simulating // set_global_trigger_offset_angle 84 engineConfiguration->globalTriggerAngleOffset = 84; diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 595fe7512d..433517b674 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -179,8 +179,6 @@ void printState(Engine *engine, int currentCkpEventCounter) { debugFloat(&logger, "timing", getAdvance(rpm, engineLoad), 2); // float map = getMap(); -// float fuel = getDefaultFuel(rpm, map); -// debugFloat(&logger, "d_fuel", fuel, 2); #endif /* EFI_SHAFT_POSITION_INPUT */ } @@ -454,7 +452,7 @@ void updateTunerStudioState(Engine *engine, TunerStudioOutputChannels *tsOutputC tsOutputChannels->isIatError = !isValidIntakeAirTemperature(getIntakeAirTemperature(engine)); #endif tsOutputChannels->tCharge = getTCharge(rpm, tps, coolant, intake); - tsOutputChannels->sparkDwell = getSparkDwellMs(rpm); + tsOutputChannels->sparkDwell = getSparkDwellMsT(engineConfiguration, rpm); tsOutputChannels->pulseWidthMs = getRunningFuel(baseFuelMs, engine, rpm); tsOutputChannels->crankingFuelMs = getCrankingFuel(engine); } diff --git a/firmware/controllers/algo/advance_map.cpp b/firmware/controllers/algo/advance_map.cpp index 1062535a47..542674fa76 100644 --- a/firmware/controllers/algo/advance_map.cpp +++ b/firmware/controllers/algo/advance_map.cpp @@ -50,7 +50,7 @@ float getAdvance(int rpm, float engineLoad) { } else { angle = -getBaseAdvance(rpm, engineLoad); } - return fixAngle(angle + engineConfiguration->ignitionOffset); + return fixAngle(engineConfiguration, angle + engineConfiguration->ignitionOffset); } void prepareTimingMap(void) { diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index 00ac2037ce..fa472891f4 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -141,6 +141,7 @@ void setDefaultConfiguration(engine_configuration_s *engineConfiguration, board_ } setConstantDwell(engineConfiguration, 4); // 4ms is global default dwell + engineConfiguration->useConstantDwellDuringCranking = false; setFuelLoadBin(engineConfiguration, 1.2, 4.4); setFuelRpmBin(engineConfiguration, 800, 7000); diff --git a/firmware/controllers/algo/engine_configuration.h b/firmware/controllers/algo/engine_configuration.h index 59445f4023..92c68e08c5 100644 --- a/firmware/controllers/algo/engine_configuration.h +++ b/firmware/controllers/algo/engine_configuration.h @@ -440,6 +440,7 @@ typedef struct { bool_t hasIatSensor : 1; // bit 1 bool_t hasBaroSensor : 1; // bit 1 bool_t hasAfrSensor : 1; // bit 2 + bool_t useConstantDwellDuringCranking : 1; // bit 3 // that's the next 32 bit field int hasCltSensor; @@ -480,7 +481,9 @@ typedef struct { float crankingCycleCoef[CRANKING_CURVE_SIZE]; float crankingCycleBins[CRANKING_CURVE_SIZE]; - int unused3[94]; + float ignitionDwellForCrankingMs; + + int unused3[93]; } engine_configuration_s; diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index dba4f279f2..f8ede0b511 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -50,7 +50,7 @@ float getCrankshaftRevolutionTimeMs(int rpm) { * @brief Shifts angle into the [0..720) range * TODO: should be 'crankAngleRange' range? */ -float fixAngle(float angle) { +float fixAngle(engine_configuration_s const *engineConfiguration, float angle) { // I guess this implementation would be faster than 'angle % 720' while (angle < 0) angle += 720; @@ -231,9 +231,13 @@ void addFuelEvents(engine_configuration_s const *e, engine_configuration2_s *eng */ float getSparkDwellMsT(engine_configuration_s *engineConfiguration, int rpm) { if (isCrankingR(rpm)) { + if(engineConfiguration->useConstantDwellDuringCranking) { + return engineConfiguration->ignitionDwellForCrankingMs; + } else { // technically this could be implemented via interpolate2d float angle = engineConfiguration->crankingChargeAngle; return getOneDegreeTimeMs(rpm) * angle; + } } efiAssert(!cisnan(rpm), "invalid rpm", NAN); @@ -255,7 +259,7 @@ int getEngineCycleEventCount(engine_configuration_s const *engineConfiguration, void findTriggerPosition(engine_configuration_s const *engineConfiguration, trigger_shape_s * s, event_trigger_position_s *position, float angleOffset) { - angleOffset = fixAngle(angleOffset + engineConfiguration->globalTriggerAngleOffset); + angleOffset = fixAngle(engineConfiguration, angleOffset + engineConfiguration->globalTriggerAngleOffset); int engineCycleEventCount = getEngineCycleEventCount(engineConfiguration, s); @@ -345,7 +349,7 @@ void prepareOutputSignals(Engine *engine) { engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2; // todo: move this reset into decoder - engineConfiguration2->triggerShape.calculateTriggerSynchPoint(&engineConfiguration->triggerConfig); + engineConfiguration2->triggerShape.calculateTriggerSynchPoint(engineConfiguration, &engineConfiguration->triggerConfig); injectonSignals.clear(); EventHandlerConfiguration *config = &engineConfiguration2->engineEventConfiguration; diff --git a/firmware/controllers/math/engine_math.h b/firmware/controllers/math/engine_math.h index bb47bb2c13..d47d3a22ca 100644 --- a/firmware/controllers/math/engine_math.h +++ b/firmware/controllers/math/engine_math.h @@ -21,8 +21,6 @@ void findTriggerPosition(engine_configuration_s const *engineConfiguration, trig int isInjectionEnabled(engine_configuration_s *engineConfiguration); -float fixAngle(float angle); - #endif #ifdef __cplusplus @@ -30,7 +28,7 @@ extern "C" { #endif /* __cplusplus */ -float getDefaultFuel(int rpm, float map); +float fixAngle(engine_configuration_s const *engineConfiguration, float angle); /** * So that's how 'inline' syntax for both GCC and IAR @@ -57,7 +55,6 @@ float getEngineLoadT(Engine *engine); #define getEngineLoad() getEngineLoadT(&engine) float getSparkDwellMsT(engine_configuration_s *engineConfiguration, int rpm); -#define getSparkDwellMs(rpm) getSparkDwellMsT(engineConfiguration, rpm) int getCylinderId(firing_order_e firingOrder, int index); diff --git a/firmware/controllers/trigger/trigger_structure.cpp b/firmware/controllers/trigger/trigger_structure.cpp index 3da1856834..20ae6d1364 100644 --- a/firmware/controllers/trigger/trigger_structure.cpp +++ b/firmware/controllers/trigger/trigger_structure.cpp @@ -22,6 +22,7 @@ #include "trigger_structure.h" #include "error_handling.h" #include "trigger_decoder.h" +#include "engine_math.h" trigger_shape_helper::trigger_shape_helper() { for (int i = 0; i < TRIGGER_CHANNEL_COUNT; i++) { @@ -53,13 +54,12 @@ int trigger_shape_s::getTriggerShapeSynchPointIndex() { // todo: clean-up! int getEngineCycleEventCount2(operation_mode_e mode, trigger_shape_s * s); -float fixAngle(float angle); -void trigger_shape_s::calculateTriggerSynchPoint(trigger_config_s const*triggerConfig) { - setTriggerShapeSynchPointIndex(findTriggerZeroEventIndex(this, triggerConfig)); +void trigger_shape_s::calculateTriggerSynchPoint(engine_configuration_s const*engineConfiguration, trigger_config_s const*triggerConfig) { + setTriggerShapeSynchPointIndex(engineConfiguration, findTriggerZeroEventIndex(this, triggerConfig)); } -void trigger_shape_s::setTriggerShapeSynchPointIndex(int triggerShapeSynchPointIndex) { +void trigger_shape_s::setTriggerShapeSynchPointIndex(engine_configuration_s const *engineConfiguration, int triggerShapeSynchPointIndex) { this->triggerShapeSynchPointIndex = triggerShapeSynchPointIndex; int engineCycleEventCount = getEngineCycleEventCount2(operationMode, this); @@ -71,7 +71,7 @@ void trigger_shape_s::setTriggerShapeSynchPointIndex(int triggerShapeSynchPointI // explicit check for zero to avoid issues where logical zero is not exactly zero due to float nature eventAngles[i] = 0; } else { - eventAngles[i] = fixAngle(getAngle((triggerShapeSynchPointIndex + i) % engineCycleEventCount) - firstAngle); + eventAngles[i] = fixAngle(engineConfiguration, getAngle((triggerShapeSynchPointIndex + i) % engineCycleEventCount) - firstAngle); } } } diff --git a/firmware/controllers/trigger/trigger_structure.h b/firmware/controllers/trigger/trigger_structure.h index 4a356248e1..8cd21d8053 100644 --- a/firmware/controllers/trigger/trigger_structure.h +++ b/firmware/controllers/trigger/trigger_structure.h @@ -83,9 +83,9 @@ public: int getTriggerShapeSynchPointIndex(); - void calculateTriggerSynchPoint(trigger_config_s const*triggerConfig); + void calculateTriggerSynchPoint(engine_configuration_s const *engineConfiguration, trigger_config_s const*triggerConfig); - void setTriggerShapeSynchPointIndex(int triggerShapeSynchPointIndex); + void setTriggerShapeSynchPointIndex(engine_configuration_s const *engineConfiguration, int triggerShapeSynchPointIndex); /** * These angles are in event coordinates - with synchronization point located at angle zero. * These values are pre-calculated for performance reasons. diff --git a/firmware/emulation/wave_analyzer.cpp b/firmware/emulation/wave_analyzer.cpp index 2428adfd3f..ae65e9d529 100644 --- a/firmware/emulation/wave_analyzer.cpp +++ b/firmware/emulation/wave_analyzer.cpp @@ -234,7 +234,7 @@ static void reportWave(Logging *logging, int index) { float oneDegreeUs = getOneDegreeTimeUs(getRpm()); appendPrintf(logging, "advance%d%s", index, DELIMETER); - appendFloat(logging, fixAngle((offsetUs / oneDegreeUs) - engineConfiguration->globalTriggerAngleOffset), 3); + appendFloat(logging, fixAngle(engineConfiguration, (offsetUs / oneDegreeUs) - engineConfiguration->globalTriggerAngleOffset), 3); appendPrintf(logging, "%s", DELIMETER); } } diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 38597aed11..575acaf656 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -249,5 +249,5 @@ void firmwareError(const char *fmt, ...) { } int getRusEfiVersion(void) { - return 20141105; + return 20141106; } diff --git a/firmware/tunerstudio/rusefi.ini b/firmware/tunerstudio/rusefi.ini index e8b2e5fd90..8552df1444 100644 --- a/firmware/tunerstudio/rusefi.ini +++ b/firmware/tunerstudio/rusefi.ini @@ -303,9 +303,9 @@ enable2ndByteCanID = false max31855spiDevice = bits, U32, 5912, [0:1], "Off", "SPI1", "SPI2", "SPI3" - - - ; idle mode 6288 + useConstantDwellDuringCranking= bits, U32, 6280, [3:3], "false", "true" + ; hasCltSensor 6284 + ; idleMode 6288 isInjectionEnabled = bits, U32, 6292, [0:0], "false", "true" isIgnitionEnabled = bits, U32, 6292, [1:1], "false", "true" @@ -327,6 +327,7 @@ enable2ndByteCanID = false crankingCycleCoef = array, F32, 9568, [8], "%", 100, 0, 0.0, 500.0, 2; size 32 crankingCycleBins = array, F32, 9600, [8], "C", 1, 0, -80.0, 170.0, 2; size 32 + ignitionDwellForCrankingMs=scalar, F32, 9632, "ms", 1, 0, 0, 200, 1; size 4 [OutputChannels] diff --git a/unit_tests/test_fuel_map.cpp b/unit_tests/test_fuel_map.cpp index 7ee3136a6b..5493c046da 100644 --- a/unit_tests/test_fuel_map.cpp +++ b/unit_tests/test_fuel_map.cpp @@ -156,7 +156,7 @@ void testAngleResolver(void) { confgiureFordAspireTriggerShape(ts); - ts->calculateTriggerSynchPoint(&engineConfiguration->triggerConfig); + ts->calculateTriggerSynchPoint(engineConfiguration, &engineConfiguration->triggerConfig); assertEqualsM("index 2", 232.76, ts->eventAngles[3]); // this angle is relation to synch point assertEqualsM("time 2", 0.3233, ts->wave.getSwitchTime(2));