diff --git a/firmware/config/engines/mazda_miata_vvt.cpp b/firmware/config/engines/mazda_miata_vvt.cpp index c4ed4294fa..6ed6c2fb19 100644 --- a/firmware/config/engines/mazda_miata_vvt.cpp +++ b/firmware/config/engines/mazda_miata_vvt.cpp @@ -11,7 +11,7 @@ #include "mazda_miata_vvt.h" #include "custom_engine.h" #include "fsio_impl.h" - +#include "ego.h" EXTERN_ENGINE; @@ -204,6 +204,15 @@ void setMazdaMiata2003EngineConfiguration(DECLARE_ENGINE_PARAMETER_F) { boardConfiguration->malfunctionIndicatorPin = GPIOD_9; // boardConfiguration->malfunctionIndicatorPinMode = OM_INVERTED; + + /** + * PA4 Wideband O2 Sensor + */ + // todo: re-wire the board to use default input channel! + engineConfiguration->afr.hwChannel = EFI_ADC_4; + + setEgoSensor(ES_Innovate_MTX_L PASS_ENGINE_PARAMETER); + } diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index bf0397a2be..4099bd7505 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -143,6 +143,7 @@ EngineState::EngineState() { runningFuel = baseFuel = currentVE = 0; timeOfPreviousWarning = -10; baseTableFuel = iat = iatFuelCorrection = 0; + fuelPidCorrection = 0; clt = cltFuelCorrection = postCrankingFuelCorrection = 0; warmupTargetAfr = airMass = 0; baroCorrection = timingAdvance = fuelTankGauge = 0; diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index 9f20d2b1c8..3b0b8e667c 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -563,6 +563,9 @@ void setDefaultConfiguration(DECLARE_ENGINE_PARAMETER_F) { engineConfiguration->fuelClosedLoopCltThreshold = 70; engineConfiguration->fuelClosedLoopRpmThreshold = 900; engineConfiguration->fuelClosedLoopTpsThreshold = 80; + engineConfiguration->fuelClosedLoopAfrLowThreshold = 10.3; + engineConfiguration->fuelClosedLoopAfrHighThreshold = 19.8; + engineConfiguration->fuelClosedLoopPid.pFactor = -0.1; engineConfiguration->cranking.baseFuel = 5; diff --git a/firmware/controllers/algo/engine_configuration_generated_structures.h b/firmware/controllers/algo/engine_configuration_generated_structures.h index 3e68b9a82e..80451645e2 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 Sun Jan 22 17:18:49 EST 2017 +// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Sun Jan 22 23:36:11 EST 2017 // begin #ifndef ENGINE_CONFIGURATION_GENERATED_H_ #define ENGINE_CONFIGURATION_GENERATED_H_ @@ -1803,7 +1803,7 @@ typedef struct { /** * offset 2738 */ - int16_t fuelClosedLoopAfrLowThreshold; + int16_t unusedShort; /** * offset 2740 */ @@ -1811,15 +1811,15 @@ typedef struct { /** * offset 2756 */ - int16_t fuelClosedLoopAfrHighThreshold; - /** - * offset 2758 - */ - int16_t unusedShort; + float fuelClosedLoopAfrLowThreshold; /** * offset 2760 */ - int unused[72]; + float fuelClosedLoopAfrHighThreshold; + /** + * offset 2764 + */ + int unused[71]; /** total size 3048*/ } engine_configuration_s; @@ -2034,4 +2034,4 @@ typedef struct { #endif // end -// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Sun Jan 22 17:18:49 EST 2017 +// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Sun Jan 22 23:36:11 EST 2017 diff --git a/firmware/controllers/algo/rusefi_generated.h b/firmware/controllers/algo/rusefi_generated.h index d1f417cd25..825de30b69 100644 --- a/firmware/controllers/algo/rusefi_generated.h +++ b/firmware/controllers/algo/rusefi_generated.h @@ -920,15 +920,15 @@ #define fuelClosedLoopCltThreshold_offset 2732 #define fuelClosedLoopTpsThreshold_offset 2734 #define fuelClosedLoopRpmThreshold_offset 2736 -#define fuelClosedLoopAfrLowThreshold_offset 2738 +#define unusedShort_offset 2738 #define fuelClosedLoopPid_offset 2740 #define fuelClosedLoopPid_pFactor_offset 2740 #define fuelClosedLoopPid_iFactor_offset 2744 #define fuelClosedLoopPid_dFactor_offset 2748 #define fuelClosedLoopPid_offset_offset 2752 -#define fuelClosedLoopAfrHighThreshold_offset 2756 -#define unusedShort_offset 2758 -#define unused_offset 2760 +#define fuelClosedLoopAfrLowThreshold_offset 2756 +#define fuelClosedLoopAfrHighThreshold_offset 2760 +#define unused_offset 2764 #define le_formulas1_offset 3048 #define le_formulas2_offset 3248 #define le_formulas3_offset 3448 diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index 25586d716f..6ba5ff08e9 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -372,17 +372,17 @@ static void scheduleOutput2(OutputSignalPair *pair, efitimeus_t nowUs, float del } static void fuelClosedLoopCorrection(DECLARE_ENGINE_PARAMETER_F) { - if (ENGINE(rpmCalculator.rpmValue) < CONFIG(fuelClosedLoopRpmThreshold)) { - return; - } - if (ENGINE(engineState.clt) < CONFIG(fuelClosedLoopCltThreshold)) { - return; - } - if (getTPS(PASS_ENGINE_PARAMETER_F) > CONFIG(fuelClosedLoopTpsThreshold)) { +#if ! EFI_UNIT_TEST + if (ENGINE(rpmCalculator.rpmValue) < CONFIG(fuelClosedLoopRpmThreshold) || + ENGINE(engineState.clt) < CONFIG(fuelClosedLoopCltThreshold) || + getTPS(PASS_ENGINE_PARAMETER_F) > CONFIG(fuelClosedLoopTpsThreshold) || + ENGINE(engineState.currentAfr) < 10 || + ENGINE(engineState.currentAfr) > 20) { + engine->engineState.fuelPidCorrection = 0; + fuelPid.reset(); return; } -#if ! EFI_UNIT_TEST engine->engineState.fuelPidCorrection = fuelPid.getValue(ENGINE(engineState.targetAFR), ENGINE(engineState.currentAfr), 1); if (engineConfiguration->debugMode == DBG_FUEL_PID_CORRECTION) { tsOutputChannels.debugFloatField1 = engine->engineState.fuelPidCorrection; diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index c23b01f69a..81eb07655e 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -765,11 +765,11 @@ float[MAP_ACCEL_TAPER] mapAccelTaperMult;;"mult", 1, 0, 0.0, 300, int16_t fuelClosedLoopCltThreshold;;"C", 1, 0, 0, 100, 0 int16_t fuelClosedLoopTpsThreshold;;"%", 1, 0, 0, 100, 0 int16_t fuelClosedLoopRpmThreshold;;"rpm", 1, 0, 0, 5000, 0 - int16_t fuelClosedLoopAfrLowThreshold;;"ratio", 1, 0, 0, 100, 1 - pid_s fuelClosedLoopPid; - int16_t fuelClosedLoopAfrHighThreshold;;"ratio", 1, 0, 0, 100, 1 int16_t unusedShort - int[72] unused; + pid_s fuelClosedLoopPid; + float fuelClosedLoopAfrLowThreshold;;"ratio", 1, 0, 0, 100, 1 + float fuelClosedLoopAfrHighThreshold;;"ratio", 1, 0, 0, 100, 1 + int[71] unused; end_struct diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index 82dd81ea08..099fd49c0e 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -1127,7 +1127,7 @@ fileVersion = { 20161225 } pulseWidthGauge = pulseWidth, "fuel final squirt, per injection", "mSec", 0, 25.5, 1.0, 1.2, 20, 25, 3, 1 baseFuelGauge = baseFuel, "fuel: base duration, before corr", "mSec", 0, 25.5, 1.0, 1.2, 20, 25, 3, 1 - fuelPidCorrectionGauge = fuelPidCorrection, "fuel: closed loop correction", "mSec", 0, 25.5, 1.0, 1.2, 20, 25, 3, 1 + fuelPidCorrectionGauge = fuelPidCorrection, "fuel: closed loop correction", "mSec", -11, 11, 1.0, 1.2, 20, 25, 3, 1 crankingFuelGauge = crankingFuel, "fuel: crank Width", "mSec", 0, 25.5, 1.0, 1.2, 20, 25, 3, 1 iatCorrectionGauge = iatCorrection, "fuel: IAT correction", "mult", 0, 3, 0, 0, 3, 3, 2, 2 @@ -1797,6 +1797,8 @@ cmd_test_idle_valve = "w\x00\x17\x00\x01" field = "CLT - low threshod", fuelClosedLoopCltThreshold, {fuelClosedLoopCorrectionEnabled == 1} field = "RPM - low threshod", fuelClosedLoopRpmThreshold, {fuelClosedLoopCorrectionEnabled == 1} field = "TPS - high threshod", fuelClosedLoopTpsThreshold, {fuelClosedLoopCorrectionEnabled == 1} + field = "EGO - low threshod", fuelClosedLoopAfrLowThreshold, {fuelClosedLoopCorrectionEnabled == 1} + field = "EGO - high threshod", fuelClosedLoopAfrHighThreshold, {fuelClosedLoopCorrectionEnabled == 1} field = "P factor", fuelClosedLoopPid_pFactor, {fuelClosedLoopCorrectionEnabled == 1} field = "I factor", fuelClosedLoopPid_iFactor, {fuelClosedLoopCorrectionEnabled == 1} field = "D factor", fuelClosedLoopPid_dFactor, {fuelClosedLoopCorrectionEnabled == 1} diff --git a/java_console/models/src/com/rusefi/config/Fields.java b/java_console/models/src/com/rusefi/config/Fields.java index de6dd5d09b..20a2fa4a72 100644 --- a/java_console/models/src/com/rusefi/config/Fields.java +++ b/java_console/models/src/com/rusefi/config/Fields.java @@ -1,6 +1,6 @@ package com.rusefi.config; -// this file was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Sun Jan 22 17:18:49 EST 2017 +// this file was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Sun Jan 22 23:36:11 EST 2017 public class Fields { public static final int LE_COMMAND_LENGTH = 200; public static final int FSIO_ADC_COUNT = 4; @@ -924,15 +924,15 @@ public class Fields { public static final int fuelClosedLoopCltThreshold_offset = 2732; public static final int fuelClosedLoopTpsThreshold_offset = 2734; public static final int fuelClosedLoopRpmThreshold_offset = 2736; - public static final int fuelClosedLoopAfrLowThreshold_offset = 2738; + public static final int unusedShort_offset = 2738; public static final int fuelClosedLoopPid_offset = 2740; public static final int fuelClosedLoopPid_pFactor_offset = 2740; public static final int fuelClosedLoopPid_iFactor_offset = 2744; public static final int fuelClosedLoopPid_dFactor_offset = 2748; public static final int fuelClosedLoopPid_offset_offset = 2752; - public static final int fuelClosedLoopAfrHighThreshold_offset = 2756; - public static final int unusedShort_offset = 2758; - public static final int unused_offset = 2760; + public static final int fuelClosedLoopAfrLowThreshold_offset = 2756; + public static final int fuelClosedLoopAfrHighThreshold_offset = 2760; + public static final int unused_offset = 2764; public static final int le_formulas1_offset = 3048; public static final int le_formulas2_offset = 3248; public static final int le_formulas3_offset = 3448; @@ -1595,13 +1595,13 @@ public class Fields { public static final Field FUELCLOSEDLOOPCLTTHRESHOLD = Field.create("FUELCLOSEDLOOPCLTTHRESHOLD", 2732, FieldType.INT); public static final Field FUELCLOSEDLOOPTPSTHRESHOLD = Field.create("FUELCLOSEDLOOPTPSTHRESHOLD", 2734, FieldType.INT); public static final Field FUELCLOSEDLOOPRPMTHRESHOLD = Field.create("FUELCLOSEDLOOPRPMTHRESHOLD", 2736, FieldType.INT); - public static final Field FUELCLOSEDLOOPAFRLOWTHRESHOLD = Field.create("FUELCLOSEDLOOPAFRLOWTHRESHOLD", 2738, FieldType.INT); + public static final Field UNUSEDSHORT = Field.create("UNUSEDSHORT", 2738, FieldType.INT); public static final Field FUELCLOSEDLOOPPID_PFACTOR = Field.create("FUELCLOSEDLOOPPID_PFACTOR", 2740, FieldType.FLOAT); public static final Field FUELCLOSEDLOOPPID_IFACTOR = Field.create("FUELCLOSEDLOOPPID_IFACTOR", 2744, FieldType.FLOAT); public static final Field FUELCLOSEDLOOPPID_DFACTOR = Field.create("FUELCLOSEDLOOPPID_DFACTOR", 2748, FieldType.FLOAT); public static final Field FUELCLOSEDLOOPPID_OFFSET = Field.create("FUELCLOSEDLOOPPID_OFFSET", 2752, FieldType.FLOAT); - public static final Field FUELCLOSEDLOOPAFRHIGHTHRESHOLD = Field.create("FUELCLOSEDLOOPAFRHIGHTHRESHOLD", 2756, FieldType.INT); - public static final Field UNUSEDSHORT = Field.create("UNUSEDSHORT", 2758, FieldType.INT); + public static final Field FUELCLOSEDLOOPAFRLOWTHRESHOLD = Field.create("FUELCLOSEDLOOPAFRLOWTHRESHOLD", 2756, FieldType.FLOAT); + public static final Field FUELCLOSEDLOOPAFRHIGHTHRESHOLD = Field.create("FUELCLOSEDLOOPAFRHIGHTHRESHOLD", 2760, FieldType.FLOAT); public static final Field LE_FORMULAS1 = Field.create("LE_FORMULAS1", 3048, FieldType.INT); public static final Field LE_FORMULAS2 = Field.create("LE_FORMULAS2", 3248, FieldType.INT); public static final Field LE_FORMULAS3 = Field.create("LE_FORMULAS3", 3448, FieldType.INT);