From 7b11219a1563a81b9e7bd6da429b5271dfed7805 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Fri, 3 Apr 2015 19:08:31 -0500 Subject: [PATCH] auto-sync --- firmware/config/engines/mazda_miata.cpp | 4 + .../controllers/algo/accel_enrichment.cpp | 93 +++++++++---------- .../controllers/algo/engine_configuration.cpp | 2 +- firmware/controllers/algo/fuel_math.cpp | 3 +- firmware/controllers/algo/idle_controller.cpp | 8 +- firmware/controllers/algo/idle_controller.h | 8 +- firmware/controllers/idle_thread.cpp | 37 ++++---- firmware/controllers/sensors/maf.cpp | 57 ++++++++++++ firmware/controllers/sensors/maf.h | 1 + 9 files changed, 139 insertions(+), 74 deletions(-) diff --git a/firmware/config/engines/mazda_miata.cpp b/firmware/config/engines/mazda_miata.cpp index b3f7ce350b..ac4695c089 100644 --- a/firmware/config/engines/mazda_miata.cpp +++ b/firmware/config/engines/mazda_miata.cpp @@ -491,6 +491,10 @@ void setMiata1994_s(DECLARE_ENGINE_PARAMETER_F) { boardConfiguration->malfunctionIndicatorPin = GPIOE_5; boardConfiguration->malfunctionIndicatorPinMode = OM_DEFAULT; + + engineConfiguration->algorithm = LM_REAL_MAF; + setMazdaMiataNAMaf(engineConfiguration); + engineConfiguration->injector.flow = 230; } /** diff --git a/firmware/controllers/algo/accel_enrichment.cpp b/firmware/controllers/algo/accel_enrichment.cpp index 72af6ad739..220ea74b5e 100644 --- a/firmware/controllers/algo/accel_enrichment.cpp +++ b/firmware/controllers/algo/accel_enrichment.cpp @@ -24,53 +24,6 @@ EXTERN_ENGINE static AccelEnrichmemnt instance; static Logging *logger; -#if ! EFI_UNIT_TEST || defined(__DOXYGEN__) - -static void accelInfo() { - scheduleMsg(logger, "accel length=%d", instance.cb.getSize()); - scheduleMsg(logger, "accel th=%f/mult=%f", engineConfiguration->accelEnrichmentThreshold, engineConfiguration->accelEnrichmentMultiplier); - scheduleMsg(logger, "decel th=%f/mult=%f", engineConfiguration->decelEnrichmentThreshold, engineConfiguration->decelEnrichmentMultiplier); -} - -static void setAccelThr(float value) { - engineConfiguration->accelEnrichmentThreshold = value; - accelInfo(); -} - -static void setAccelMult(float value) { - engineConfiguration->accelEnrichmentMultiplier = value; - accelInfo(); -} - -static void setDecelThr(float value) { - engineConfiguration->decelEnrichmentThreshold = value; - accelInfo(); -} - -static void setDecelMult(float value) { - engineConfiguration->decelEnrichmentMultiplier = value; - accelInfo(); -} - -static void setAccelLen(int len) { - instance.cb.setSize(len); - accelInfo(); -} - -void initAccelEnrichment(Logging *sharedLogger) { - logger = sharedLogger; - addConsoleActionF("set_accel_th", setAccelThr); - addConsoleActionF("set_accel_mult", setAccelMult); - addConsoleActionF("set_decel_th", setDecelThr); - addConsoleActionF("set_decel_mult", setDecelMult); - addConsoleActionI("set_accel_len", setAccelLen); - addConsoleAction("accelinfo", accelInfo); - - setAccelLen(engineConfiguration->accelLength); - -} -#endif /* ! EFI_UNIT_TEST */ - void AccelEnrichmemnt::updateDiffEnrichment(engine_configuration_s *engineConfiguration, float engineLoad) { // for (int i = 3; i == 1; i--) // array[i] = array[i - 1]; @@ -147,3 +100,49 @@ AccelEnrichmemnt::AccelEnrichmemnt() { //#endif + +#if ! EFI_UNIT_TEST || defined(__DOXYGEN__) + +static void accelInfo() { + scheduleMsg(logger, "accel length=%d", instance.cb.getSize()); + scheduleMsg(logger, "accel th=%f/mult=%f", engineConfiguration->accelEnrichmentThreshold, engineConfiguration->accelEnrichmentMultiplier); + scheduleMsg(logger, "decel th=%f/mult=%f", engineConfiguration->decelEnrichmentThreshold, engineConfiguration->decelEnrichmentMultiplier); +} + +static void setAccelThr(float value) { + engineConfiguration->accelEnrichmentThreshold = value; + accelInfo(); +} + +static void setAccelMult(float value) { + engineConfiguration->accelEnrichmentMultiplier = value; + accelInfo(); +} + +static void setDecelThr(float value) { + engineConfiguration->decelEnrichmentThreshold = value; + accelInfo(); +} + +static void setDecelMult(float value) { + engineConfiguration->decelEnrichmentMultiplier = value; + accelInfo(); +} + +static void setAccelLen(int len) { + instance.cb.setSize(len); + accelInfo(); +} + +void initAccelEnrichment(Logging *sharedLogger) { + logger = sharedLogger; + addConsoleActionF("set_accel_threshold", setAccelThr); + addConsoleActionF("set_accel_multiplier", setAccelMult); + addConsoleActionF("set_decel_threshold", setDecelThr); + addConsoleActionF("set_decel_multiplier", setDecelMult); + addConsoleActionI("set_accel_len", setAccelLen); + addConsoleAction("accelinfo", accelInfo); + + setAccelLen(engineConfiguration->accelLength); +} +#endif /* ! EFI_UNIT_TEST */ diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index 6823e5b251..e060c13345 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -359,7 +359,7 @@ void setDefaultConfiguration(DECLARE_ENGINE_PARAMETER_F) { engineConfiguration->isDigitalChartEnabled = true; boardConfiguration->idleSolenoidFrequency = 200; - // set_idle_pwm 50 + // set_idle_position 50 boardConfiguration->idleSolenoidPwm = 0.5; engineConfiguration->targetIdleRpm = 1200; // engineConfiguration->idleMode = IM_AUTO; diff --git a/firmware/controllers/algo/fuel_math.cpp b/firmware/controllers/algo/fuel_math.cpp index d622420cc8..7ae83b7a10 100644 --- a/firmware/controllers/algo/fuel_math.cpp +++ b/firmware/controllers/algo/fuel_math.cpp @@ -76,7 +76,8 @@ float getBaseFuel(int rpm DECLARE_ENGINE_PARAMETER_S) { if (engineConfiguration->algorithm == LM_SPEED_DENSITY) { return getSpeedDensityFuel(rpm PASS_ENGINE_PARAMETER); } else if (engineConfiguration->algorithm == LM_REAL_MAF) { - return getRealMafFuel(getRealMaf(PASS_ENGINE_PARAMETER_F), rpm PASS_ENGINE_PARAMETER); + float maf = getRealMaf(PASS_ENGINE_PARAMETER_F) + engine->accelEnrichment.getEnrichment(PASS_ENGINE_PARAMETER_F); + return getRealMafFuel(maf, rpm PASS_ENGINE_PARAMETER); } else { float engineLoad = getEngineLoadT(PASS_ENGINE_PARAMETER_F); return getBaseTableFuel(engineConfiguration, rpm, engineLoad); diff --git a/firmware/controllers/algo/idle_controller.cpp b/firmware/controllers/algo/idle_controller.cpp index d0efb044bf..5afbaff7f3 100644 --- a/firmware/controllers/algo/idle_controller.cpp +++ b/firmware/controllers/algo/idle_controller.cpp @@ -32,12 +32,12 @@ IdleValveState::IdleValveState() { } void IdleValveState::init(DECLARE_ENGINE_PARAMETER_F) { - setIdleRpm(this, engineConfiguration->targetIdleRpm); + setTargetRpm(engineConfiguration->targetIdleRpm); } -void setIdleRpm(IdleValveState *idle, int targetRpm) { - idle->targetRpmRangeLeft = (int) (targetRpm * 0.93); - idle->targetRpmRangeRight = (int) (targetRpm * 1.07); +void IdleValveState::setTargetRpm(int targetRpm) { + targetRpmRangeLeft = (int) (targetRpm * 0.93); + targetRpmRangeRight = (int) (targetRpm * 1.07); } /** diff --git a/firmware/controllers/algo/idle_controller.h b/firmware/controllers/algo/idle_controller.h index 22800a455e..c2c732a49b 100644 --- a/firmware/controllers/algo/idle_controller.h +++ b/firmware/controllers/algo/idle_controller.h @@ -27,18 +27,18 @@ class IdleValveState { public: IdleValveState(); void init(DECLARE_ENGINE_PARAMETER_F); + void setTargetRpm(int targetRpm); percent_t getIdle(int currentRpm, efitimems_t now DECLARE_ENGINE_PARAMETER_S); int time; - int targetRpmRangeLeft, targetRpmRangeRight; - percent_t value; efitimems_t timeOfLastIdleChange; +private: + int targetRpmRangeLeft; + int targetRpmRangeRight; }; -void setIdleRpm(IdleValveState *idle, int targetRpm); - void idleDebug(const char *msg, percent_t value); #endif /* IDLE_CONTROLLER_H_ */ diff --git a/firmware/controllers/idle_thread.cpp b/firmware/controllers/idle_thread.cpp index 03936d9a5d..814a8e6a0b 100644 --- a/firmware/controllers/idle_thread.cpp +++ b/firmware/controllers/idle_thread.cpp @@ -49,7 +49,7 @@ static StepperMotor iacMotor; /** * Idle level calculation algorithm lives in idle_controller.c */ -static IdleValveState idle; +static IdleValveState idleMath; void idleDebug(const char *msg, percent_t value) { scheduleMsg(logger, "%s%f", msg, value); @@ -67,10 +67,6 @@ static void setIdleControlEnabled(int value) { showIdleInfo(); } -static void setIdleValvePosition(int position) { - iacMotor.targetPosition = position; -} - static void setIdleValvePwm(percent_t value) { if (value < 0.01 || value > 99.9) return; @@ -85,6 +81,14 @@ static void setIdleValvePwm(percent_t value) { idleValvePwm.setSimplePwmDutyCycle(f); } +static void setIdleValvePosition(int position) { + if(boardConfiguration->useStepperIdle) { + iacMotor.targetPosition = position; + } else { + setIdleValvePwm(position); + } +} + static msg_t ivThread(int param) { (void) param; chRegSetThreadName("IdleValve"); @@ -108,7 +112,7 @@ static msg_t ivThread(int param) { efitimems_t now = currentTimeMillis(); - percent_t newValue = idle.getIdle(getRpm(), now PASS_ENGINE_PARAMETER); + percent_t newValue = idleMath.getIdle(getRpm(), now PASS_ENGINE_PARAMETER); if (currentIdleValve != newValue) { currentIdleValve = newValue; @@ -122,7 +126,7 @@ static msg_t ivThread(int param) { } static void setIdleRpmAction(int value) { - setIdleRpm(&idle, value); + idleMath.setTargetRpm(value); scheduleMsg(logger, "target idle RPM %d", value); } @@ -138,19 +142,19 @@ static void applyIdleSolenoidPinState(PwmConfig *state, int stateIndex) { void startIdleThread(Logging*sharedLogger, Engine *engine) { logger = sharedLogger; - if (boardConfiguration->idleStepperDirection != GPIO_UNASSIGNED) { + if (boardConfiguration->useStepperIdle) { iacMotor.initialize(boardConfiguration->idleStepperStep, boardConfiguration->idleStepperDirection); + } else { + /** + * Start PWM for idleValvePin + */ + startSimplePwmExt(&idleValvePwm, "Idle Valve", boardConfiguration->idleValvePin, &idlePin, + boardConfiguration->idleSolenoidFrequency, boardConfiguration->idleSolenoidPwm, applyIdleSolenoidPinState); } - /** - * Start PWM for IDLE_VALVE logical / idleValvePin physical - */ - startSimplePwmExt(&idleValvePwm, "Idle Valve", boardConfiguration->idleValvePin, &idlePin, - boardConfiguration->idleSolenoidFrequency, boardConfiguration->idleSolenoidPwm, applyIdleSolenoidPinState); - - idle.init(); - scheduleMsg(logger, "initial idle %d", idle.value); + idleMath.init(); + scheduleMsg(logger, "initial idle %d", idleMath.value); chThdCreateStatic(ivThreadStack, sizeof(ivThreadStack), NORMALPRIO, (tfunc_t) ivThread, NULL); @@ -165,7 +169,6 @@ void startIdleThread(Logging*sharedLogger, Engine *engine) { addConsoleAction("idleinfo", showIdleInfo); addConsoleActionI("set_idle_rpm", setIdleRpmAction); - addConsoleActionF("set_idle_pwm", setIdleValvePwm); addConsoleActionI("set_idle_position", setIdleValvePosition); diff --git a/firmware/controllers/sensors/maf.cpp b/firmware/controllers/sensors/maf.cpp index 9f62147e54..50744ed4ae 100644 --- a/firmware/controllers/sensors/maf.cpp +++ b/firmware/controllers/sensors/maf.cpp @@ -86,3 +86,60 @@ void setDensoTODO(engine_configuration_s *e) { i++; } } + +void setMazdaMiataNAMaf(engine_configuration_s *e) { + int i = 0; + i= addMafPoint(e, i, 0.000000, 0.000000); + i= addMafPoint(e, i, 0.000028, 0.100000); + i= addMafPoint(e, i, 0.000387, 0.200000); + i= addMafPoint(e, i, 0.001809, 0.300000); + i= addMafPoint(e, i, 0.005409, 0.400000); + i= addMafPoint(e, i, 0.012648, 0.500000); + i= addMafPoint(e, i, 0.025320, 0.600000); + i= addMafPoint(e, i, 0.045532, 0.700000); + i= addMafPoint(e, i, 0.075698, 0.800000); + i= addMafPoint(e, i, 0.118525, 0.900000); + i= addMafPoint(e, i, 0.177011, 1.000000); + i= addMafPoint(e, i, 0.254434, 1.100000); + i= addMafPoint(e, i, 0.354347, 1.200000); + i= addMafPoint(e, i, 0.480576, 1.300000); + i= addMafPoint(e, i, 0.637210, 1.400000); + i= addMafPoint(e, i, 0.828604, 1.500000); + i= addMafPoint(e, i, 1.059369, 1.600000); + i= addMafPoint(e, i, 1.334371, 1.700000); + i= addMafPoint(e, i, 1.658728, 1.800000); + i= addMafPoint(e, i, 2.037809, 1.900000); + i= addMafPoint(e, i, 2.477225, 2.000000); + i= addMafPoint(e, i, 2.982835, 2.100000); + i= addMafPoint(e, i, 3.560736, 2.200000); + i= addMafPoint(e, i, 4.217265, 2.300000); + i= addMafPoint(e, i, 4.958995, 2.400000); + i= addMafPoint(e, i, 5.792737, 2.500000); + i= addMafPoint(e, i, 6.725531, 2.600000); + i= addMafPoint(e, i, 7.764648, 2.700000); + i= addMafPoint(e, i, 8.917592, 2.800000); + i= addMafPoint(e, i, 10.192092, 2.900000); + i= addMafPoint(e, i, 11.596102, 3.000000); + i= addMafPoint(e, i, 13.137802, 3.100000); + i= addMafPoint(e, i, 14.825595, 3.200000); + i= addMafPoint(e, i, 16.668105, 3.300000); + i= addMafPoint(e, i, 18.674177, 3.400000); + i= addMafPoint(e, i, 20.852874, 3.500000); + i= addMafPoint(e, i, 23.213478, 3.600000); + i= addMafPoint(e, i, 25.765485, 3.700000); + i= addMafPoint(e, i, 28.518610, 3.800000); + i= addMafPoint(e, i, 31.482778, 3.900000); + i= addMafPoint(e, i, 34.668130, 4.000000); + i= addMafPoint(e, i, 38.085019, 4.100000); + i= addMafPoint(e, i, 41.744006, 4.200000); + i= addMafPoint(e, i, 45.655865, 4.300000); + i= addMafPoint(e, i, 49.831577, 4.400000); + i= addMafPoint(e, i, 54.282334, 4.500000); + i= addMafPoint(e, i, 59.019531, 4.600000); + i= addMafPoint(e, i, 64.054771, 4.700000); + i= addMafPoint(e, i, 69.399864, 4.800000); + i= addMafPoint(e, i, 75.066822, 4.900000); + i= addMafPoint(e, i, 81.067862, 5.000000); + + fillTheRest(e, i); +} diff --git a/firmware/controllers/sensors/maf.h b/firmware/controllers/sensors/maf.h index d99ba235f9..e0f0548e59 100644 --- a/firmware/controllers/sensors/maf.h +++ b/firmware/controllers/sensors/maf.h @@ -22,5 +22,6 @@ void setBosch0280218037(engine_configuration_s *engineConfiguration); void setBosch0280218004(engine_configuration_s *engineConfiguration); void setDensoTODO(engine_configuration_s *engineConfiguration); +void setMazdaMiataNAMaf(engine_configuration_s *e); #endif