improved noFiringUntilVvtSync logic (#3696)
* s * poke * poke again for science * kick for science * kick * kick * comment kick * s * don't try to compare the array decay pointer to 0 (!) * collateral damage * adjust miata sync * reset trigger states correctly on engine stop * s * nissan MR too
This commit is contained in:
parent
20b4ecc585
commit
95ad75318d
|
@ -434,6 +434,14 @@ void Engine::OnTriggerStateProperState(efitick_t nowNt) {
|
||||||
void Engine::OnTriggerSynchronizationLost() {
|
void Engine::OnTriggerSynchronizationLost() {
|
||||||
// Needed for early instant-RPM detection
|
// Needed for early instant-RPM detection
|
||||||
rpmCalculator.setStopSpinning();
|
rpmCalculator.setStopSpinning();
|
||||||
|
|
||||||
|
triggerCentral.triggerState.resetTriggerState();
|
||||||
|
|
||||||
|
for (size_t i = 0; i < efi::size(triggerCentral.vvtState); i++) {
|
||||||
|
for (size_t j = 0; j < efi::size(triggerCentral.vvtState[0]); j++) {
|
||||||
|
triggerCentral.vvtState[i][j].resetTriggerState();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::OnTriggerInvalidIndex(int currentIndex) {
|
void Engine::OnTriggerInvalidIndex(int currentIndex) {
|
||||||
|
|
|
@ -330,8 +330,18 @@ static void handleFuel(const bool limitedFuel, uint32_t trgEventIndex, int rpm,
|
||||||
uint32_t *cyccnt = (uint32_t*) &DWT->CYCCNT;
|
uint32_t *cyccnt = (uint32_t*) &DWT->CYCCNT;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool noFiringUntilVvtSync(vvt_mode_e mode) {
|
static bool noFiringUntilVvtSync(vvt_mode_e vvtMode) {
|
||||||
return mode == VVT_MIATA_NB2 || mode == VVT_MAP_V_TWIN_ANOTHER;
|
auto operationMode = engine->getOperationMode();
|
||||||
|
|
||||||
|
// V-Twin MAP phase sense needs to always wait for sync
|
||||||
|
if (vvtMode == VVT_MAP_V_TWIN_ANOTHER) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Symmetrical crank modes require cam sync before firing
|
||||||
|
// non-symmetrical cranks can use faster spin-up mode (firing in wasted/batch before VVT sync)
|
||||||
|
// Examples include Nissan MR/VQ, Miata NB, etc
|
||||||
|
return operationMode == FOUR_STROKE_SYMMETRICAL_CRANK_SENSOR || operationMode == FOUR_STROKE_THREE_TIMES_CRANK_SENSOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -341,11 +351,11 @@ static bool noFiringUntilVvtSync(vvt_mode_e mode) {
|
||||||
void mainTriggerCallback(uint32_t trgEventIndex, efitick_t edgeTimestamp) {
|
void mainTriggerCallback(uint32_t trgEventIndex, efitick_t edgeTimestamp) {
|
||||||
ScopePerf perf(PE::MainTriggerCallback);
|
ScopePerf perf(PE::MainTriggerCallback);
|
||||||
|
|
||||||
if (noFiringUntilVvtSync(engineConfiguration->vvtMode[0]) && engine->triggerCentral.vvtSyncTimeNt == 0) {
|
if (noFiringUntilVvtSync(engineConfiguration->vvtMode[0]) && engine->triggerCentral.vvtSyncTimeNt[0][0] == 0) {
|
||||||
// this is a bit spaghetti code for sure
|
// Any engine that requires cam-assistance for a full crank sync (symmetrical crank) can't schedule until we have cam sync
|
||||||
// do not spark & do not fuel until we have VVT sync.
|
// examples:
|
||||||
// NB2 is a special case due to symmetrical crank wheel and we need to make sure no spark happens out of sync
|
// NB2, Nissan VQ/MR: symmetrical crank wheel and we need to make sure no spark happens out of sync
|
||||||
// VTwin is another special case where we really need to know phase before firing
|
// VTwin Harley: uneven firing order, so we need "cam" MAP sync to make sure no spark happens out of sync
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ void initializeMazdaMiataNb2Crank(TriggerWaveform *s) {
|
||||||
// Nominal gap 70/110 = 0.636
|
// Nominal gap 70/110 = 0.636
|
||||||
s->setTriggerSynchronizationGap2(0.35f, 0.98f);
|
s->setTriggerSynchronizationGap2(0.35f, 0.98f);
|
||||||
// Nominal gap 110/70 = 1.571
|
// Nominal gap 110/70 = 1.571
|
||||||
s->setSecondTriggerSynchronizationGap2(1.05f, 1.8f);
|
s->setSecondTriggerSynchronizationGap2(1.02f, 1.8f);
|
||||||
|
|
||||||
// todo: NB2 fronts are inverted comparing to NB1, life is not perfect :(
|
// todo: NB2 fronts are inverted comparing to NB1, life is not perfect :(
|
||||||
s->addEventAngle(180.0f - NB_CRANK_MAGIC - 4, T_PRIMARY, TV_FALL);
|
s->addEventAngle(180.0f - NB_CRANK_MAGIC - 4, T_PRIMARY, TV_FALL);
|
||||||
|
|
|
@ -317,7 +317,8 @@ void hwHandleVvtCamSignal(trigger_value_e front, efitick_t nowNt, int index) {
|
||||||
case VVT_BOSCH_QUICK_START:
|
case VVT_BOSCH_QUICK_START:
|
||||||
case VVT_BARRA_3_PLUS_1:
|
case VVT_BARRA_3_PLUS_1:
|
||||||
case VVT_NISSAN_VQ:
|
case VVT_NISSAN_VQ:
|
||||||
{
|
case VVT_NISSAN_MR:
|
||||||
|
{
|
||||||
if (tc->vvtState[bankIndex][camIndex].currentCycle.current_index != 0) {
|
if (tc->vvtState[bankIndex][camIndex].currentCycle.current_index != 0) {
|
||||||
// this is not sync tooth - exiting
|
// this is not sync tooth - exiting
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -71,7 +71,6 @@ void TriggerState::resetTriggerState() {
|
||||||
lastDecodingErrorTime = US2NT(-10000000LL);
|
lastDecodingErrorTime = US2NT(-10000000LL);
|
||||||
someSortOfTriggerError = false;
|
someSortOfTriggerError = false;
|
||||||
|
|
||||||
memset(toothDurations, 0, sizeof(toothDurations));
|
|
||||||
curSignal = SHAFT_PRIMARY_FALLING;
|
curSignal = SHAFT_PRIMARY_FALLING;
|
||||||
prevSignal = SHAFT_PRIMARY_FALLING;
|
prevSignal = SHAFT_PRIMARY_FALLING;
|
||||||
startOfCycleNt = 0;
|
startOfCycleNt = 0;
|
||||||
|
@ -218,6 +217,16 @@ int TriggerState::getTotalRevolutionCounter() const {
|
||||||
return totalRevolutionCounter;
|
return totalRevolutionCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TriggerStateWithRunningStatistics::resetTriggerState() {
|
||||||
|
TriggerState::resetTriggerState();
|
||||||
|
|
||||||
|
memset(timeOfLastEvent, 0, sizeof(timeOfLastEvent));
|
||||||
|
memset(spinningEvents, 0, sizeof(spinningEvents));
|
||||||
|
spinningEventIndex = 0;
|
||||||
|
prevInstantRpmValue = 0;
|
||||||
|
m_instantRpm = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void TriggerStateWithRunningStatistics::movePreSynchTimestamps() {
|
void TriggerStateWithRunningStatistics::movePreSynchTimestamps() {
|
||||||
// here we take timestamps of events which happened prior to synchronization and place them
|
// here we take timestamps of events which happened prior to synchronization and place them
|
||||||
// at appropriate locations
|
// at appropriate locations
|
||||||
|
|
|
@ -139,7 +139,7 @@ public:
|
||||||
uint32_t totalTriggerErrorCounter;
|
uint32_t totalTriggerErrorCounter;
|
||||||
uint32_t orderingErrorCounter;
|
uint32_t orderingErrorCounter;
|
||||||
|
|
||||||
void resetTriggerState();
|
virtual void resetTriggerState();
|
||||||
void setShaftSynchronized(bool value);
|
void setShaftSynchronized(bool value);
|
||||||
bool getShaftSynchronized();
|
bool getShaftSynchronized();
|
||||||
|
|
||||||
|
@ -175,6 +175,7 @@ private:
|
||||||
class TriggerStateWithRunningStatistics : public TriggerState {
|
class TriggerStateWithRunningStatistics : public TriggerState {
|
||||||
public:
|
public:
|
||||||
TriggerStateWithRunningStatistics();
|
TriggerStateWithRunningStatistics();
|
||||||
|
void resetTriggerState() override;
|
||||||
|
|
||||||
float getInstantRpm() const {
|
float getInstantRpm() const {
|
||||||
return m_instantRpm;
|
return m_instantRpm;
|
||||||
|
|
Loading…
Reference in New Issue