rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
default_ignition.cpp
Go to the documentation of this file.
1#include "pch.h"
2
3#include "defaults.h"
4#include "table_helper.h"
5
6#if EFI_ENGINE_CONTROL
8 // 1ms spark + 2ms dwell
11
12 // Conservative defaults - probably won't blow up coils
16}
17
19 setLinearCurve(config->ignitionIatCorrLoadBins, /*from=*/ 0, /*to*/ 140, 1);
20#if IAT_IGN_CORR_COUNT == 8
21 copyArray(config->ignitionIatCorrTempBins, { -40, 0, 10, 20, 30, 40, 50, 60});
22
23 // top 5 rows are the same
24 for (size_t i = 3; i < IAT_IGN_CORR_COUNT; i++) {
25 // 40 50 60 deg C
26 copyArray(config->ignitionIatCorrTable[i], {0.0, 0.0, 0.0, 0.0, 0.0, -1.0, -2.0, -3.0});
27 }
28
29 // 6th row tapers out
30 // 40 50 60 deg C
31 copyArray(config->ignitionIatCorrTable[2], {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, -2.0});
32#else
33 setLinearCurve(config->ignitionIatCorrTempBins, /*from=*/ -40, /*to*/ 60, 1);
34#endif
35}
36
38 setLinearCurve(config->ignitionCltCorrLoadBins, /*from=*/ 0, /*to*/ 140, 1);
40
41#if CLT_TIMING_CURVE_SIZE == 5
42 for (size_t i = 0; i < CLT_TIMING_CURVE_SIZE; i++) {
43 // huh? use setArrayValues? and we probably get all zeros by default anyway?
44 copyArray(config->ignitionCltCorrTable[i], {0.0, 0.0, 0.0, 0.0, 0.0});
45 }
46#endif
47}
48
52
53#if TRAILING_SPARK_SIZE == 4
54 for (size_t i = 0; i < TRAILING_SPARK_SIZE; i++) {
55 copyArray(config->trailingSparkTable[i], {7,9,10,12});
56 }
57#endif
58
59}
60
61static float getAdvanceForRpm(float rpm, float advanceMax) {
62 if (rpm >= 3000) {
63 return advanceMax;
64 }
65
66 if (rpm < 600) {
67 return 10;
68 }
69
70 return interpolateMsg("advance", 600, 10, 3000, advanceMax, rpm);
71}
72
73#define round10(x) efiRound(x, 0.1)
74
75float getInitialAdvance(float rpm, float map, float advanceMax) {
76 map = std::min(map, 100.0f);
77 float advance = getAdvanceForRpm(rpm, advanceMax);
78
79 if (rpm >= 3000)
80 return round10(advance + 0.1 * (100 - map));
81 return round10(advance + 0.1 * (100 - map) * rpm / 3000);
82}
83
84/**
85 * this method builds a good-enough base timing advance map bases on a number of heuristics
86 */
87static void buildTimingMap(float advanceMax) {
88 if (engineConfiguration->fuelAlgorithm != engine_load_mode_e::LM_SPEED_DENSITY) {
89 warning(ObdCode::CUSTOM_WRONG_ALGORITHM, "wrong algorithm for MAP-based timing");
90 return;
91 }
92 /**
93 * good enough (but do not trust us!) default timing map in case of MAP-based engine load
94 */
95 for (int loadIndex = 0; loadIndex < IGN_LOAD_COUNT; loadIndex++) {
96 float load = config->ignitionLoadBins[loadIndex];
97 for (int rpmIndex = 0;rpmIndex<IGN_RPM_COUNT;rpmIndex++) {
98 float rpm = config->ignitionRpmBins[rpmIndex];
99 config->ignitionTable[loadIndex][rpmIndex] = getInitialAdvance(rpm, load, advanceMax);
100 }
101 }
102}
103
105 // Ignition base settings
107
108 engineConfiguration->timingMode = TM_DYNAMIC;
110
113
114 // Dwell table - a bit conservative but reasonable
116
119
120 // Multispark
122
123 // Ignition advance table
125 setTimingRpmBin(800, 7000);
126 buildTimingMap(35);
127
129
130 // CLT correction
132
133 // IAT correction
135
136 // Give default axes for cylinder trim tables
137#if IGN_TRIM_SIZE == 4
138 copyArray(config->ignTrimRpmBins, { 1000, 3000, 5000, 7000 });
139 copyArray(config->ignTrimLoadBins, { 20, 50, 80, 100 });
140#else
143#endif
144
145 // Default axes for VE blends
146 for (size_t i = 0; i < efi::size(config->ignBlends); i++) {
147 auto& blend = config->ignBlends[i];
148 setLinearCurve(blend.loadBins, 0, 100, 10);
149 setLinearCurve(blend.rpmBins, 0, 7000);
150
151 setLinearCurve(blend.blendBins, 0, 100);
152 setLinearCurve(blend.blendValues, 0, 100);
153 }
154}
155#endif // EFI_ENGINE_CONTROL
static void setDefaultCltTimingCorrection()
static void setDefaultTrailingSparkTable()
static void buildTimingMap(float advanceMax)
float getInitialAdvance(float rpm, float map, float advanceMax)
static void setDefaultMultisparkParameters()
void setDefaultIgnition()
static float getAdvanceForRpm(float rpm, float advanceMax)
static void setDefaultIatTimingCorrection()
float interpolateMsg(const char *msg, float x1, float y1, float x2, float y2, float x)
Linear interpolation by two points.
void setConstantDwell(floatms_t dwellMs)
Sets the same dwell time across the whole getRpm() range set dwell X.
static constexpr persistent_config_s * config
static constexpr engine_configuration_s * engineConfiguration
void setTimingRpmBin(float from, float to)
bool warning(ObdCode code, const char *fmt,...)
@ CUSTOM_WRONG_ALGORITHM
scaled_channel< uint8_t, 10, 1 > dwellVoltageCorrVoltBins[DWELL_CURVE_SIZE]
scaled_channel< int8_t, 10, 1 > trailingSparkTable[TRAILING_SPARK_SIZE][TRAILING_SPARK_SIZE]
scaled_channel< uint8_t, 1, 5 > trailingSparkLoadBins[TRAILING_SPARK_SIZE]
scaled_channel< uint8_t, 50, 1 > dwellVoltageCorrValues[DWELL_CURVE_SIZE]
scaled_channel< int16_t, 10, 1 > ignitionCltCorrTable[CLT_TIMING_CURVE_SIZE][CLT_TIMING_CURVE_SIZE]
scaled_channel< int16_t, 1, 1 > ignitionCltCorrTempBins[CLT_TIMING_CURVE_SIZE]
scaled_channel< uint8_t, 1, 50 > trailingSparkRpmBins[TRAILING_SPARK_SIZE]
scaled_channel< int16_t, 10, 1 > ignitionIatCorrTable[IAT_IGN_CORR_LOAD_COUNT][IAT_IGN_CORR_COUNT]
scaled_channel< int16_t, 10, 1 > ignitionTable[IGN_LOAD_COUNT][IGN_RPM_COUNT]
scaled_channel< uint8_t, 1, 5 > ignitionIatCorrLoadBins[IAT_IGN_CORR_LOAD_COUNT]
scaled_channel< uint8_t, 1, 5 > ignitionCltCorrLoadBins[CLT_TIMING_CURVE_SIZE]
void setRpmTableBin(TValue(&array)[TSize])
void setLinearCurve(TValue(&array)[TSize], float from, float to, float precision=0.01f)