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 211 of file ignition_state.cpp.

211 {
212 if (std::isnan(engineLoad)) {
213 return 0; // any error should already be reported
214 }
215 if (engineConfiguration->timingMode == TM_FIXED) {
216 // fixed timing is the simple: cranking/running does not matter, no corrections!
218 }
219
220 angle_t angle;
221
222 bool isCranking = engine->rpmCalculator.isCranking();
223 if (isCranking) {
224 angle = getCrankingAdvance(rpm, engineLoad);
225 assertAngleRange(angle, "crAngle", ObdCode::CUSTOM_ERR_ANGLE_CR);
226 efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !std::isnan(angle), "cr_AngleN", 0);
227 } else {
228 angle = getRunningAdvance(rpm, engineLoad);
229
230 if (std::isnan(angle)) {
231 warning(ObdCode::CUSTOM_ERR_6610, "NaN angle from table");
232 return 0;
233 }
234 }
235
236 // Allow if we're either not cranking OR allowed to correct in cranking
237 bool allowCorrections = !isCranking || engineConfiguration->useAdvanceCorrectionsForCranking;
238
239 if (allowCorrections) {
240 angle_t correction = getAdvanceCorrections(engineLoad);
241 if (!std::isnan(correction)) { // correction could be NaN during settings update
242 angle += correction;
243 }
244 }
245
246 efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !std::isnan(angle), "_AngleN5", 0);
247 return angle;
248}
angle_t getAdvanceCorrections(float engineLoad)
angle_t getCrankingAdvance(float rpm, float engineLoad)
angle_t getRunningAdvance(float rpm, float engineLoad)
RpmCalculator rpmCalculator
Definition engine.h:314
bool isCranking() const override
static EngineAccessor engine
Definition engine.h:421
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 342 of file ignition_state.cpp.

342 {
343 return sparkDwell;
344}

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 368 of file ignition_state.cpp.

368 {
369 return interpolate3d(
373 );
374}
static constexpr persistent_config_s * config
ignitionLoad("Ignition: load", SensorCategory.SENSOR_INPUTS, FieldType.INT, 1420, 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 376 of file ignition_state.cpp.

380 {
381 return interpolate3d(
382 config->ignTrims[cylinderNumber].table,
385 );
386}
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 307 of file ignition_state.cpp.

307 {
308 float dwellMs;
309 if (isCranking) {
311 } else {
312 efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !std::isnan(rpm), "invalid rpm", NAN);
313
315 dwellVoltageCorrection = interpolate2d(
319 );
320
321 // for compat (table full of zeroes)
322 if (dwellVoltageCorrection < 0.1f) {
324 }
325
327 }
328
329 if (std::isnan(dwellMs) || dwellMs <= 0) {
330 // this could happen during engine configuration reset
331 warning(ObdCode::CUSTOM_ERR_DWELL_DURATION, "invalid dwell: %.2f at rpm=%.0f", dwellMs, rpm);
332 return 0;
333 }
334 return dwellMs;
335}
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 358 of file ignition_state.cpp.

358 {
359 // time => degree
361
362 if (!std::isnan(correction)) {
363 return correction;
364 }
365 return 0;
366}
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 346 of file ignition_state.cpp.

346 {
347 if (std::isnan(engineLoad)) {
348 // default value from: https://github.com/rusefi/rusefi/commit/86683afca22ed1a8af8fd5ac9231442e2124646e#diff-6e80cdd8c55add68105618ad9e8954170a47f59814201dadd2b888509d6b2e39R176
349 return 10;
350 }
351 return interpolate3d(
353 config->trailingSparkLoadBins, engineLoad,
355 );
356}
scaled_channel< uint8_t, 1, 50 > trailingSparkRpmBins[TRAILING_SPARK_RPM_SIZE]
scaled_channel< uint8_t, 1, 5 > trailingSparkLoadBins[TRAILING_SPARK_SIZE]
scaled_channel< int8_t, 10, 1 > trailingSparkTable[TRAILING_SPARK_SIZE][TRAILING_SPARK_RPM_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 250 of file ignition_state.cpp.

250 {
251 angle_t angle = getAdvance(rpm, engineLoad) * luaTimingMult + luaTimingAdd;
252 wrapAngle(angle, "getWrappedAdvance", ObdCode::CUSTOM_ERR_ADCANCE_CALC_ANGLE);
253 return angle;
254}
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 160 of file ignition_state.cpp.

160 {
162}
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 337 of file ignition_state.cpp.

337 {
338 sparkDwell = getSparkDwell(rpm, isCranking);
339 dwellDurationAngle = std::isnan(rpm) ? NAN : getDwell() / getOneDegreeTimeMs(rpm);
340}
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: