Missing dwell altogether in some corner cases fix #796

This commit is contained in:
rusefi 2019-11-06 00:31:24 -05:00
parent 5106ada9ce
commit df291f4421
2 changed files with 9 additions and 5 deletions

View File

@ -129,13 +129,15 @@ bool RpmCalculator::checkIfSpinning(efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUF
return true;
}
void RpmCalculator::assignRpmValue(float value DECLARE_ENGINE_PARAMETER_SUFFIX) {
void RpmCalculator::assignRpmValue(float floatRpmValue DECLARE_ENGINE_PARAMETER_SUFFIX) {
previousRpmValue = rpmValue;
rpmValue = value;
// we still persist integer RPM! todo: figure out the next steps
rpmValue = floatRpmValue;
if (rpmValue <= 0) {
oneDegreeUs = NAN;
} else {
oneDegreeUs = getOneDegreeTimeUs(rpmValue);
// here it's really important to have more precise float RPM value, see #796
oneDegreeUs = getOneDegreeTimeUs(floatRpmValue);
if (previousRpmValue == 0) {
/**
* this would make sure that we have good numbers for first cranking revolution
@ -248,7 +250,7 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType,
rpmState->setRpmValue(NOISY_RPM PASS_ENGINE_PARAMETER_SUFFIX);
} else {
int mult = (int)getEngineCycle(engine->getOperationMode(PASS_ENGINE_PARAMETER_SIGNATURE)) / 360;
float rpm = (int) (60 * US2NT(US_PER_SECOND_LL) * mult / diffNt);
float rpm = 60.0 * US2NT(US_PER_SECOND_LL) * mult / diffNt;
rpmState->setRpmValue(rpm > UNREALISTIC_RPM ? NOISY_RPM : rpm PASS_ENGINE_PARAMETER_SUFFIX);
}
}

View File

@ -20,10 +20,12 @@ TEST(scheduler, dwellIssue796) {
ASSERT_EQ( 100, GET_RPM()) << "spinning-RPM#1";
ASSERT_EQ(300000, ENGINE(rpmCalculator.oneDegreeUs) * 180);
// with just a bit much time between events integer RPM goes down one full percent
eth.fireRise(601);
eth.fireFall(600);
ASSERT_NEAR( 99, GET_RPM(), EPS3D) << "spinning-RPM#2";
ASSERT_EQ(303030, (int)(ENGINE(rpmCalculator.oneDegreeUs) * 180));
// while integer RPM value is 1% away from rpm=100, below oneDegreeUs is much closer to RPM=100 value
ASSERT_EQ(300250, (int)(ENGINE(rpmCalculator.oneDegreeUs) * 180));
}