rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions
IgnitionState Class Reference

#include <ignition_state.h>

Inheritance diagram for IgnitionState:
Inheritance graph
[legend]
Collaboration diagram for IgnitionState:
Collaboration graph
[legend]

Public Member Functions

void updateDwell (float rpm, bool isCranking)
 
void updateAdvanceCorrections (float engineLoad)
 
floatms_t getDwell () const
 
angle_t getWrappedAdvance (const float rpm, const float engineLoad)
 
angle_t getTrailingSparkAngle (const float rpm, const float engineLoad)
 
angle_t getSparkHardwareLatencyCorrection ()
 

Static Public Member Functions

static angle_t getInterpolatedIgnitionAngle (float rpm, float ignitionLoad)
 
static angle_t getInterpolatedIgnitionTrim (size_t cylinderNumber, float rpm, float ignitionLoad)
 

Private Member Functions

angle_t getAdvance (float rpm, float engineLoad)
 
floatms_t getSparkDwell (float rpm, bool isCranking)
 

Additional Inherited Members

- Data Fields inherited from ignition_state_s
float baseDwell = (float)0
 
floatms_t sparkDwell = (floatms_t)0
 
angle_t dwellDurationAngle = (angle_t)0
 
scaled_channel< int16_t, 100, 1 > cltTimingCorrection = (int16_t)0
 
scaled_channel< int16_t, 100, 1 > timingIatCorrection = (int16_t)0
 
scaled_channel< int16_t, 100, 1 > timingPidCorrection = (int16_t)0
 
scaled_channel< int16_t, 100, 1 > dfcoTimingRetard = (int16_t)0
 
scaled_channel< int16_t, 50, 1 > baseIgnitionAdvance = (int16_t)0
 
scaled_channel< int16_t, 50, 1 > correctedIgnitionAdvance = (int16_t)0
 
scaled_channel< int16_t, 50, 1 > tractionAdvanceDrop = (int16_t)0
 
uint8_t alignmentFill_at_26 [2] = {}
 
float dwellVoltageCorrection = (float)0
 
float luaTimingAdd = (float)0
 
float luaTimingMult = (float)0
 
bool luaIgnitionSkip: 1 {}
 
bool unusedBit_15_1: 1 {}
 
bool unusedBit_15_2: 1 {}
 
bool unusedBit_15_3: 1 {}
 
bool unusedBit_15_4: 1 {}
 
bool unusedBit_15_5: 1 {}
 
bool unusedBit_15_6: 1 {}
 
bool unusedBit_15_7: 1 {}
 
bool unusedBit_15_8: 1 {}
 
bool unusedBit_15_9: 1 {}
 
bool unusedBit_15_10: 1 {}
 
bool unusedBit_15_11: 1 {}
 
bool unusedBit_15_12: 1 {}
 
bool unusedBit_15_13: 1 {}
 
bool unusedBit_15_14: 1 {}
 
bool unusedBit_15_15: 1 {}
 
bool unusedBit_15_16: 1 {}
 
bool unusedBit_15_17: 1 {}
 
bool unusedBit_15_18: 1 {}
 
bool unusedBit_15_19: 1 {}
 
bool unusedBit_15_20: 1 {}
 
bool unusedBit_15_21: 1 {}
 
bool unusedBit_15_22: 1 {}
 
bool unusedBit_15_23: 1 {}
 
bool unusedBit_15_24: 1 {}
 
bool unusedBit_15_25: 1 {}
 
bool unusedBit_15_26: 1 {}
 
bool unusedBit_15_27: 1 {}
 
bool unusedBit_15_28: 1 {}
 
bool unusedBit_15_29: 1 {}
 
bool unusedBit_15_30: 1 {}
 
bool unusedBit_15_31: 1 {}
 
scaled_channel< int16_t, 100, 1 > trailingSparkAngle = (int16_t)0
 
int16_t rpmForIgnitionTableDot = (int16_t)0
 
int16_t rpmForIgnitionIdleTableDot = (int16_t)0
 
uint8_t alignmentFill_at_50 [2] = {}
 
float loadForIgnitionTableDot = (float)0
 

Detailed Description

Definition at line 5 of file ignition_state.h.

Member Function Documentation

◆ getAdvance()

angle_t IgnitionState::getAdvance ( float  rpm,
float  engineLoad 
)
private

Definition at line 217 of file ignition_state.cpp.

217 {
218 if (std::isnan(engineLoad)) {
219 return 0; // any error should already be reported
220 }
221 if (engineConfiguration->timingMode == TM_FIXED) {
222 // fixed timing is the simple: cranking/running does not matter, no corrections!
224 }
225
226 angle_t angle;
227
228 bool isCranking = engine->rpmCalculator.isCranking();
229 if (isCranking) {
230 angle = getCrankingAdvance(rpm, engineLoad);
231 assertAngleRange(angle, "crAngle", ObdCode::CUSTOM_ERR_ANGLE_CR);
232 efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !std::isnan(angle), "cr_AngleN", 0);
233 } else {
234 angle = getRunningAdvance(rpm, engineLoad);
235
236 if (std::isnan(angle)) {
237 warning(ObdCode::CUSTOM_ERR_6610, "NaN angle from table");
238 return 0;
239 }
240 }
241
242 // Allow if we're either not cranking OR allowed to correct in cranking
243 bool allowCorrections = !isCranking || engineConfiguration->useAdvanceCorrectionsForCranking;
244
245 if (allowCorrections) {
246 angle_t correction = getAdvanceCorrections(engineLoad);
247 if (!std::isnan(correction)) { // correction could be NaN during settings update
248 angle += correction;
249 }
250 }
251
252 efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !std::isnan(angle), "_AngleN5", 0);
253 return angle;
254}
angle_t getAdvanceCorrections(float engineLoad)
angle_t getCrankingAdvance(float rpm, float engineLoad)
angle_t getRunningAdvance(float rpm, float engineLoad)
RpmCalculator rpmCalculator
Definition engine.h:306
bool isCranking() const override
static EngineAccessor engine
Definition engine.h:413
static constexpr engine_configuration_s * engineConfiguration
bool warning(ObdCode code, const char *fmt,...)
@ CUSTOM_ERR_6610
@ CUSTOM_ERR_ANGLE_CR
@ CUSTOM_ERR_ASSERT
float angle_t

Referenced by getWrappedAdvance().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getDwell()

floatms_t IgnitionState::getDwell ( ) const

Definition at line 348 of file ignition_state.cpp.

348 {
349 return sparkDwell;
350}

Referenced by fireSparkAndPrepareNextSchedule(), getCoilDutyCycle(), initializeIgnitionActions(), onTriggerEventSparkLogic(), and updateDwell().

Here is the caller graph for this function:

◆ getInterpolatedIgnitionAngle()

angle_t IgnitionState::getInterpolatedIgnitionAngle ( float  rpm,
float  ignitionLoad 
)
static

Definition at line 374 of file ignition_state.cpp.

374 {
375 return interpolate3d(
379 );
380}
static constexpr persistent_config_s * config
ignitionLoad("Ignition: load", SensorCategory.SENSOR_INPUTS, FieldType.INT, 1412, 1.0, -1.0, -1.0, "")
scaled_channel< int16_t, 10, 1 > ignitionTable[IGN_LOAD_COUNT][IGN_RPM_COUNT]

Referenced by getRunningAdvance().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getInterpolatedIgnitionTrim()

angle_t IgnitionState::getInterpolatedIgnitionTrim ( size_t  cylinderNumber,
float  rpm,
float  ignitionLoad 
)
static

Definition at line 382 of file ignition_state.cpp.

386 {
387 return interpolate3d(
388 config->ignTrims[cylinderNumber].table,
391 );
392}
scaled_channel< int8_t, 5, 1 > table[IGN_TRIM_SIZE][IGN_TRIM_SIZE]

Referenced by getCylinderIgnitionTrim().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSparkDwell()

floatms_t IgnitionState::getSparkDwell ( float  rpm,
bool  isCranking 
)
private
Returns
Spark dwell time, in milliseconds. 0 if tables are not ready.

Definition at line 313 of file ignition_state.cpp.

313 {
314 float dwellMs;
315 if (isCranking) {
317 } else {
318 efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !std::isnan(rpm), "invalid rpm", NAN);
319
321 dwellVoltageCorrection = interpolate2d(
325 );
326
327 // for compat (table full of zeroes)
328 if (dwellVoltageCorrection < 0.1f) {
330 }
331
333 }
334
335 if (std::isnan(dwellMs) || dwellMs <= 0) {
336 // this could happen during engine configuration reset
337 warning(ObdCode::CUSTOM_ERR_DWELL_DURATION, "invalid dwell: %.2f at rpm=%.0f", dwellMs, rpm);
338 return 0;
339 }
340 return dwellMs;
341}
static float getOrZero(SensorType type)
Definition sensor.h:83
@ CUSTOM_ERR_DWELL_DURATION
scaled_channel< uint8_t, 10, 1 > dwellVoltageCorrVoltBins[DWELL_CURVE_SIZE]
scaled_channel< uint8_t, 50, 1 > dwellVoltageCorrValues[DWELL_CURVE_SIZE]
scaled_channel< uint16_t, 100, 1 > sparkDwellValues[DWELL_CURVE_SIZE]

Referenced by updateDwell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSparkHardwareLatencyCorrection()

angle_t IgnitionState::getSparkHardwareLatencyCorrection ( )

Definition at line 364 of file ignition_state.cpp.

364 {
365 // time => degree
367
368 if (!std::isnan(correction)) {
369 return correction;
370 }
371 return 0;
372}
floatus_t oneDegreeUs

Referenced by EngineState::periodicFastCallback().

Here is the caller graph for this function:

◆ getTrailingSparkAngle()

angle_t IgnitionState::getTrailingSparkAngle ( const float  rpm,
const float  engineLoad 
)

Definition at line 352 of file ignition_state.cpp.

352 {
353 if (std::isnan(engineLoad)) {
354 // default value from: https://github.com/rusefi/rusefi/commit/86683afca22ed1a8af8fd5ac9231442e2124646e#diff-6e80cdd8c55add68105618ad9e8954170a47f59814201dadd2b888509d6b2e39R176
355 return 10;
356 }
357 return interpolate3d(
359 config->trailingSparkLoadBins, engineLoad,
361 );
362}
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, 1, 50 > trailingSparkRpmBins[TRAILING_SPARK_SIZE]

Referenced by EngineState::periodicFastCallback().

Here is the caller graph for this function:

◆ getWrappedAdvance()

angle_t IgnitionState::getWrappedAdvance ( const float  rpm,
const float  engineLoad 
)

Definition at line 256 of file ignition_state.cpp.

256 {
257 angle_t angle = getAdvance(rpm, engineLoad) * luaTimingMult + luaTimingAdd;
258 wrapAngle(angle, "getWrappedAdvance", ObdCode::CUSTOM_ERR_ADCANCE_CALC_ANGLE);
259 return angle;
260}
angle_t getAdvance(float rpm, float engineLoad)
@ CUSTOM_ERR_ADCANCE_CALC_ANGLE
void wrapAngle(angle_t &angle, const char *msg, ObdCode code)

Referenced by EngineState::periodicFastCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateAdvanceCorrections()

void IgnitionState::updateAdvanceCorrections ( float  engineLoad)

Definition at line 164 of file ignition_state.cpp.

164 {
166}
angle_t getCltTimingCorrection()
scaled_channel< int16_t, 100, 1 > cltTimingCorrection

Referenced by EngineState::periodicFastCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateDwell()

void IgnitionState::updateDwell ( float  rpm,
bool  isCranking 
)

Definition at line 343 of file ignition_state.cpp.

343 {
344 sparkDwell = getSparkDwell(rpm, isCranking);
345 dwellDurationAngle = std::isnan(rpm) ? NAN : getDwell() / getOneDegreeTimeMs(rpm);
346}
floatms_t getSparkDwell(float rpm, bool isCranking)
floatms_t getDwell() const

Referenced by EngineState::periodicFastCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files: