This commit is contained in:
parent
4bfbb715de
commit
ac7c2290ca
|
@ -79,15 +79,22 @@ public:
|
||||||
uint32_t getRevolutionCounter(void);
|
uint32_t getRevolutionCounter(void);
|
||||||
void setRpmValue(int value DECLARE_ENGINE_PARAMETER_SUFFIX);
|
void setRpmValue(int value DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||||
uint32_t getRevolutionCounterSinceStart(void);
|
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();
|
float getRpmAcceleration();
|
||||||
/**
|
/**
|
||||||
* This is public because sometimes we cannot afford to call isRunning() and the value is good enough
|
* This is public because sometimes we cannot afford to call isRunning() and the value is good enough
|
||||||
* Zero if engine is not running
|
* Zero if engine is not running
|
||||||
*/
|
*/
|
||||||
volatile int rpmValue;
|
volatile int rpmValue;
|
||||||
|
/**
|
||||||
|
* this is RPM on previous engine cycle.
|
||||||
|
*/
|
||||||
int previousRpmValue;
|
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
|
* NaN while engine is not spinning
|
||||||
*/
|
*/
|
||||||
volatile floatus_t oneDegreeUs;
|
volatile floatus_t oneDegreeUs;
|
||||||
|
|
|
@ -118,8 +118,15 @@ private:
|
||||||
*/
|
*/
|
||||||
class TriggerStateWithRunningStatistics : public TriggerState {
|
class TriggerStateWithRunningStatistics : public TriggerState {
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* timestamp of each trigger wheel tooth
|
||||||
|
*/
|
||||||
uint32_t timeOfLastEvent[PWM_PHASE_MAX_COUNT];
|
uint32_t timeOfLastEvent[PWM_PHASE_MAX_COUNT];
|
||||||
|
/**
|
||||||
|
* instant RPM calculated at this trigger wheel tooth
|
||||||
|
*/
|
||||||
float instantRpmValue[PWM_PHASE_MAX_COUNT];
|
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);
|
virtual void runtimeStatistics(trigger_event_e const signal, efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -212,32 +212,44 @@ void TriggerState::runtimeStatistics(trigger_event_e const signal, efitime_t now
|
||||||
// empty base implementation
|
// empty base implementation
|
||||||
}
|
}
|
||||||
|
|
||||||
void TriggerStateWithRunningStatistics::runtimeStatistics(trigger_event_e const signal, efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
float TriggerStateWithRunningStatistics::calculateInstantRpm(int *prevIndex, efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
if (ENGINE(sensorChartMode) == SC_RPM_ACCEL || ENGINE(sensorChartMode) == SC_DETAILED_RPM) {
|
/**
|
||||||
|
* Here we calculate RPM based on last 90 degrees
|
||||||
|
*/
|
||||||
angle_t currentAngle = TRIGGER_SHAPE(eventAngles[currentCycle.current_index]);
|
angle_t currentAngle = TRIGGER_SHAPE(eventAngles[currentCycle.current_index]);
|
||||||
// todo: make this '90' depend on cylinder count?
|
// todo: make this '90' depend on cylinder count?
|
||||||
angle_t prevAngle = currentAngle - 90;
|
angle_t previousAngle = currentAngle - 90;
|
||||||
fixAngle(prevAngle, "prevAngle");
|
fixAngle(previousAngle, "prevAngle");
|
||||||
// todo: prevIndex should be pre-calculated
|
// todo: prevIndex should be pre-calculated
|
||||||
int prevIndex = TRIGGER_SHAPE(triggerIndexByAngle[(int)prevAngle]);
|
*prevIndex = TRIGGER_SHAPE(triggerIndexByAngle[(int)previousAngle]);
|
||||||
|
|
||||||
// now let's get precise angle for that event
|
// now let's get precise angle for that event
|
||||||
prevAngle = TRIGGER_SHAPE(eventAngles[prevIndex]);
|
angle_t prevIndexAngle = TRIGGER_SHAPE(eventAngles[*prevIndex]);
|
||||||
uint32_t time = nowNt - timeOfLastEvent[prevIndex];
|
uint32_t time = nowNt - timeOfLastEvent[*prevIndex];
|
||||||
angle_t angleDiff = currentAngle - prevAngle;
|
angle_t angleDiff = currentAngle - prevIndexAngle;
|
||||||
// todo: angle diff should be pre-calculated
|
// todo: angle diff should be pre-calculated
|
||||||
fixAngle(angleDiff, "angleDiff");
|
fixAngle(angleDiff, "angleDiff");
|
||||||
|
|
||||||
float r = (60000000.0 / 360 * US_TO_NT_MULTIPLIER) * angleDiff / time;
|
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) {
|
||||||
|
int prevIndex;
|
||||||
|
float instantRpm = calculateInstantRpm(&prevIndex, nowNt PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
|
|
||||||
#if EFI_SENSOR_CHART || defined(__DOXYGEN__)
|
#if EFI_SENSOR_CHART || defined(__DOXYGEN__)
|
||||||
|
angle_t currentAngle = TRIGGER_SHAPE(eventAngles[currentCycle.current_index]);
|
||||||
if (boardConfiguration->sensorChartMode == SC_DETAILED_RPM) {
|
if (boardConfiguration->sensorChartMode == SC_DETAILED_RPM) {
|
||||||
scAddData(currentAngle, r);
|
scAddData(currentAngle, instantRpm);
|
||||||
} else {
|
} else {
|
||||||
scAddData(currentAngle, r / instantRpmValue[prevIndex]);
|
scAddData(currentAngle, instantRpm / instantRpmValue[prevIndex]);
|
||||||
}
|
}
|
||||||
#endif /* EFI_SENSOR_CHART */
|
#endif /* EFI_SENSOR_CHART */
|
||||||
instantRpmValue[currentCycle.current_index] = r;
|
|
||||||
timeOfLastEvent[currentCycle.current_index] = nowNt;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue