auto-sync

This commit is contained in:
rusEfi 2015-02-10 09:09:58 -06:00
parent 32c133cd24
commit f21821d1fd
14 changed files with 41 additions and 14 deletions

View File

@ -239,7 +239,7 @@ void setFordEscortGt(engine_configuration_s *engineConfiguration) {
setFrankenso0_1_joystick(engineConfiguration); setFrankenso0_1_joystick(engineConfiguration);
engineConfiguration->specs.displacement = 1.839; engineConfiguration->specs.displacement = 1.839;
engineConfiguration->algorithm = LM_MAF; engineConfiguration->algorithm = LM_PLAIN_MAF;
boardConfiguration->tunerStudioSerialSpeed = 9600; boardConfiguration->tunerStudioSerialSpeed = 9600;
setFuelLoadBin(engineConfiguration, 1.2, 4.4); setFuelLoadBin(engineConfiguration, 1.2, 4.4);

View File

@ -174,8 +174,8 @@ case Force_4b_engine_load_mode:
return "Force_4b_engine_load_mode"; return "Force_4b_engine_load_mode";
case LM_ALPHA_N: case LM_ALPHA_N:
return "LM_ALPHA_N"; return "LM_ALPHA_N";
case LM_MAF: case LM_PLAIN_MAF:
return "LM_MAF"; return "LM_PLAIN_MAF";
case LM_MAP: case LM_MAP:
return "LM_MAP"; return "LM_MAP";
case LM_SPEED_DENSITY: case LM_SPEED_DENSITY:

View File

@ -14,6 +14,7 @@
#include "engine_state.h" #include "engine_state.h"
#include "efiGpio.h" #include "efiGpio.h"
#include "trigger_central.h" #include "trigger_central.h"
#include "fuel_math.h"
#if EFI_PROD_CODE #if EFI_PROD_CODE
#include "injector_central.h" #include "injector_central.h"
@ -34,6 +35,9 @@ EXTERN_ENGINE
void Engine::updateSlowSensors() { void Engine::updateSlowSensors() {
engineState.iat = getIntakeAirTemperature(this); engineState.iat = getIntakeAirTemperature(this);
engineState.clt = getCoolantTemperature(this); engineState.clt = getCoolantTemperature(this);
Engine *engine = this;
injectorLagMs = getInjectorLag(getVBatt(engineConfiguration) PASS_ENGINE_PARAMETER);
} }
void Engine::onTriggerEvent(uint64_t nowNt) { void Engine::onTriggerEvent(uint64_t nowNt) {

View File

@ -128,6 +128,12 @@ public:
EngineState engineState; EngineState engineState;
uint64_t lastTriggerEventTimeNt; uint64_t lastTriggerEventTimeNt;
/**
* this value depends on a slow-changing VBatt value, so
* we update it once in a while
*/
float injectorLagMs;
/** /**
* This coefficient translates ADC value directly into voltage adjusted according to * This coefficient translates ADC value directly into voltage adjusted according to
* voltage divider configuration. This is a future (?) performance optimization. * voltage divider configuration. This is a future (?) performance optimization.

View File

@ -261,7 +261,7 @@ void setDefaultConfiguration(engine_configuration_s *engineConfiguration, board_
engineConfiguration->overrideCrankingIgnition = true; engineConfiguration->overrideCrankingIgnition = true;
engineConfiguration->analogChartFrequency = 20; engineConfiguration->analogChartFrequency = 20;
engineConfiguration->algorithm = LM_MAF; engineConfiguration->algorithm = LM_PLAIN_MAF;
engineConfiguration->vbattDividerCoeff = ((float) (15 + 65)) / 15; engineConfiguration->vbattDividerCoeff = ((float) (15 + 65)) / 15;

View File

@ -89,8 +89,8 @@ float getFuelMs(int rpm DECLARE_ENGINE_PARAMETER_S) {
} }
float getRunningFuel(float baseFuelMs, int rpm DECLARE_ENGINE_PARAMETER_S) { float getRunningFuel(float baseFuelMs, int rpm DECLARE_ENGINE_PARAMETER_S) {
float iatCorrection = getIatCorrection(getIntakeAirTemperature(engine) PASS_ENGINE_PARAMETER); float iatCorrection = getIatCorrection(engine->engineState.iat PASS_ENGINE_PARAMETER);
float cltCorrection = getCltCorrection(getCoolantTemperature(engine) PASS_ENGINE_PARAMETER); float cltCorrection = getCltCorrection(engine->engineState.clt PASS_ENGINE_PARAMETER);
#if EFI_ACCEL_ENRICHMENT #if EFI_ACCEL_ENRICHMENT
float accelEnrichment = getAccelEnrichment(); float accelEnrichment = getAccelEnrichment();

View File

@ -170,7 +170,7 @@ typedef enum {
/** /**
* raw Mass Air Flow sensor value algorithm. http://en.wikipedia.org/wiki/Mass_flow_sensor * raw Mass Air Flow sensor value algorithm. http://en.wikipedia.org/wiki/Mass_flow_sensor
*/ */
LM_MAF = 0, LM_PLAIN_MAF = 0,
/** /**
* Throttle Position Sensor value is used as engine load. http://en.wikipedia.org/wiki/Throttle_position_sensor * Throttle Position Sensor value is used as engine load. http://en.wikipedia.org/wiki/Throttle_position_sensor
*/ */

View File

@ -51,7 +51,8 @@ static volatile int perRevolutionCounter = 0;
static volatile int perRevolution = 0; static volatile int perRevolution = 0;
/** /**
* In this lock-free imlementation 'readIndex' * In this lock-free imlementation 'readIndex' is always pointing
* to the consistent copy of accumulator and counter pair
*/ */
static int readIndex = 0; static int readIndex = 0;
static float accumulators[2]; static float accumulators[2];
@ -121,6 +122,18 @@ void mapAveragingCallback(adcsample_t adcValue) {
} }
#endif /* EFI_ANALOG_CHART */ #endif /* EFI_ANALOG_CHART */
/**
* Local copy is now safe, but it's an overkill: we only
* have one writing thread anyway
*/
int readIndexLocal = readIndex;
int writeIndex = readIndexLocal ^ 1;
accumulators[writeIndex] = accumulators[readIndexLocal] + adcValue;
counters[writeIndex] = counters[readIndexLocal] + 1;
// this would commit the new pair of values
readIndex = writeIndex;
// todo: migrate to the lock-free implementation
chSysLockFromIsr() chSysLockFromIsr()
; ;
// with locking we would have a consistent state // with locking we would have a consistent state
@ -151,7 +164,7 @@ static void mapAveragingCallback(trigger_event_e ckpEventType, uint32_t index DE
if (index != 0) if (index != 0)
return; return;
int rpm = getRpmE(engine); int rpm = engine->rpmCalculator.rpmValue;
if (!isValidRpm(rpm)) if (!isValidRpm(rpm))
return; return;
@ -186,7 +199,7 @@ float getMapVoltage(void) {
* @return Manifold Absolute Pressure, in kPa * @return Manifold Absolute Pressure, in kPa
*/ */
float getMap(void) { float getMap(void) {
if (getRpm() == 0) if (!isValidRpm(engine->rpmCalculator.rpmValue))
return getRawMap(); // maybe return NaN in case of stopped engine? return getRawMap(); // maybe return NaN in case of stopped engine?
return getMapByVoltage(v_averagedMapValue); return getMapByVoltage(v_averagedMapValue);
} }

View File

@ -57,7 +57,7 @@ float getEngineLoadT(DECLARE_ENGINE_PARAMETER_F) {
efiAssert(engine!=NULL, "engine 2NULL", NAN); efiAssert(engine!=NULL, "engine 2NULL", NAN);
efiAssert(engineConfiguration!=NULL, "engineConfiguration 2NULL", NAN); efiAssert(engineConfiguration!=NULL, "engineConfiguration 2NULL", NAN);
switch (engineConfiguration->algorithm) { switch (engineConfiguration->algorithm) {
case LM_MAF: case LM_PLAIN_MAF:
return getMafT(engineConfiguration); return getMafT(engineConfiguration);
case LM_SPEED_DENSITY: case LM_SPEED_DENSITY:
// SD engine load is used for timing lookup but not for fuel calculation // SD engine load is used for timing lookup but not for fuel calculation

View File

@ -69,8 +69,8 @@ float getSpeedDensityFuel(Engine *engine, int rpm) {
engine_configuration_s *engineConfiguration = engine->engineConfiguration; engine_configuration_s *engineConfiguration = engine->engineConfiguration;
float tps = getTPS(PASS_ENGINE_PARAMETER_F); float tps = getTPS(PASS_ENGINE_PARAMETER_F);
float coolantC = getCoolantTemperature(engine); float coolantC = engine->engineState.clt;
float intakeC = getIntakeAirTemperature(engine); float intakeC = engine->engineState.iat;
float tChargeK = convertCelsiusToKelvin(getTCharge(rpm, tps, coolantC, intakeC)); float tChargeK = convertCelsiusToKelvin(getTCharge(rpm, tps, coolantC, intakeC));
float map = getMap(); float map = getMap();
float VE = veMap.getValue(map, engineConfiguration->veLoadBins, rpm, float VE = veMap.getValue(map, engineConfiguration->veLoadBins, rpm,

View File

@ -99,7 +99,7 @@ float RpmCalculator::getRpmAcceleration() {
* *
* @return -1 in case of isNoisySignal(), current RPM otherwise * @return -1 in case of isNoisySignal(), current RPM otherwise
*/ */
// todo: migrate to float return result or add a float verion? this would have with calculations // todo: migrate to float return result or add a float version? this would have with calculations
// todo: add a version which does not check time & saves time? need to profile // todo: add a version which does not check time & saves time? need to profile
int RpmCalculator::rpm(DECLARE_ENGINE_PARAMETER_F) { int RpmCalculator::rpm(DECLARE_ENGINE_PARAMETER_F) {
#if !EFI_PROD_CODE #if !EFI_PROD_CODE

View File

@ -48,6 +48,7 @@ public:
float getRpmAcceleration(); float getRpmAcceleration();
/** /**
* This is public because sometimes we cannot afford to call isRunning() and the value is good enough * This is public because sometimes we cannot afford to call isRunning() and the value is good enough
* Zero if engine is not running
*/ */
volatile int rpmValue; volatile int rpmValue;
int previousRpmValue; int previousRpmValue;

View File

@ -55,6 +55,7 @@ void testFuelMap(void) {
eth.engine.engineConfiguration->injector.battLagCorr[i] = 2 * i; eth.engine.engineConfiguration->injector.battLagCorr[i] = 2 * i;
} }
eth.engine.updateSlowSensors();
// because all the correction tables are zero // because all the correction tables are zero
printf("*************************************************** getRunningFuel 1\r\n"); printf("*************************************************** getRunningFuel 1\r\n");

View File

@ -373,6 +373,7 @@ static void testRpmCalculator(void) {
engine_configuration_s *engineConfiguration = &eth.persistentConfig.engineConfiguration; engine_configuration_s *engineConfiguration = &eth.persistentConfig.engineConfiguration;
initThermistors(PASS_ENGINE_PARAMETER_F); initThermistors(PASS_ENGINE_PARAMETER_F);
engine->updateSlowSensors();
engineConfiguration->trigger.customTotalToothCount = 8; engineConfiguration->trigger.customTotalToothCount = 8;
engineConfiguration->globalFuelCorrection = 3; engineConfiguration->globalFuelCorrection = 3;
@ -382,6 +383,7 @@ static void testRpmCalculator(void) {
// engine.engineConfiguration = eth.engine.engineConfiguration; // engine.engineConfiguration = eth.engine.engineConfiguration;
eth.engine.engineConfiguration->injector.lag = 0.0; eth.engine.engineConfiguration->injector.lag = 0.0;
engine->updateSlowSensors();
timeNow = 0; timeNow = 0;
assertEquals(0, eth.engine.rpmCalculator.rpm(PASS_ENGINE_PARAMETER_F)); assertEquals(0, eth.engine.rpmCalculator.rpm(PASS_ENGINE_PARAMETER_F));