firmware/controllers/algo/defaults/default_ignition.cpp
| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | #include "pch.h" | |||
| 2 | ||||
| 3 | #include "defaults.h" | |||
| 4 | #include "table_helper.h" | |||
| 5 | ||||
| 6 | #if EFI_ENGINE_CONTROL | |||
| 7 | 601 | static void setDefaultMultisparkParameters() { | ||
| 8 | // 1ms spark + 2ms dwell | |||
| 9 | 601 | engineConfiguration->multisparkSparkDuration = 1; | ||
| 10 | 601 | engineConfiguration->multisparkDwell = 2; | ||
| 11 | ||||
| 12 | // Conservative defaults - probably won't blow up coils | |||
| 13 | 601 | engineConfiguration->multisparkMaxRpm = 1500; | ||
| 14 | 601 | engineConfiguration->multisparkMaxExtraSparkCount = 2; | ||
| 15 | 601 | engineConfiguration->multisparkMaxSparkingAngle = 30; | ||
| 16 | 601 | } | ||
| 17 | ||||
| 18 | 601 | static void setDefaultIatTimingCorrection() { | ||
| 19 | 601 | setLinearCurve(config->ignitionIatCorrLoadBins, /*from=*/ 0, /*to*/ 140, 1); | ||
| 20 | ||||
| 21 |
1/1✓ Branch 2 taken 601 times.
|
601 | copyArrayInterpolated(config->ignitionIatCorrTempBins, { -40, 0, 10, 20, 30, 40, 50, 60}); | |
| 22 | ||||
| 23 | // top rows are the same | |||
| 24 |
2/2✓ Branch 1 taken 4207 times.
✓ Branch 2 taken 601 times.
|
2/2✓ Decision 'true' taken 4207 times.
✓ Decision 'false' taken 601 times.
|
4808 | for (size_t i = 0; i < efi::size(config->ignitionIatCorrTable) - 1; i++) { |
| 25 | // 40 50 60 deg C | |||
| 26 |
1/1✓ Branch 3 taken 4207 times.
|
4207 | copyArrayInterpolated(config->ignitionIatCorrTable[i], {0.0, 0.0, 0.0, 0.0, 0.0, -1.0, -2.0, -3.0}); | |
| 27 | } | |||
| 28 | ||||
| 29 | // last row tapers out | |||
| 30 | // 40 50 60 deg C | |||
| 31 |
1/1✓ Branch 4 taken 601 times.
|
601 | copyArrayInterpolated(config->ignitionIatCorrTable[efi::size(config->ignitionIatCorrTable) - 1], {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, -2.0}); | |
| 32 | 601 | } | ||
| 33 | ||||
| 34 | 601 | static void setDefaultCltTimingCorrection() { | ||
| 35 | 601 | setLinearCurve(config->ignitionCltCorrLoadBins, /*from=*/ 0, /*to*/ 140, 1); | ||
| 36 | 601 | setLinearCurve(config->ignitionCltCorrTempBins, -20, 60, 1); | ||
| 37 | ||||
| 38 | #if CLT_TIMING_TEMP_AXIS_SIZE == 5 | |||
| 39 |
2/2✓ Branch 0 taken 3005 times.
✓ Branch 1 taken 601 times.
|
2/2✓ Decision 'true' taken 3005 times.
✓ Decision 'false' taken 601 times.
|
3606 | for (size_t i = 0; i < CLT_TIMING_TEMP_AXIS_SIZE; i++) { |
| 40 | // huh? use setArrayValues? and we probably get all zeros by default anyway? | |||
| 41 | 3005 | copyArray(config->ignitionCltCorrTable[i], {0.0, 0.0, 0.0, 0.0, 0.0}); | ||
| 42 | } | |||
| 43 | #endif | |||
| 44 | 601 | } | ||
| 45 | ||||
| 46 | 601 | static void setDefaultTrailingSparkTable() { | ||
| 47 | 601 | setLinearCurve(config->trailingSparkLoadBins, 20, 100, 1); | ||
| 48 | 601 | setRpmTableBin(config->trailingSparkRpmBins); | ||
| 49 | ||||
| 50 | #if TRAILING_SPARK_SIZE == 4 | |||
| 51 |
2/2✓ Branch 0 taken 2404 times.
✓ Branch 1 taken 601 times.
|
2/2✓ Decision 'true' taken 2404 times.
✓ Decision 'false' taken 601 times.
|
3005 | for (size_t i = 0; i < TRAILING_SPARK_SIZE; i++) { |
| 52 |
1/1✓ Branch 3 taken 2404 times.
|
2404 | copyArray(config->trailingSparkTable[i], {7,9,10,12}); | |
| 53 | } | |||
| 54 | #endif | |||
| 55 | ||||
| 56 | 601 | } | ||
| 57 | ||||
| 58 | 153861 | static float getAdvanceForRpm(float rpm, float advanceMax) { | ||
| 59 |
2/2✓ Branch 0 taken 67314 times.
✓ Branch 1 taken 86547 times.
|
2/2✓ Decision 'true' taken 67314 times.
✓ Decision 'false' taken 86547 times.
|
153861 | if (rpm >= 3000) { |
| 60 | 67314 | return advanceMax; | ||
| 61 | } | |||
| 62 | ||||
| 63 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 86547 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 86547 times.
|
86547 | if (rpm < 600) { |
| 64 | ✗ | return 10; | ||
| 65 | } | |||
| 66 | ||||
| 67 | 86547 | return interpolateMsg("advance", 600, 10, 3000, advanceMax, rpm); | ||
| 68 | } | |||
| 69 | ||||
| 70 | #define round10(x) efiRound(x, 0.1) | |||
| 71 | ||||
| 72 | 153861 | float getInitialAdvance(float rpm, float map, float advanceMax) { | ||
| 73 | 153861 | map = std::min(map, 100.0f); | ||
| 74 | 153861 | float advance = getAdvanceForRpm(rpm, advanceMax); | ||
| 75 | ||||
| 76 |
2/2✓ Branch 0 taken 67314 times.
✓ Branch 1 taken 86547 times.
|
2/2✓ Decision 'true' taken 67314 times.
✓ Decision 'false' taken 86547 times.
|
153861 | if (rpm >= 3000) |
| 77 | 67314 | return round10(advance + 0.1 * (100 - map)); | ||
| 78 | 86547 | return round10(advance + 0.1 * (100 - map) * rpm / 3000); | ||
| 79 | } | |||
| 80 | ||||
| 81 | /** | |||
| 82 | * this method builds a good-enough base timing advance map bases on a number of heuristics | |||
| 83 | */ | |||
| 84 | 601 | static void buildTimingMap(float advanceMax) { | ||
| 85 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 601 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 601 times.
|
601 | if (engineConfiguration->fuelAlgorithm != engine_load_mode_e::LM_SPEED_DENSITY) { |
| 86 | ✗ | warning(ObdCode::CUSTOM_WRONG_ALGORITHM, "wrong algorithm for MAP-based timing"); | ||
| 87 | ✗ | return; | ||
| 88 | } | |||
| 89 | /** | |||
| 90 | * good enough (but do not trust us!) default timing map in case of MAP-based engine load | |||
| 91 | */ | |||
| 92 |
2/2✓ Branch 0 taken 9616 times.
✓ Branch 1 taken 601 times.
|
2/2✓ Decision 'true' taken 9616 times.
✓ Decision 'false' taken 601 times.
|
10217 | for (int loadIndex = 0; loadIndex < IGN_LOAD_COUNT; loadIndex++) { |
| 93 | 9616 | float load = config->ignitionLoadBins[loadIndex]; | ||
| 94 |
2/2✓ Branch 0 taken 153856 times.
✓ Branch 1 taken 9616 times.
|
2/2✓ Decision 'true' taken 153856 times.
✓ Decision 'false' taken 9616 times.
|
163472 | for (int rpmIndex = 0;rpmIndex<IGN_RPM_COUNT;rpmIndex++) { |
| 95 | 153856 | float rpm = config->ignitionRpmBins[rpmIndex]; | ||
| 96 |
1/1✓ Branch 2 taken 153856 times.
|
153856 | config->ignitionTable[loadIndex][rpmIndex] = getInitialAdvance(rpm, load, advanceMax); | |
| 97 | } | |||
| 98 | } | |||
| 99 | } | |||
| 100 | ||||
| 101 | 601 | void setDefaultIgnition() { | ||
| 102 | // Ignition base settings | |||
| 103 | 601 | engineConfiguration->isIgnitionEnabled = true; | ||
| 104 | ||||
| 105 | 601 | engineConfiguration->timingMode = TM_DYNAMIC; | ||
| 106 | 601 | engineConfiguration->fixedModeTiming = 50; | ||
| 107 | ||||
| 108 | 601 | engineConfiguration->minimumIgnitionTiming = -10; | ||
| 109 | 601 | engineConfiguration->maximumIgnitionTiming = 60; | ||
| 110 | ||||
| 111 | // Dwell table - a bit conservative but reasonable | |||
| 112 | 601 | setConstantDwell(4); | ||
| 113 | ||||
| 114 | 601 | setLinearCurve(config->dwellVoltageCorrVoltBins, 8, 15, 0.1); | ||
| 115 | 601 | setLinearCurve(config->dwellVoltageCorrValues, 1, 1, 1); | ||
| 116 | ||||
| 117 | // Multispark | |||
| 118 | 601 | setDefaultMultisparkParameters(); | ||
| 119 | ||||
| 120 | // Ignition advance table | |||
| 121 | 601 | setLinearCurve(config->ignitionLoadBins, 20, 120, 3); | ||
| 122 | 601 | setTimingRpmBin(800, 7000); | ||
| 123 | 601 | buildTimingMap(35); | ||
| 124 | ||||
| 125 | 601 | setDefaultTrailingSparkTable(); | ||
| 126 | ||||
| 127 | // CLT correction | |||
| 128 | 601 | setDefaultCltTimingCorrection(); | ||
| 129 | ||||
| 130 | // IAT correction | |||
| 131 | 601 | setDefaultIatTimingCorrection(); | ||
| 132 | ||||
| 133 | // Give default axes for cylinder trim tables | |||
| 134 | #if IGN_TRIM_SIZE == 4 | |||
| 135 | 601 | copyArray(config->ignTrimRpmBins, { 1000, 3000, 5000, 7000 }); | ||
| 136 | 601 | copyArray(config->ignTrimLoadBins, { 20, 50, 80, 100 }); | ||
| 137 | #else | |||
| 138 | setRpmTableBin(config->ignTrimRpmBins); | |||
| 139 | setLinearCurve(config->ignTrimLoadBins, 20, 100); | |||
| 140 | #endif | |||
| 141 | ||||
| 142 | // Default axes for VE blends | |||
| 143 |
2/2✓ Branch 1 taken 2404 times.
✓ Branch 2 taken 601 times.
|
2/2✓ Decision 'true' taken 2404 times.
✓ Decision 'false' taken 601 times.
|
3005 | for (size_t i = 0; i < efi::size(config->ignBlends); i++) { |
| 144 | 2404 | auto& blend = config->ignBlends[i]; | ||
| 145 | 2404 | setLinearCurve(blend.loadBins, 0, 100, 10); | ||
| 146 | 2404 | setLinearCurve(blend.rpmBins, 0, 7000); | ||
| 147 | ||||
| 148 | 2404 | setLinearCurve(blend.blendBins, 0, 100); | ||
| 149 | 2404 | setLinearCurve(blend.blendValues, 0, 100); | ||
| 150 | } | |||
| 151 | 601 | } | ||
| 152 | #endif // EFI_ENGINE_CONTROL | |||
| 153 |