rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Data Structures | Enumerations | Functions
rpm_calculator.h File Reference

Detailed Description

Shaft position sensor(s) decoder header.

Date
Jan 1, 2013
Author
Andrey Belomutskiy, (c) 2012-2020

Definition in file rpm_calculator.h.

Data Structures

class  RpmCalculator
 

Enumerations

enum  spinning_state_e { STOPPED , SPINNING_UP , CRANKING , RUNNING }
 

Functions

void rpmShaftPositionCallback (trigger_event_e ckpSignalType, uint32_t trgEventIndex, efitick_t edgeTimestamp)
 Shaft position callback used by RPM calculation logic.
 
void tdcMarkCallback (uint32_t trgEventIndex, efitick_t edgeTimestamp)
 
operation_mode_e lookupOperationMode ()
 
efitick_t scheduleByAngle (scheduling_s *timer, efitick_t nowNt, angle_t angle, action_s const &action)
 

Enumeration Type Documentation

◆ spinning_state_e

Enumerator
STOPPED 

The engine is not spinning, RPM=0

SPINNING_UP 

The engine is spinning up (reliable RPM is not detected yet). In this state, rpmValue is >= 0 (can be zero).

CRANKING 

The engine is cranking (0 < RPM < cranking.rpm)

RUNNING 

The engine is running (RPM >= cranking.rpm)

Definition at line 19 of file rpm_calculator.h.

19 {
20 /**
21 * The engine is not spinning, RPM=0
22 */
23 STOPPED,
24 /**
25 * The engine is spinning up (reliable RPM is not detected yet).
26 * In this state, rpmValue is >= 0 (can be zero).
27 */
29 /**
30 * The engine is cranking (0 < RPM < cranking.rpm)
31 */
33 /**
34 * The engine is running (RPM >= cranking.rpm)
35 */
36 RUNNING,
spinning_state_e
@ RUNNING
@ SPINNING_UP
@ CRANKING
@ STOPPED

Function Documentation

◆ lookupOperationMode()

operation_mode_e lookupOperationMode ( )

Definition at line 53 of file rpm_calculator.cpp.

Referenced by TriggerCentral::applyShapesConfiguration(), and RpmCalculator::getOperationMode().

Here is the caller graph for this function:

◆ rpmShaftPositionCallback()

void rpmShaftPositionCallback ( trigger_event_e  ckpSignalType,
uint32_t  trgEventIndex,
efitick_t  nowNt 
)

Shaft position callback used by RPM calculation logic.

This callback should always be the first of trigger callbacks because other callbacks depend of values updated here. This callback is invoked on interrupt thread.

Four stroke cycle is two crankshaft revolutions

We always do '* 2' because the event signal is already adjusted to 'per engine cycle' and each revolution of crankshaft consists of two engine cycles revolutions

Definition at line 253 of file rpm_calculator.cpp.

254 {
255
256 bool alwaysInstantRpm = engineConfiguration->alwaysInstantRpm;
257
258 RpmCalculator *rpmState = &engine->rpmCalculator;
259
260 if (trgEventIndex == 0) {
261 if (HAVE_CAM_INPUT()) {
263 }
264
265
266 bool hadRpmRecently = rpmState->checkIfSpinning(nowNt);
267
268 float periodSeconds = engine->rpmCalculator.lastTdcTimer.getElapsedSecondsAndReset(nowNt);
269
270 if (hadRpmRecently) {
271 /**
272 * Four stroke cycle is two crankshaft revolutions
273 *
274 * We always do '* 2' because the event signal is already adjusted to 'per engine cycle'
275 * and each revolution of crankshaft consists of two engine cycles revolutions
276 *
277 */
278 if (!alwaysInstantRpm) {
279 if (periodSeconds == 0) {
280 rpmState->setRpmValue(0);
281 rpmState->rpmRate = 0;
282 } else {
283 // todo: extract utility method? see duplication with high_pressure_pump.cpp
284 int mult = (int)getEngineCycle(getEngineRotationState()->getOperationMode()) / 360;
285 float rpm = 60 * mult / periodSeconds;
286
287 auto rpmDelta = rpm - rpmState->previousRpmValue;
288 rpmState->rpmRate = rpmDelta / (mult * periodSeconds);
289
290 rpmState->setRpmValue(rpm);
291 }
292 }
293 } else {
294 // we are here only once trigger is synchronized for the first time
295 // while transitioning from 'spinning' to 'running'
297 }
298
299 rpmState->onNewEngineCycle();
300 }
301
302
303 // Always update instant RPM even when not spinning up
306
308 trgEventIndex, nowNt);
309
311 if (alwaysInstantRpm) {
312 rpmState->setRpmValue(instantRpm);
313 } else if (rpmState->isSpinningUp()) {
314 rpmState->assignRpmValue(instantRpm);
315#if 0
316 efiPrintf("** RPM: idx=%d sig=%d iRPM=%d", trgEventIndex, ckpSignalType, instantRpm);
317#else
318 UNUSED(ckpSignalType);
319#endif
320 }
321}
TriggerCentral triggerCentral
Definition engine.h:318
RpmCalculator rpmCalculator
Definition engine.h:306
virtual operation_mode_e getOperationMode() const =0
void updateInstantRpm(uint32_t current_index, TriggerWaveform const &triggerShape, TriggerFormDetails *triggerFormDetails, uint32_t index, efitick_t nowNt)
bool isSpinningUp() const
bool checkIfSpinning(efitick_t nowNt) const
void setRpmValue(float value)
void assignRpmValue(float value)
InstantRpmCalculator instantRpm
PrimaryTriggerDecoder triggerState
TriggerWaveform triggerShape
TriggerFormDetails triggerFormDetails
current_cycle_state_s currentCycle
EngineRotationState * getEngineRotationState()
Definition engine.cpp:573
static EngineAccessor engine
Definition engine.h:413
UNUSED(samplingTimeSeconds)
instantRpm("sync: instant RPM", SensorCategory.SENSOR_INPUTS, FieldType.INT16, 326, 1.0, 0.0, 0.0, "rpm")
angle_t getEngineCycle(operation_mode_e operationMode)

Referenced by TriggerCentral::handleShaftSignal().

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

◆ scheduleByAngle()

efitick_t scheduleByAngle ( scheduling_s timer,
efitick_t  nowNt,
angle_t  angle,
action_s const &  action 
)
Returns
tick time of scheduled action

Schedules a callback 'angle' degree of crankshaft from now. The callback would be executed once after the duration of time which it takes the crankshaft to rotate to the specified angle.

Returns
tick time of scheduled action

Definition at line 381 of file rpm_calculator.cpp.

381 {
382 float delayUs = engine->rpmCalculator.oneDegreeUs * angle;
383
384 efitick_t actionTimeNt = sumTickAndFloat(nowNt, USF2NT(delayUs));
385
386 engine->scheduler.schedule("angle", timer, actionTimeNt, action);
387
388 return actionTimeNt;
389}
SingleTimerExecutor scheduler
Definition engine.h:271
floatus_t oneDegreeUs
void schedule(const char *msg, scheduling_s *scheduling, efitick_t timeNt, action_s const &action) override
Schedule an action to be executed in the future.
efitick_t sumTickAndFloat(efitick_t ticks, float extra)
Definition efitime.h:90

Referenced by fireSparkAndPrepareNextSchedule(), MapAveragingModule::onEnginePhase(), Engine::onSparkFireKnockSense(), InjectionEvent::onTriggerTooth(), HpfpController::pinTurnOn(), TriggerScheduler::scheduleEventsUntilNextTriggerTooth(), TriggerScheduler::scheduleOrQueue(), scheduleSparkEvent(), startAveraging(), tdcMarkCallback(), and turnSparkPinHighStartCharging().

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

◆ tdcMarkCallback()

void tdcMarkCallback ( uint32_t  trgEventIndex,
efitick_t  nowNt 
)

This trigger callback schedules the actual physical TDC callback in relation to trigger synchronization point.

Definition at line 349 of file rpm_calculator.cpp.

350 {
351 bool isTriggerSynchronizationPoint = trgEventIndex == 0;
352 if (isTriggerSynchronizationPoint && getTriggerCentral()->isEngineSnifferEnabled) {
353
354#if EFI_UNIT_TEST
355 if (!engine->tdcMarkEnabled) {
356 return;
357 }
358#endif // EFI_UNIT_TEST
359
360
361 // two instances of scheduling_s are needed to properly handle event overlap
362 int revIndex2 = getRevolutionCounter() % 2;
364 // todo: use tooth event-based scheduling, not just time-based scheduling
365 if (rpm != 0) {
366 angle_t tdcPosition = tdcPosition();
367 // we need a positive angle offset here
368 wrapAngle(tdcPosition, "tdcPosition", ObdCode::CUSTOM_ERR_6553);
369 scheduleByAngle(&engine->tdcScheduler[revIndex2], nowNt, tdcPosition, action_s::make<onTdcCallback>());
370 }
371 }
372}
scheduling_s tdcScheduler[2]
Definition engine.h:290
bool tdcMarkEnabled
Definition engine.h:301
static float getOrZero(SensorType type)
Definition sensor.h:83
TriggerCentral * getTriggerCentral()
Definition engine.cpp:590
@ CUSTOM_ERR_6553
efitick_t scheduleByAngle(scheduling_s *timer, efitick_t nowNt, angle_t angle, action_s const &action)
float angle_t
void wrapAngle(angle_t &angle, const char *msg, ObdCode code)

Referenced by TriggerCentral::handleShaftSignal().

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

Go to the source code of this file.