MAP phase sensing #3544

new implementation
This commit is contained in:
Andrey 2021-12-07 20:00:04 -05:00
parent 73fb5a2ef8
commit e72d57438a
4 changed files with 70 additions and 3 deletions

View File

@ -37,6 +37,10 @@ void contextSwitchHook() {}
#endif /* ENABLE_PERF_TRACE */
#if EFI_ENABLE_MOCK_ADC
/**
* in 2021 the api is Sensor::setMockValue
* todo: remove this mockAdcState https://github.com/rusefi/rusefi/issues/3672
*/
void setMockVoltage(int hwChannel, float voltage) {
engine->engineState.mockAdcState.setMockVoltage(hwChannel, voltage);
}

View File

@ -105,6 +105,7 @@ static bool vvtWithRealDecoder(vvt_mode_e vvtMode) {
return vvtMode != VVT_INACTIVE
&& vvtMode != VVT_2JZ
&& vvtMode != VVT_HONDA_K
&& vvtMode != VVT_MAP_V_TWIN_ANOTHER &&
&& vvtMode != VVT_SECOND_HALF
&& vvtMode != VVT_FIRST_HALF;
}
@ -143,6 +144,7 @@ static angle_t adjustCrankPhase(int camIndex) {
switch (engineConfiguration->vvtMode[camIndex]) {
case VVT_FIRST_HALF:
case VVT_MAP_V_TWIN_ANOTHER:
return syncAndReport(tc, getCrankDivider(operationMode), 1);
case VVT_SECOND_HALF:
return syncAndReport(tc, getCrankDivider(operationMode), 0);
@ -662,11 +664,43 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta
mainTriggerCallback(triggerIndexForListeners, timestamp);
#if EFI_TUNER_STUDIO
auto toothAngle = engine->triggerCentral.triggerFormDetails.eventAngles[triggerIndexForListeners] - tdcPosition();
wrapAngle(toothAngle, "currentEnginePhase", CUSTOM_ERR_6555);
#if EFI_TUNER_STUDIO
tsOutputChannels.currentEnginePhase = toothAngle;
#endif
#endif // EFI_TUNER_STUDIO
if (engineConfiguration->vvtMode[0] == VVT_MAP_V_TWIN_ANOTHER) {
if (mapCamPrevToothAngle < engineConfiguration->mapCamDetectionAnglePosition && toothAngle > engineConfiguration->mapCamDetectionAnglePosition) {
// we are somewhere close to 'mapCamDetectionAnglePosition'
float map = Sensor::getOrZero(SensorType::Map);
if (map > mapCamPrevCycleValue) {
mapCamCounter++;
efitick_t stamp = getTimeNowNt();
hwHandleVvtCamSignal(TV_RISE, stamp, /*index*/0);
hwHandleVvtCamSignal(TV_FALL, stamp, /*index*/0);
}
#if EFI_TUNER_STUDIO
tsOutputChannels.TEMPLOG_MAP_INSTANT_AVERAGE = map;
tsOutputChannels.TEMPLOG_map_peak = mapCamCounter;
tsOutputChannels.TEMPLOG_MAP_AT_DIFF = map - mapCamPrevCycleValue;
#endif // EFI_TUNER_STUDIO
mapCamPrevCycleValue = map;
}
mapCamPrevToothAngle = toothAngle;
}
}
}

View File

@ -73,14 +73,20 @@ public:
void resetCounters();
void validateCamVvtCounters();
LocalVersionHolder triggerVersion;
MapState mapState;
angle_t mapCamPrevToothAngle = -1;
float mapCamPrevCycleValue = 0;
uint8_t mapCamCounter = 0;
/**
* true if a recent configuration change has changed any of the trigger settings which
* we have not adjusted for yet
*/
bool triggerConfigChanged = false;
LocalVersionHolder triggerVersion;
bool checkIfTriggerConfigChanged();
bool isTriggerConfigChanged();

View File

@ -69,3 +69,26 @@ TEST(trigger, map_cam) {
ASSERT_TRUE(state.isPeak(false)) << "high At " << i;
ASSERT_TRUE(state.isPeak(false)) << "low At " << i;
}
TEST(trigger, map_cam_by_magic_point) {
EngineTestHelper eth(TEST_ENGINE);
engineConfiguration->camInputs[0] = GPIOA_0;
engineConfiguration->vvtMode[0] = VVT_MAP_V_TWIN_ANOTHER;
Sensor::setMockValue(SensorType::Map, 100);
engineConfiguration->mapCamDetectionAnglePosition = 90;
eth.smartFireTriggerEvents2(/*count*/10, /*delayMs*/200);
ASSERT_EQ( 150, GET_RPM()) << "RPM";
ASSERT_EQ(1, engine->triggerCentral.mapCamCounter);
Sensor::setMockValue(SensorType::Map, 120);
eth.smartFireTriggerEvents2(/*count*/2, /*delayMs*/200);
ASSERT_EQ(2, engine->triggerCentral.mapCamCounter);
}