trigger: in corner cases like NB2 and VQ35 those are not revolutions
This commit is contained in:
parent
00fea2cbe5
commit
8e49542600
|
@ -624,7 +624,7 @@ void TriggerCentral::decodeMapCam(efitick_t timestamp, float currentPhase) {
|
||||||
|
|
||||||
if (diff > 0) {
|
if (diff > 0) {
|
||||||
mapVvt_map_peak++;
|
mapVvt_map_peak++;
|
||||||
int revolutionCounter = engine->triggerCentral.triggerState.getTotalRevolutionCounter();
|
int revolutionCounter = engine->triggerCentral.triggerState.getCrankSynchronizationCounter();
|
||||||
mapVvt_MAP_AT_CYCLE_COUNT = revolutionCounter - prevChangeAtCycle;
|
mapVvt_MAP_AT_CYCLE_COUNT = revolutionCounter - prevChangeAtCycle;
|
||||||
prevChangeAtCycle = revolutionCounter;
|
prevChangeAtCycle = revolutionCounter;
|
||||||
|
|
||||||
|
@ -695,7 +695,7 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta
|
||||||
* cycle into a four stroke, 720 degrees cycle.
|
* cycle into a four stroke, 720 degrees cycle.
|
||||||
*/
|
*/
|
||||||
int crankDivider = getCrankDivider(triggerShape.getWheelOperationMode());
|
int crankDivider = getCrankDivider(triggerShape.getWheelOperationMode());
|
||||||
int crankInternalIndex = triggerState.getTotalRevolutionCounter() % crankDivider;
|
int crankInternalIndex = triggerState.getCrankSynchronizationCounter() % crankDivider;
|
||||||
int triggerIndexForListeners = decodeResult.Value.CurrentIndex + (crankInternalIndex * triggerShape.getSize());
|
int triggerIndexForListeners = decodeResult.Value.CurrentIndex + (crankInternalIndex * triggerShape.getSize());
|
||||||
|
|
||||||
reportEventToWaveChart(signal, triggerIndexForListeners);
|
reportEventToWaveChart(signal, triggerIndexForListeners);
|
||||||
|
@ -752,7 +752,7 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta
|
||||||
|
|
||||||
#if EFI_CDM_INTEGRATION
|
#if EFI_CDM_INTEGRATION
|
||||||
if (trgEventIndex == 0 && isBrainPinValid(engineConfiguration->cdmInputPin)) {
|
if (trgEventIndex == 0 && isBrainPinValid(engineConfiguration->cdmInputPin)) {
|
||||||
int cdmKnockValue = getCurrentCdmValue(engine->triggerCentral.triggerState.getTotalRevolutionCounter());
|
int cdmKnockValue = getCurrentCdmValue(engine->triggerCentral.triggerState.getCrankSynchronizationCounter());
|
||||||
engine->knockLogic(cdmKnockValue);
|
engine->knockLogic(cdmKnockValue);
|
||||||
}
|
}
|
||||||
#endif /* EFI_CDM_INTEGRATION */
|
#endif /* EFI_CDM_INTEGRATION */
|
||||||
|
@ -828,7 +828,7 @@ void triggerInfo(void) {
|
||||||
boolToString(engine->triggerCentral.isTriggerDecoderError()),
|
boolToString(engine->triggerCentral.isTriggerDecoderError()),
|
||||||
engine->triggerCentral.triggerState.totalTriggerErrorCounter,
|
engine->triggerCentral.triggerState.totalTriggerErrorCounter,
|
||||||
engine->triggerCentral.triggerState.orderingErrorCounter,
|
engine->triggerCentral.triggerState.orderingErrorCounter,
|
||||||
engine->triggerCentral.triggerState.getTotalRevolutionCounter(),
|
engine->triggerCentral.triggerState.getCrankSynchronizationCounter(),
|
||||||
boolToString(engine->directSelfStimulation));
|
boolToString(engine->directSelfStimulation));
|
||||||
|
|
||||||
if (TRIGGER_WAVEFORM(isSynchronizationNeeded)) {
|
if (TRIGGER_WAVEFORM(isSynchronizationNeeded)) {
|
||||||
|
|
|
@ -67,7 +67,7 @@ void TriggerDecoderBase::resetTriggerState() {
|
||||||
|
|
||||||
memset(toothDurations, 0, sizeof(toothDurations));
|
memset(toothDurations, 0, sizeof(toothDurations));
|
||||||
|
|
||||||
totalRevolutionCounter = 0;
|
crankSynchronizationCounter = 0;
|
||||||
totalTriggerErrorCounter = 0;
|
totalTriggerErrorCounter = 0;
|
||||||
orderingErrorCounter = 0;
|
orderingErrorCounter = 0;
|
||||||
m_timeSinceDecodeError.init();
|
m_timeSinceDecodeError.init();
|
||||||
|
@ -205,8 +205,8 @@ int64_t TriggerDecoderBase::getTotalEventCounter() const {
|
||||||
return totalEventCountBase + currentCycle.current_index;
|
return totalEventCountBase + currentCycle.current_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TriggerDecoderBase::getTotalRevolutionCounter() const {
|
int TriggerDecoderBase::getCrankSynchronizationCounter() const {
|
||||||
return totalRevolutionCounter;
|
return crankSynchronizationCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrimaryTriggerDecoder::resetTriggerState() {
|
void PrimaryTriggerDecoder::resetTriggerState() {
|
||||||
|
@ -369,8 +369,8 @@ int TriggerDecoderBase::getCurrentIndex() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TriggerCentral::validateCamVvtCounters() {
|
void TriggerCentral::validateCamVvtCounters() {
|
||||||
// micro-optimized 'totalRevolutionCounter % 256'
|
// micro-optimized 'crankSynchronizationCounter % 256'
|
||||||
int camVvtValidationIndex = triggerState.getTotalRevolutionCounter() & 0xFF;
|
int camVvtValidationIndex = triggerState.getCrankSynchronizationCounter() & 0xFF;
|
||||||
if (camVvtValidationIndex == 0) {
|
if (camVvtValidationIndex == 0) {
|
||||||
vvtCamCounter = 0;
|
vvtCamCounter = 0;
|
||||||
} else if (camVvtValidationIndex == 0xFE && vvtCamCounter < 60) {
|
} else if (camVvtValidationIndex == 0xFE && vvtCamCounter < 60) {
|
||||||
|
@ -382,7 +382,7 @@ void TriggerCentral::validateCamVvtCounters() {
|
||||||
angle_t PrimaryTriggerDecoder::syncEnginePhase(int divider, int remainder, angle_t engineCycle) {
|
angle_t PrimaryTriggerDecoder::syncEnginePhase(int divider, int remainder, angle_t engineCycle) {
|
||||||
efiAssert(OBD_PCM_Processor_Fault, remainder < divider, "syncEnginePhase", false);
|
efiAssert(OBD_PCM_Processor_Fault, remainder < divider, "syncEnginePhase", false);
|
||||||
angle_t totalShift = 0;
|
angle_t totalShift = 0;
|
||||||
while (getTotalRevolutionCounter() % divider != remainder) {
|
while (getCrankSynchronizationCounter() % divider != remainder) {
|
||||||
/**
|
/**
|
||||||
* we are here if we've detected the cam sensor within the wrong crank phase
|
* we are here if we've detected the cam sensor within the wrong crank phase
|
||||||
* let's increase the trigger event counter, that would adjust the state of
|
* let's increase the trigger event counter, that would adjust the state of
|
||||||
|
@ -407,7 +407,7 @@ angle_t PrimaryTriggerDecoder::syncEnginePhase(int divider, int remainder, angle
|
||||||
}
|
}
|
||||||
|
|
||||||
void TriggerDecoderBase::incrementShaftSynchronizationCounter() {
|
void TriggerDecoderBase::incrementShaftSynchronizationCounter() {
|
||||||
totalRevolutionCounter++;
|
crankSynchronizationCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrimaryTriggerDecoder::onTriggerError() {
|
void PrimaryTriggerDecoder::onTriggerError() {
|
||||||
|
@ -469,7 +469,7 @@ void TriggerDecoderBase::onShaftSynchronization(
|
||||||
incrementShaftSynchronizationCounter();
|
incrementShaftSynchronizationCounter();
|
||||||
} else {
|
} else {
|
||||||
// We have just synchronized, this is the zeroth revolution
|
// We have just synchronized, this is the zeroth revolution
|
||||||
totalRevolutionCounter = 0;
|
crankSynchronizationCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
totalEventCountBase += triggerShape.getSize();
|
totalEventCountBase += triggerShape.getSize();
|
||||||
|
@ -478,7 +478,7 @@ void TriggerDecoderBase::onShaftSynchronization(
|
||||||
if (printTriggerDebug) {
|
if (printTriggerDebug) {
|
||||||
printf("onShaftSynchronization index=%d %d\r\n",
|
printf("onShaftSynchronization index=%d %d\r\n",
|
||||||
currentCycle.current_index,
|
currentCycle.current_index,
|
||||||
totalRevolutionCounter);
|
crankSynchronizationCounter);
|
||||||
}
|
}
|
||||||
#endif /* EFI_UNIT_TEST */
|
#endif /* EFI_UNIT_TEST */
|
||||||
}
|
}
|
||||||
|
@ -833,7 +833,7 @@ uint32_t TriggerDecoderBase::findTriggerZeroEventIndex(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert that we found the sync point on the very first revolution
|
// Assert that we found the sync point on the very first revolution
|
||||||
efiAssert(CUSTOM_ERR_ASSERT, getTotalRevolutionCounter() == 0, "findZero_revCounter", EFI_ERROR_CODE);
|
efiAssert(CUSTOM_ERR_ASSERT, getCrankSynchronizationCounter() == 0, "findZero_revCounter", EFI_ERROR_CODE);
|
||||||
|
|
||||||
#if EFI_UNIT_TEST
|
#if EFI_UNIT_TEST
|
||||||
if (printTriggerDebug) {
|
if (printTriggerDebug) {
|
||||||
|
|
|
@ -68,7 +68,7 @@ public:
|
||||||
* current trigger processing index, between zero and #size
|
* current trigger processing index, between zero and #size
|
||||||
*/
|
*/
|
||||||
int getCurrentIndex() const;
|
int getCurrentIndex() const;
|
||||||
int getTotalRevolutionCounter() const;
|
int getCrankSynchronizationCounter() const;
|
||||||
/**
|
/**
|
||||||
* this is important for crank-based virtual trigger and VVT magic
|
* this is important for crank-based virtual trigger and VVT magic
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -106,7 +106,7 @@ void TriggerStimulatorHelper::assertSyncPosition(
|
||||||
feedSimulatedEvent(triggerConfiguration, state, shape, i);
|
feedSimulatedEvent(triggerConfiguration, state, shape, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
int revolutionCounter = state.getTotalRevolutionCounter();
|
int revolutionCounter = state.getCrankSynchronizationCounter();
|
||||||
if (revolutionCounter != TEST_REVOLUTIONS) {
|
if (revolutionCounter != TEST_REVOLUTIONS) {
|
||||||
warning(CUSTOM_OBD_TRIGGER_WAVEFORM, "sync failed/wrong gap parameters trigger=%s revolutionCounter=%d",
|
warning(CUSTOM_OBD_TRIGGER_WAVEFORM, "sync failed/wrong gap parameters trigger=%s revolutionCounter=%d",
|
||||||
getTrigger_type_e(triggerConfiguration.TriggerType.type),
|
getTrigger_type_e(triggerConfiguration.TriggerType.type),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
struct_no_prefix trigger_state_s
|
struct_no_prefix trigger_state_s
|
||||||
uint32_t totalRevolutionCounter;Crank revolution counter
|
uint32_t crankSynchronizationCounter;Crank sync counter\nUsually matches crank revolutions
|
||||||
float autoscale vvtSyncGapRatio;;"", 1, 0, -10000, 10000, 3
|
float autoscale vvtSyncGapRatio;;"", 1, 0, -10000, 10000, 3
|
||||||
float autoscale vvtCurrentPosition;;"", 1, 0, -10000, 10000, 3
|
float autoscale vvtCurrentPosition;;"", 1, 0, -10000, 10000, 3
|
||||||
float autoscale triggerSyncGapRatio;@@GAUGE_NAME_TRG_GAP@@;"", 1, 0, -10000, 10000, 3
|
float autoscale triggerSyncGapRatio;@@GAUGE_NAME_TRG_GAP@@;"", 1, 0, -10000, 10000, 3
|
||||||
|
|
|
@ -9,7 +9,7 @@ struct trigger_state_s {
|
||||||
* Crank revolution counter
|
* Crank revolution counter
|
||||||
* offset 0
|
* offset 0
|
||||||
*/
|
*/
|
||||||
uint32_t totalRevolutionCounter = (uint32_t)0;
|
uint32_t crankSynchronizationCounter = (uint32_t)0;
|
||||||
/**
|
/**
|
||||||
* offset 4
|
* offset 4
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -68,7 +68,7 @@ static void extIonCallback(void *arg) {
|
||||||
UNUSED(arg);
|
UNUSED(arg);
|
||||||
instance.totalCdmEvents++;
|
instance.totalCdmEvents++;
|
||||||
|
|
||||||
int currentRevolution = engine->triggerCentral.triggerState.getTotalRevolutionCounter();
|
int currentRevolution = engine->triggerCentral.triggerState.getCrankSynchronizationCounter();
|
||||||
instance.onNewSignal(currentRevolution);
|
instance.onNewSignal(currentRevolution);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -142,7 +142,7 @@ TEST(trigger, testNB2CamInput) {
|
||||||
// need to be out of VVT sync to see VVT sync in action
|
// need to be out of VVT sync to see VVT sync in action
|
||||||
eth.fireRise(25 * 70 / 180);
|
eth.fireRise(25 * 70 / 180);
|
||||||
eth.fireRise(25 * 110 / 180);
|
eth.fireRise(25 * 110 / 180);
|
||||||
ASSERT_EQ(totalRevolutionCountBeforeVvtSync, engine->triggerCentral.triggerState.getTotalRevolutionCounter());
|
ASSERT_EQ(totalRevolutionCountBeforeVvtSync, engine->triggerCentral.triggerState.getCrankSynchronizationCounter());
|
||||||
ASSERT_TRUE((totalRevolutionCountBeforeVvtSync % SYMMETRICAL_CRANK_SENSOR_DIVIDER) != 0);
|
ASSERT_TRUE((totalRevolutionCountBeforeVvtSync % SYMMETRICAL_CRANK_SENSOR_DIVIDER) != 0);
|
||||||
|
|
||||||
eth.moveTimeForwardUs(MS2US(3)); // shifting VVT phase a few angles
|
eth.moveTimeForwardUs(MS2US(3)); // shifting VVT phase a few angles
|
||||||
|
@ -164,7 +164,7 @@ TEST(trigger, testNB2CamInput) {
|
||||||
hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), 0);
|
hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), 0);
|
||||||
|
|
||||||
ASSERT_FLOAT_EQ(0, engine->triggerCentral.getVVTPosition(0, 0));
|
ASSERT_FLOAT_EQ(0, engine->triggerCentral.getVVTPosition(0, 0));
|
||||||
ASSERT_EQ(totalRevolutionCountBeforeVvtSync, engine->triggerCentral.triggerState.getTotalRevolutionCounter());
|
ASSERT_EQ(totalRevolutionCountBeforeVvtSync, engine->triggerCentral.triggerState.getCrankSynchronizationCounter());
|
||||||
|
|
||||||
// Third gap - long
|
// Third gap - long
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ TEST(trigger, testNB2CamInput) {
|
||||||
|
|
||||||
EXPECT_NEAR(290.5f, engine->triggerCentral.getVVTPosition(0, 0), EPS2D);
|
EXPECT_NEAR(290.5f, engine->triggerCentral.getVVTPosition(0, 0), EPS2D);
|
||||||
// actually position based on VVT!
|
// actually position based on VVT!
|
||||||
ASSERT_EQ(totalRevolutionCountBeforeVvtSync + 3, engine->triggerCentral.triggerState.getTotalRevolutionCounter());
|
ASSERT_EQ(totalRevolutionCountBeforeVvtSync + 3, engine->triggerCentral.triggerState.getCrankSynchronizationCounter());
|
||||||
|
|
||||||
EXPECT_EQ(40, waveChart.getSize());
|
EXPECT_EQ(40, waveChart.getSize());
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,7 @@ TEST(TriggerDecoder, FindsSyncPointMultipleRevolutions) {
|
||||||
doTooth(dut, shape, cfg, t);
|
doTooth(dut, shape, cfg, t);
|
||||||
EXPECT_TRUE(dut.getShaftSynchronized());
|
EXPECT_TRUE(dut.getShaftSynchronized());
|
||||||
EXPECT_EQ(0, dut.currentCycle.current_index);
|
EXPECT_EQ(0, dut.currentCycle.current_index);
|
||||||
EXPECT_EQ(0, dut.getTotalRevolutionCounter());
|
EXPECT_EQ(0, dut.getCrankSynchronizationCounter());
|
||||||
|
|
||||||
// Do 100 turns and make sure we stay synchronized
|
// Do 100 turns and make sure we stay synchronized
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
|
@ -135,7 +135,7 @@ TEST(TriggerDecoder, FindsSyncPointMultipleRevolutions) {
|
||||||
EXPECT_FALSE(dut.someSortOfTriggerError());
|
EXPECT_FALSE(dut.someSortOfTriggerError());
|
||||||
|
|
||||||
// We do one revolution per loop iteration
|
// We do one revolution per loop iteration
|
||||||
EXPECT_EQ(i + 1, dut.getTotalRevolutionCounter());
|
EXPECT_EQ(i + 1, dut.getCrankSynchronizationCounter());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue