This commit is contained in:
rusefi 2017-12-03 23:58:48 -05:00
parent 4bfbb715de
commit ac7c2290ca
3 changed files with 45 additions and 19 deletions

View File

@ -79,15 +79,22 @@ public:
uint32_t getRevolutionCounter(void);
void setRpmValue(int value DECLARE_ENGINE_PARAMETER_SUFFIX);
uint32_t getRevolutionCounterSinceStart(void);
/**
* RPM rate of change between current RPM and RPM measured during previous engine cycle
* see also SC_RPM_ACCEL
*/
float getRpmAcceleration();
/**
* This is public because sometimes we cannot afford to call isRunning() and the value is good enough
* Zero if engine is not running
*/
volatile int rpmValue;
/**
* this is RPM on previous engine cycle.
*/
int previousRpmValue;
/**
* This is a performance optimization: let's pre-calulate this each time RPM changes
* This is a performance optimization: let's pre-calculate this each time RPM changes
* NaN while engine is not spinning
*/
volatile floatus_t oneDegreeUs;

View File

@ -118,8 +118,15 @@ private:
*/
class TriggerStateWithRunningStatistics : public TriggerState {
public:
/**
* timestamp of each trigger wheel tooth
*/
uint32_t timeOfLastEvent[PWM_PHASE_MAX_COUNT];
/**
* instant RPM calculated at this trigger wheel tooth
*/
float instantRpmValue[PWM_PHASE_MAX_COUNT];
float calculateInstantRpm(int *prevIndex, efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
virtual void runtimeStatistics(trigger_event_e const signal, efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
};

View File

@ -212,32 +212,44 @@ void TriggerState::runtimeStatistics(trigger_event_e const signal, efitime_t now
// empty base implementation
}
float TriggerStateWithRunningStatistics::calculateInstantRpm(int *prevIndex, efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
/**
* Here we calculate RPM based on last 90 degrees
*/
angle_t currentAngle = TRIGGER_SHAPE(eventAngles[currentCycle.current_index]);
// todo: make this '90' depend on cylinder count?
angle_t previousAngle = currentAngle - 90;
fixAngle(previousAngle, "prevAngle");
// todo: prevIndex should be pre-calculated
*prevIndex = TRIGGER_SHAPE(triggerIndexByAngle[(int)previousAngle]);
// now let's get precise angle for that event
angle_t prevIndexAngle = TRIGGER_SHAPE(eventAngles[*prevIndex]);
uint32_t time = nowNt - timeOfLastEvent[*prevIndex];
angle_t angleDiff = currentAngle - prevIndexAngle;
// todo: angle diff should be pre-calculated
fixAngle(angleDiff, "angleDiff");
float instantRpm = (60000000.0 / 360 * US_TO_NT_MULTIPLIER) * angleDiff / time;
instantRpmValue[currentCycle.current_index] = instantRpm;
timeOfLastEvent[currentCycle.current_index] = nowNt;
return instantRpm;
}
void TriggerStateWithRunningStatistics::runtimeStatistics(trigger_event_e const signal, efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
if (ENGINE(sensorChartMode) == SC_RPM_ACCEL || ENGINE(sensorChartMode) == SC_DETAILED_RPM) {
angle_t currentAngle = TRIGGER_SHAPE(eventAngles[currentCycle.current_index]);
// todo: make this '90' depend on cylinder count?
angle_t prevAngle = currentAngle - 90;
fixAngle(prevAngle, "prevAngle");
// todo: prevIndex should be pre-calculated
int prevIndex = TRIGGER_SHAPE(triggerIndexByAngle[(int)prevAngle]);
// now let's get precise angle for that event
prevAngle = TRIGGER_SHAPE(eventAngles[prevIndex]);
uint32_t time = nowNt - timeOfLastEvent[prevIndex];
angle_t angleDiff = currentAngle - prevAngle;
// todo: angle diff should be pre-calculated
fixAngle(angleDiff, "angleDiff");
float r = (60000000.0 / 360 * US_TO_NT_MULTIPLIER) * angleDiff / time;
int prevIndex;
float instantRpm = calculateInstantRpm(&prevIndex, nowNt PASS_ENGINE_PARAMETER_SUFFIX);
#if EFI_SENSOR_CHART || defined(__DOXYGEN__)
angle_t currentAngle = TRIGGER_SHAPE(eventAngles[currentCycle.current_index]);
if (boardConfiguration->sensorChartMode == SC_DETAILED_RPM) {
scAddData(currentAngle, r);
scAddData(currentAngle, instantRpm);
} else {
scAddData(currentAngle, r / instantRpmValue[prevIndex]);
scAddData(currentAngle, instantRpm / instantRpmValue[prevIndex]);
}
#endif /* EFI_SENSOR_CHART */
instantRpmValue[currentCycle.current_index] = r;
timeOfLastEvent[currentCycle.current_index] = nowNt;
}
}