...
 
Commits (3)
......@@ -48,9 +48,9 @@
#define MAX_RPM_CRANKING 1000.0 /* Max RPM at which the ECU will consider it to be in cranking mode */
#define PRIMARY_SKIP_EDGES 0
#define PRIMARY_INPUT_TOLLERANCE 80.0 /* Difference allowed in percentage */
#define PRIMARY_INPUT_TOLLERANCE 85.0 /* Difference allowed in percentage */
#define PRIMARY_INPUT_TOLLERANCE_CRANKING 20.0 /* Difference allowed in percentage */
#define SYNC_SEARCH_TOLLERANCE 70.0 /* A logic analyzer is needed to find this */
#define SYNC_SEARCH_TOLLERANCE 90.0 /* A logic analyzer is needed to find this */
#define FILTER_ENABLE_RPM MAX_RPM_CRANKING /* RPM to start filtering tach signal */
#define MIN_SYNC_REQUIRED CRANK_AND_CAM
......@@ -84,10 +84,10 @@
#define VSS_DIVISOR 30
/* WARNING capture edges may be over written by decoder */
#define ECT0_CAPTURE_RISING FALSE
#define ECT0_CAPTURE_FALLING TRUE
#define ECT1_CAPTURE_RISING FALSE
#define ECT1_CAPTURE_FALLING TRUE
#define ECT0_CAPTURE_RISING TRUE
#define ECT0_CAPTURE_FALLING FALSE
#define ECT1_CAPTURE_RISING TRUE
#define ECT1_CAPTURE_FALLING FALSE
#define ECT2_CAPTURE_RISING TRUE
#define ECT2_CAPTURE_FALLING TRUE
#define ECT3_CAPTURE_RISING TRUE
......@@ -135,28 +135,28 @@
*
*/
#define CYL_1_TDC_ANGLE 105 /* TDC angle */
#define CYL_1_TDC_ANGLE 465 /* TDC angle */
#define CYL_1_INJ_ANGLE 135 /* Angle to inject Fuel */
#define CYL_1_READ_ANGLE 135 /* Angle to sample sensors */
#define CYL_1_IGN_CH 0 /* XGate ignition channel */
#define CYL_1_PRIMARY_INJ_CH 4 /* XGate primary fuel channel */
#define CYL_1_SECONDARY_INJ_CH 8 /* XGate secondary fuel channel */
#define CYL_2_TDC_ANGLE 285 /* TDC angle */
#define CYL_2_TDC_ANGLE 645 /* TDC angle */
#define CYL_2_INJ_ANGLE 135 /* Angle to inject Fuel */
#define CYL_2_READ_ANGLE 135 /* Angle to sample sensors */
#define CYL_2_IGN_CH 1 /* XGate ignition channel */
#define CYL_2_PRIMARY_INJ_CH 5 /* XGate primary fuel channel */
#define CYL_2_SECONDARY_INJ_CH 9 /* XGate secondary fuel channel */
#define CYL_3_TDC_ANGLE 645 /* TDC angle */
#define CYL_3_TDC_ANGLE 285 /* TDC angle */
#define CYL_3_INJ_ANGLE 135 /* Angle to inject Fuel */
#define CYL_3_READ_ANGLE 135 /* Angle to sample sensors */
#define CYL_3_IGN_CH 2 /* XGate ignition channel */
#define CYL_3_PRIMARY_INJ_CH 6 /* XGate primary fuel channel */
#define CYL_3_SECONDARY_INJ_CH 10 /* XGate secondary fuel channel */
#define CYL_4_TDC_ANGLE 465 /* TDC angle */
#define CYL_4_TDC_ANGLE 105 /* TDC angle */
#define CYL_4_INJ_ANGLE 135 /* Angle to inject Fuel */
#define CYL_4_READ_ANGLE 135 /* Angle to sample sensors */
#define CYL_4_IGN_CH 3 /* XGate ignition channel */
......
......@@ -47,8 +47,8 @@ static inline void camSyncLogic(DecoderStats *decoderStats) {
if ((decoderStats->currentPrimaryEvent == TOTAL_ENGINE_CYCLE_INDEXES) ||
(decoderStats->currentPrimaryEvent == TOTAL_CRANK_INDEXES)) {
/* Correct phase if we are out */
if (decoderStats->currentPrimaryEvent != TOTAL_CRANK_INDEXES) {
decoderStats->currentPrimaryEvent = TOTAL_CRANK_INDEXES;
if (decoderStats->currentPrimaryEvent != TOTAL_ENGINE_CYCLE_INDEXES) {
decoderStats->currentPrimaryEvent = TOTAL_ENGINE_CYCLE_INDEXES;
}
decoderStats->decoderFlags.bits.phaseLock = 1;
decoderStats->decoderFlags.bits.minimalSync = 1;
......
......@@ -182,49 +182,51 @@ void PrimaryEngineAngle() {
ratioBetweenCurrentAndLast = ratio16(previousPrimaryTicksPerDegree, ticksPerDegree, DECODER_STAMP_RATIO_F);
decoderStats_g.primaryInputVariance = ratioBetweenCurrentAndLast; /* Record raw when not synced */
/* Lookup sync tolerance, when not in sync */
uint16_t allowedTollerance = Config.tachDecoderSettings.syncSearchTollerance;
/* Lookup sync tolerance, when not in sync. If you specify a sync
* tolerance of 90%, then you are telling the decoder that your
* sync window needs to be between 45-55% .
*/
uint16_t syncWindowLowerBoundary = Config.tachDecoderSettings.syncSearchTollerance / (1 + MISSING_CRANK_TEETH);
uint16_t syncWindowUpperBoundary = TACH_INPUT_RATIO(100.00) / (1 + MISSING_CRANK_TEETH);
syncWindowUpperBoundary += syncWindowUpperBoundary - syncWindowLowerBoundary;
//TODO add additional checks for correct TPD direction
/* Greater than for missing tooth, less than for added tooth */
if (ratioBetweenCurrentAndLast < allowedTollerance) {
if (ratioBetweenCurrentAndLast >= syncWindowLowerBoundary &&
ratioBetweenCurrentAndLast <= syncWindowUpperBoundary) {
/* see if we have seen a min number of skip teeth */
if (consecutiveEvenTeethFound > 3) {
/* Correct ticks per degree */
uint16_t ticksPerDegreeAdjusted = ticksPerDegree
/ (MISSING_CRANK_TEETH + 1);
/* Recalc TPD */
ratioBetweenCurrentAndLast = ratio16(previousPrimaryTicksPerDegree,
ticksPerDegreeAdjusted, DECODER_STAMP_RATIO_F);
/* Here we apply an allowed tolerance scaler.
* If we go over a missing tooth and our tolerance is say 10%,
* then we should allow 20% for the next physical tooth(10+10),
* since we moved twice as many crank degrees.
*/
uint16_t adjustedTollerance = TACH_INPUT_RATIO(100.0);
adjustedTollerance -= (adjustedTollerance - allowedTollerance) * (1 + MISSING_CRANK_TEETH);
if (ratioBetweenCurrentAndLast < adjustedTollerance) {
if (ticksPerDegreeAdjusted < previousPrimaryTicksPerDegree) {
resetDecoderStatus(PRIMARY_EVENT_TOO_SOON_UNSYNC);
} else {
resetDecoderStatus(PRIMARY_EVENT_TOO_LATE_UNSYNC);
}
return;
} else {
ticksPerDegree = ticksPerDegreeAdjusted;
decoderStats_g.decoderFlags.bits.crankLock = 1;
if (Config.tachDecoderSettings.minimalSyncRequired == CRANK_ONLY) {
decoderStats_g.decoderFlags.bits.minimalSync = 1;
}
decoderStats_g.currentPrimaryEvent = 0;
ticksPerDegree /= (MISSING_CRANK_TEETH + 1);
decoderStats_g.decoderFlags.bits.crankLock = 1;
if (Config.tachDecoderSettings.minimalSyncRequired == CRANK_ONLY) {
decoderStats_g.decoderFlags.bits.minimalSync = 1;
}
decoderStats_g.currentPrimaryEvent = 0;
} else {
consecutiveEvenTeethFound = 0;
}
} else {
++consecutiveEvenTeethFound;
/* TODO (skeys) we may want some constraint here to qualify
* a valid "even tooth".
*/
if (ratioBetweenCurrentAndLast >= Config.tachDecoderSettings.inputEventCrankingTollerance) {
++consecutiveEvenTeethFound;
} else {
consecutiveEvenTeethFound = 0;
if (previousPrimaryTicksPerDegree < ticksPerDegree) {
decoderStats_g.lockLossCauseID = PRIMARY_EVENT_TOO_SOON_UNSYNC;
} else {
decoderStats_g.lockLossCauseID = PRIMARY_EVENT_TOO_LATE_UNSYNC;
}
}
/* TODO (skeys) we may want to clear the tooth count if we
* get a window that's below the cranking threshold.
*/
}
decoderStats_g.instantTicksPerDegree = ticksPerDegree; /* Record for cranking RPM log */
}
......