2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
|
|
|
|
2021-06-03 11:40:19 -07:00
|
|
|
#include "defaults.h"
|
|
|
|
#include "table_helper.h"
|
|
|
|
|
2023-05-24 07:00:58 -07:00
|
|
|
#if EFI_ENGINE_CONTROL
|
2021-11-16 01:15:29 -08:00
|
|
|
static void setDefaultMultisparkParameters() {
|
2021-06-03 11:40:19 -07:00
|
|
|
// 1ms spark + 2ms dwell
|
2022-04-28 05:16:02 -07:00
|
|
|
engineConfiguration->multisparkSparkDuration = 1;
|
|
|
|
engineConfiguration->multisparkDwell = 2;
|
2021-06-03 11:40:19 -07:00
|
|
|
|
|
|
|
// Conservative defaults - probably won't blow up coils
|
|
|
|
engineConfiguration->multisparkMaxRpm = 1500;
|
|
|
|
engineConfiguration->multisparkMaxExtraSparkCount = 2;
|
|
|
|
engineConfiguration->multisparkMaxSparkingAngle = 30;
|
|
|
|
}
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
static void setDefaultIatTimingCorrection() {
|
2023-01-06 18:59:34 -08:00
|
|
|
copyArray(config->ignitionIatCorrTempBins, { -40, 0, 10, 20, 30, 40, 50, 60});
|
|
|
|
setLinearCurve(config->ignitionIatCorrLoadBins, /*from=*/ 0, /*to*/ 140, 1);
|
2021-06-03 11:40:19 -07:00
|
|
|
|
2023-01-06 18:59:34 -08:00
|
|
|
// top 5 rows are the same
|
|
|
|
for (size_t i = 3; i < 8; i++) {
|
|
|
|
// 40 50 60 deg C
|
|
|
|
copyArray(config->ignitionIatCorrTable[i], {0, 0, 0, 0, 0, -1, -2, -3});
|
2021-06-03 11:40:19 -07:00
|
|
|
}
|
2023-01-06 18:59:34 -08:00
|
|
|
|
|
|
|
// 6th row tapers out
|
|
|
|
// 40 50 60 deg C
|
|
|
|
copyArray(config->ignitionIatCorrTable[2], {0, 0, 0, 0, 0, 0, -1, -2});
|
2021-06-03 11:40:19 -07:00
|
|
|
}
|
|
|
|
|
2021-12-20 05:02:38 -08:00
|
|
|
static float getAdvanceForRpm(int rpm, float advanceMax) {
|
|
|
|
if (rpm >= 3000)
|
|
|
|
return advanceMax;
|
|
|
|
if (rpm < 600)
|
|
|
|
return 10;
|
|
|
|
return interpolateMsg("advance", 600, 10, 3000, advanceMax, rpm);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define round10(x) efiRound(x, 0.1)
|
|
|
|
|
|
|
|
float getInitialAdvance(int rpm, float map, float advanceMax) {
|
|
|
|
map = minF(map, 100);
|
|
|
|
float advance = getAdvanceForRpm(rpm, advanceMax);
|
|
|
|
|
|
|
|
if (rpm >= 3000)
|
|
|
|
return round10(advance + 0.1 * (100 - map));
|
|
|
|
return round10(advance + 0.1 * (100 - map) * rpm / 3000);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* this method builds a good-enough base timing advance map bases on a number of heuristics
|
|
|
|
*/
|
|
|
|
static void buildTimingMap(float advanceMax) {
|
|
|
|
if (engineConfiguration->fuelAlgorithm != LM_SPEED_DENSITY) {
|
2023-04-11 17:01:34 -07:00
|
|
|
warning(ObdCode::CUSTOM_WRONG_ALGORITHM, "wrong algorithm for MAP-based timing");
|
2021-12-20 05:02:38 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* good enough (but do not trust us!) default timing map in case of MAP-based engine load
|
|
|
|
*/
|
|
|
|
for (int loadIndex = 0; loadIndex < IGN_LOAD_COUNT; loadIndex++) {
|
|
|
|
float load = config->ignitionLoadBins[loadIndex];
|
|
|
|
for (int rpmIndex = 0;rpmIndex<IGN_RPM_COUNT;rpmIndex++) {
|
|
|
|
float rpm = config->ignitionRpmBins[rpmIndex];
|
|
|
|
config->ignitionTable[loadIndex][rpmIndex] = getInitialAdvance(rpm, load, advanceMax);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void setDefaultIgnition() {
|
2021-06-03 11:40:19 -07:00
|
|
|
// Ignition base settings
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->isIgnitionEnabled = true;
|
2021-06-03 11:40:19 -07:00
|
|
|
|
|
|
|
engineConfiguration->timingMode = TM_DYNAMIC;
|
|
|
|
engineConfiguration->fixedModeTiming = 50;
|
|
|
|
|
2023-07-21 20:20:50 -07:00
|
|
|
engineConfiguration->minimumIgnitionTiming = -10;
|
|
|
|
engineConfiguration->maximumIgnitionTiming = 60;
|
|
|
|
|
2021-06-03 11:40:19 -07:00
|
|
|
// Dwell table
|
2021-11-16 01:15:29 -08:00
|
|
|
setConstantDwell(4);
|
2021-06-03 11:40:19 -07:00
|
|
|
|
2022-04-28 05:16:02 -07:00
|
|
|
setLinearCurve(engineConfiguration->dwellVoltageCorrVoltBins, 8, 15, 0.1);
|
2022-04-13 12:21:31 -07:00
|
|
|
setLinearCurve(engineConfiguration->dwellVoltageCorrValues, 1, 1, 1);
|
|
|
|
|
2021-06-03 11:40:19 -07:00
|
|
|
// Multispark
|
2021-11-16 01:15:29 -08:00
|
|
|
setDefaultMultisparkParameters();
|
2021-06-03 11:40:19 -07:00
|
|
|
|
|
|
|
// Ignition advance table
|
2021-12-20 05:02:38 -08:00
|
|
|
setLinearCurve(config->ignitionLoadBins, 20, 120, 3);
|
2021-11-16 01:15:29 -08:00
|
|
|
setTimingRpmBin(800, 7000);
|
2021-12-20 05:02:38 -08:00
|
|
|
buildTimingMap(35);
|
2021-06-03 11:40:19 -07:00
|
|
|
|
2021-07-09 07:14:00 -07:00
|
|
|
engineConfiguration->trailingSparkAngle = 10;
|
|
|
|
|
2021-06-03 11:40:19 -07:00
|
|
|
// CLT correction
|
2022-05-01 20:43:43 -07:00
|
|
|
setLinearCurve(config->cltTimingBins, CLT_CURVE_RANGE_FROM, 120, 1);
|
|
|
|
setArrayValues(config->cltTimingExtra, 0.0f);
|
2021-06-03 11:40:19 -07:00
|
|
|
|
|
|
|
// IAT correction
|
2021-11-16 01:15:29 -08:00
|
|
|
setDefaultIatTimingCorrection();
|
2021-06-03 11:40:19 -07:00
|
|
|
}
|
2023-05-24 07:00:58 -07:00
|
|
|
#endif // EFI_ENGINE_CONTROL
|