Full generic implementatino of the composite logger

This commit is contained in:
Josh Stewart 2018-10-15 14:40:14 +11:00
parent 9946350a69
commit 2b866dd8ad
5 changed files with 278 additions and 122 deletions

View File

@ -10,6 +10,7 @@ A full copy of the license may be found in the projects root directory
#include "storage.h"
#include "maths.h"
#include "utils.h"
#include "decoders.h"
/*
Processes the data on the serial buffer.
@ -91,10 +92,24 @@ void command()
toothHistoryIndex = 0;
toothHistorySerialIndex = 0;
compositeLastToothTime = 0;
//Disconnect the standard interrupt and add the logger verion
detachInterrupt( digitalPinToInterrupt(pinTrigger) );
attachInterrupt( digitalPinToInterrupt(pinTrigger), loggerPrimaryISR, CHANGE );
detachInterrupt( digitalPinToInterrupt(pinTrigger2) );
attachInterrupt( digitalPinToInterrupt(pinTrigger2), loggerSecondaryISR, CHANGE );
break;
case 'j': //Stop the composite logger
currentStatus.compositeLogEnabled = false;
//Disconnect the logger interrupts and attach the normal ones
detachInterrupt( digitalPinToInterrupt(pinTrigger) );
attachInterrupt( digitalPinToInterrupt(pinTrigger), triggerHandler, primaryTriggerEdge );
detachInterrupt( digitalPinToInterrupt(pinTrigger2) );
attachInterrupt( digitalPinToInterrupt(pinTrigger2), triggerSecondaryHandler, secondaryTriggerEdge );
break;
case 'L': // List the contents of current page in human readable form

View File

@ -10,13 +10,15 @@
#endif
static inline void addToothLogEntry(unsigned long, bool);
void loggerPrimaryISR();
void loggerSecondaryISR();
static inline uint16_t stdGetRPM(uint16_t);
static inline void setFilter(unsigned long);
static inline int crankingGetRPM(byte);
//static inline void doPerToothTiming(uint16_t);
void (*trigger)(); //Pointer for the trigger function (Gets pointed to the relevant decoder)
void (*triggerSecondary)(); //Pointer for the secondary trigger function (Gets pointed to the relevant decoder)
void (*triggerHandler)(); //Pointer for the trigger function (Gets pointed to the relevant decoder)
void (*triggerSecondaryHandler)(); //Pointer for the secondary trigger function (Gets pointed to the relevant decoder)
uint16_t (*getRPM)(); //Pointer to the getRPM function (Gets pointed to the relevant decoder)
int (*getCrankAngle)(); //Pointer to the getCrank Angle function (Gets pointed to the relevant decoder)
void (*triggerSetEndTeeth)(); //Pointer to the triggerSetEndTeeth function of each decoder
@ -172,12 +174,14 @@ volatile unsigned long secondaryLastToothTime1 = 0; //The time (micros()) that t
volatile int triggerActualTeeth;
volatile unsigned long triggerFilterTime; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering)
volatile unsigned long triggerSecFilterTime; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering) for the secondary input
volatile bool validTrigger; //Is set true when the last trigger (Primary or secondary) was valid (ie passed filters)
unsigned int triggerSecFilterTime_duration; // The shortest valid time (in uS) pulse DURATION
volatile uint16_t triggerToothAngle; //The number of crank degrees that elapse per tooth
volatile bool triggerToothAngleIsCorrect = false; //Whether or not the triggerToothAngle variable is currently accurate. Some patterns have times when the triggerToothAngle variable cannot be accurately set.
bool secondDerivEnabled = false; //The use of the 2nd derivative calculation is limited to certain decoders. This is set to either true or false in each decoders setup routine
bool decoderIsSequential; //Whether or not the decoder supports sequential operation
bool decoderIsLowRes = false; //Is set true, certain extra calculations are performed for better timing accuracy
bool decoderHasSecondary = false; //Whether or not the pattern uses a secondary input
bool decoderHasFixedCrankingTiming = false; //Whether or not the decoder supports fixed cranking timing
byte checkSyncToothCount; //How many teeth must've been seen on this revolution before we try to confirm sync (Useful for missing tooth type decoders)
unsigned long elapsedTime;

View File

@ -56,6 +56,7 @@ static inline void addToothLogEntry(unsigned long toothTime, bool whichTooth)
toothHistory[toothHistoryIndex] = micros() - compositeLastToothTime;
compositeLastToothTime = micros();
valueLogged = true;
}
//If there has been a value logged above, update the indexes
@ -79,6 +80,62 @@ static inline void addToothLogEntry(unsigned long toothTime, bool whichTooth)
} //Tooth/Composite log enabled
}
/*
* This function is called on both the rising and falling edges of the primary trigger, when either the
* composite or tooth loggers are turned on.
*/
void loggerPrimaryISR()
{
validTrigger = false; //This value will be set to the return value of the decoder function, indicating whether or not this pulse passed the filters
bool validEdge = false; //This is set true below if the edge
/* Two checks here:
1) If the primary trigger is RISING, then check whether the primary is currently HIGH
2) If the primary trigger is FALLING, then check whether the primary is currently LOW
If either of these are true, the primary decoder funtino is called
*/
if( ( (primaryTriggerEdge == RISING) && (READ_PRI_TRIGGER() == HIGH) ) || ( (primaryTriggerEdge == FALLING) && (READ_PRI_TRIGGER() == LOW) ) || (primaryTriggerEdge == CHANGE) )
{
triggerHandler();
validEdge = true;
}
if( (currentStatus.toothLogEnabled == true) && (validTrigger == true) )
{
//Tooth logger only logs when the edge was correct
if(validEdge == true) { addToothLogEntry(curGap, TOOTH_CRANK); }
}
//else if( (currentStatus.compositeLogEnabled == true) && (validTrigger == true) )
else if( (currentStatus.compositeLogEnabled == true) )
{
//Composite logger adds an entry regardless of which edge it was
addToothLogEntry(curGap, TOOTH_CRANK);
}
}
/*
* As above, but for the secondary
*/
void loggerSecondaryISR()
{
validTrigger = false; //This value will be set to the return value of the decoder function, indicating whether or not this pulse passed the filters
validTrigger = true;
/* 3 checks here:
1) If the primary trigger is RISING, then check whether the primary is currently HIGH
2) If the primary trigger is FALLING, then check whether the primary is currently LOW
3) The secondary trigger is CHANGING
If either of these are true, the primary decoder funtino is called
*/
if( ( (secondaryTriggerEdge == RISING) && (READ_SEC_TRIGGER() == HIGH) ) || ( (secondaryTriggerEdge == FALLING) && (READ_SEC_TRIGGER() == LOW) ) || (secondaryTriggerEdge == CHANGE) )
{
triggerSecondaryHandler();
}
//No tooth logger for the secondary input
if( (currentStatus.compositeLogEnabled == true) && (validTrigger == true) )
{
//Composite logger adds an entry regardless of which edge it was
addToothLogEntry(curGap2, TOOTH_CAM);
}
}
/*
As nearly all the decoders use a common method of determining RPM (The time the last full revolution took)
A common function is simpler
@ -214,8 +271,7 @@ void triggerPri_missingTooth()
if ( curGap >= triggerFilterTime ) //Pulses should never be less than triggerFilterTime, so if they are it means a false trigger. (A 36-1 wheel at 8000pm will have triggers approx. every 200uS)
{
toothCurrentCount++; //Increment the tooth counter
addToothLogEntry(curGap, TOOTH_CRANK);
validTrigger = true; //Flag this pulse as being a valid trigger (ie that it passed filters)
//if(toothCurrentCount > checkSyncToothCount || currentStatus.hasSync == false)
{
@ -425,7 +481,7 @@ void triggerPri_DualWheel()
if ( curGap >= triggerFilterTime )
{
toothCurrentCount++; //Increment the tooth counter
addToothLogEntry(curGap, TOOTH_CRANK);
validTrigger = true; //Flag this pulse as being a valid trigger (ie that it passed filters)
toothLastMinusOneToothTime = toothLastToothTime;
toothLastToothTime = curTime;
@ -613,7 +669,7 @@ void triggerPri_BasicDistributor()
}
setFilter(curGap); //Recalc the new filter value
addToothLogEntry(curGap, TOOTH_CRANK);
validTrigger = true; //Flag this pulse as being a valid trigger (ie that it passed filters)
if ( configPage4.ignCranklock && BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK) )
{
@ -726,8 +782,7 @@ void triggerPri_GM7X()
curTime = micros();
curGap = curTime - toothLastToothTime;
toothCurrentCount++; //Increment the tooth counter
addToothLogEntry(curGap, TOOTH_CRANK);
validTrigger = true; //Flag this pulse as being a valid trigger (ie that it passed filters)
//
if( toothCurrentCount > 7 )
@ -890,7 +945,7 @@ void triggerPri_4G63()
curGap = curTime - toothLastToothTime;
if ( (curGap >= triggerFilterTime) || (currentStatus.startRevolutions == 0) )
{
addToothLogEntry(curGap, TOOTH_CRANK);
validTrigger = true; //Flag that this pulse was accepted as a valid trigger
triggerFilterTime = curGap >> 2; //This only applies during non-sync conditions. If there is sync then triggerFilterTime gets changed again below with a better value.
toothLastMinusOneToothTime = toothLastToothTime;
@ -1089,7 +1144,8 @@ void triggerSec_4G63()
if ( (curGap2 >= triggerSecFilterTime) )//|| (currentStatus.startRevolutions == 0) )
{
toothLastSecToothTime = curTime2;
addToothLogEntry(curGap, TOOTH_CAM);
validTrigger = true; //Flag that this pulse was accepted as a valid trigger
//addToothLogEntry(curGap, TOOTH_CAM);
triggerSecFilterTime = curGap2 >> 1; //Basic 50% filter for the secondary reading
//More aggressive options:
@ -1323,7 +1379,7 @@ void triggerPri_24X()
triggerToothAngle = toothAngles[(toothCurrentCount-1)] - toothAngles[(toothCurrentCount-2)]; //Calculate the last tooth gap in degrees
}
addToothLogEntry(curGap, TOOTH_CRANK);
validTrigger = true; //Flag this pulse as being a valid trigger (ie that it passed filters)
toothLastToothTime = curTime;
@ -1435,7 +1491,7 @@ void triggerPri_Jeep2000()
setFilter(curGap); //Recalc the new filter value
addToothLogEntry(curGap, TOOTH_CRANK);
validTrigger = true; //Flag this pulse as being a valid trigger (ie that it passed filters)
toothLastMinusOneToothTime = toothLastToothTime;
toothLastToothTime = curTime;
@ -1518,7 +1574,7 @@ void triggerPri_Audi135()
{
//We only proceed for every third tooth
addToothLogEntry(curGap, TOOTH_CRANK);
validTrigger = true; //Flag this pulse as being a valid trigger (ie that it passed filters)
toothSystemLastToothTime = curTime;
toothSystemCount = 0;
toothCurrentCount++; //Increment the tooth counter
@ -1624,7 +1680,7 @@ void triggerPri_HondaD17()
curGap = curTime - toothLastToothTime;
toothCurrentCount++; //Increment the tooth counter
addToothLogEntry(curGap, TOOTH_CRANK);
validTrigger = true; //Flag this pulse as being a valid trigger (ie that it passed filters)
//
if( (toothCurrentCount == 13) && (currentStatus.hasSync == true) )
@ -1753,6 +1809,7 @@ void triggerPri_Miata9905()
if ( (curGap >= triggerFilterTime) || (currentStatus.startRevolutions == 0) )
{
toothCurrentCount++;
validTrigger = true; //Flag this pulse as being a valid trigger (ie that it passed filters)
if( (toothCurrentCount == (triggerActualTeeth + 1)) )
{
toothCurrentCount = 1; //Reset the counter
@ -1775,7 +1832,6 @@ void triggerPri_Miata9905()
if (currentStatus.hasSync == true)
{
addToothLogEntry(curGap, TOOTH_CRANK);
//Whilst this is an uneven tooth pattern, if the specific angle between the last 2 teeth is specified, 1st deriv prediction can be used
if( (configPage4.triggerFilter == 1) || (currentStatus.RPM < 1400) )
@ -1939,7 +1995,7 @@ void triggerPri_MazdaAU()
curGap = curTime - toothLastToothTime;
if ( curGap >= triggerFilterTime )
{
addToothLogEntry(curGap, TOOTH_CRANK);
validTrigger = true; //Flag this pulse as being a valid trigger (ie that it passed filters)
toothCurrentCount++;
if( (toothCurrentCount == 1) || (toothCurrentCount == 5) ) //Trigger is on CHANGE, hence 4 pulses = 1 crank rev
@ -2156,7 +2212,7 @@ void triggerPri_Nissan360()
curGap = curTime - toothLastToothTime;
//if ( curGap < triggerFilterTime ) { return; }
toothCurrentCount++; //Increment the tooth counter
//addToothLogEntry(curGap); Disable tooth logging on this decoder due to overhead
validTrigger = true; //Flag this pulse as being a valid trigger (ie that it passed filters)
toothLastMinusOneToothTime = toothLastToothTime;
toothLastToothTime = curTime;
@ -2397,7 +2453,7 @@ void triggerPri_Subaru67()
//curGap = curTime - toothLastToothTime;
//if ( curGap < triggerFilterTime ) { return; }
toothCurrentCount++; //Increment the tooth counter
addToothLogEntry(curGap, TOOTH_CRANK);
validTrigger = true; //Flag this pulse as being a valid trigger (ie that it passed filters)
toothLastMinusOneToothTime = toothLastToothTime;
toothLastToothTime = curTime;
@ -2561,6 +2617,7 @@ void triggerPri_Daihatsu()
//if ( curGap >= triggerFilterTime || (currentStatus.startRevolutions == 0 )
{
toothSystemCount++;
validTrigger = true; //Flag this pulse as being a valid trigger (ie that it passed filters)
if (currentStatus.hasSync == true)
{
@ -2581,8 +2638,6 @@ void triggerPri_Daihatsu()
setFilter(curGap); //Recalc the new filter value
}
//addToothLogEntry(curGap, TOOTH_CRANK);
if ( configPage4.ignCranklock && BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK) )
{
//This locks the cranking timing to 0 degrees BTDC (All the triggers allow for)
@ -2710,7 +2765,7 @@ void triggerPri_Harley()
{
if ( READ_PRI_TRIGGER() == HIGH) // Has to be the same as in main() trigger-attach, for readability we do it this way.
{
addToothLogEntry(curGap, TOOTH_CRANK);
validTrigger = true; //Flag this pulse as being a valid trigger (ie that it passed filters)
targetGap = lastGap ; //Gap is the Time to next toothtrigger, so we know where we are
toothCurrentCount++;
if (curGap > targetGap)
@ -2850,8 +2905,7 @@ void triggerPri_ThirtySixMinus222()
if ( curGap >= triggerFilterTime ) //Pulses should never be less than triggerFilterTime, so if they are it means a false trigger. (A 36-1 wheel at 8000pm will have triggers approx. every 200uS)
{
toothCurrentCount++; //Increment the tooth counter
addToothLogEntry(curGap, TOOTH_CRANK);
validTrigger = true; //Flag this pulse as being a valid trigger (ie that it passed filters)
//Begin the missing tooth detection
//If the time between the current tooth and the last is greater than 2x the time between the last tooth and the tooth before that, we make the assertion that we must be at the first tooth after a gap

View File

@ -311,6 +311,8 @@ volatile uint8_t compositeLogHistory[TOOTH_LOG_BUFFER];
volatile bool fpPrimed = false; //Tracks whether or not the fuel pump priming has been completed yet
volatile unsigned int toothHistoryIndex = 0;
volatile byte toothHistorySerialIndex = 0;
byte primaryTriggerEdge;
byte secondaryTriggerEdge;
int CRANK_ANGLE_MAX = 720;
int CRANK_ANGLE_MAX_IGN = 360;
int CRANK_ANGLE_MAX_INJ = 360; // The number of crank degrees that the system track over. 360 for wasted / timed batch and 720 for sequential

View File

@ -905,6 +905,9 @@ void initialiseTriggers()
//digitalWrite(pinTrigger, HIGH);
detachInterrupt(triggerInterrupt);
detachInterrupt(triggerInterrupt2);
//The default values for edges
primaryTriggerEdge = 0; //This should ALWAYS be changed below
secondaryTriggerEdge = 0; //This is optional and may not be changed below, depending on the decoder in use
//Set the trigger function based on the decoder in the config
switch (configPage4.TrigPattern)
@ -912,222 +915,300 @@ void initialiseTriggers()
case 0:
//Missing tooth decoder
triggerSetup_missingTooth();
//trigger = triggerPri_missingTooth;
//triggerSecondary = triggerSec_missingTooth;
triggerHandler = triggerPri_missingTooth;
triggerSecondaryHandler = triggerSec_missingTooth;
decoderHasSecondary = true;
getRPM = getRPM_missingTooth;
getCrankAngle = getCrankAngle_missingTooth;
triggerSetEndTeeth = triggerSetEndTeeth_missingTooth;
if(configPage4.TrigEdge == 0) { attachInterrupt(triggerInterrupt, triggerPri_missingTooth, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { attachInterrupt(triggerInterrupt, triggerPri_missingTooth, FALLING); }
if(configPage4.TrigEdge == 0) { primaryTriggerEdge = RISING; } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { primaryTriggerEdge = FALLING; }
if(configPage4.TrigEdgeSec == 0) { secondaryTriggerEdge = RISING; }
else { secondaryTriggerEdge = FALLING; }
attachInterrupt(triggerInterrupt, triggerHandler, primaryTriggerEdge);
attachInterrupt(triggerInterrupt2, triggerSecondaryHandler, secondaryTriggerEdge);
/*
if(configPage4.TrigEdge == 0) { attachInterrupt(triggerInterrupt, triggerHandler, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { attachInterrupt(triggerInterrupt, triggerHandler, FALLING); }
if(configPage4.TrigEdgeSec == 0) { attachInterrupt(triggerInterrupt2, triggerSec_missingTooth, RISING); }
else { attachInterrupt(triggerInterrupt2, triggerSec_missingTooth, FALLING); }
*/
break;
case 1:
// Basic distributor
triggerSetup_BasicDistributor();
trigger = triggerPri_BasicDistributor;
triggerHandler = triggerPri_BasicDistributor;
getRPM = getRPM_BasicDistributor;
getCrankAngle = getCrankAngle_BasicDistributor;
triggerSetEndTeeth = triggerSetEndTeeth_BasicDistributor;
if(configPage4.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { attachInterrupt(triggerInterrupt, trigger, FALLING); }
if(configPage4.TrigEdge == 0) { primaryTriggerEdge = RISING; } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { primaryTriggerEdge = FALLING; }
attachInterrupt(triggerInterrupt, triggerHandler, primaryTriggerEdge);
break;
case 2:
triggerSetup_DualWheel();
trigger = triggerPri_DualWheel;
triggerHandler = triggerPri_DualWheel;
triggerSecondaryHandler = triggerSec_DualWheel;
decoderHasSecondary = true;
getRPM = getRPM_DualWheel;
getCrankAngle = getCrankAngle_DualWheel;
triggerSetEndTeeth = triggerSetEndTeeth_DualWheel;
if(configPage4.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { attachInterrupt(triggerInterrupt, trigger, FALLING); }
if(configPage4.TrigEdgeSec == 0) { attachInterrupt(triggerInterrupt2, triggerSec_DualWheel, RISING); }
else { attachInterrupt(triggerInterrupt2, triggerSec_DualWheel, FALLING); }
if(configPage4.TrigEdge == 0) { primaryTriggerEdge = RISING; } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { primaryTriggerEdge = FALLING; }
if(configPage4.TrigEdgeSec == 0) { secondaryTriggerEdge = RISING; }
else { secondaryTriggerEdge = FALLING; }
attachInterrupt(triggerInterrupt, triggerHandler, primaryTriggerEdge);
attachInterrupt(triggerInterrupt2, triggerSecondaryHandler, secondaryTriggerEdge);
break;
case 3:
triggerSetup_GM7X();
trigger = triggerPri_GM7X;
triggerHandler = triggerPri_GM7X;
getRPM = getRPM_GM7X;
getCrankAngle = getCrankAngle_GM7X;
triggerSetEndTeeth = triggerSetEndTeeth_GM7X;
if(configPage4.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { attachInterrupt(triggerInterrupt, trigger, FALLING); }
if(configPage4.TrigEdge == 0) { attachInterrupt(triggerInterrupt, triggerHandler, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { attachInterrupt(triggerInterrupt, triggerHandler, FALLING); }
if(configPage4.TrigEdge == 0) { primaryTriggerEdge = RISING; } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { primaryTriggerEdge = FALLING; }
attachInterrupt(triggerInterrupt, triggerHandler, primaryTriggerEdge);
break;
case 4:
triggerSetup_4G63();
trigger = triggerPri_4G63;
triggerHandler = triggerPri_4G63;
triggerSecondaryHandler = triggerSec_4G63;
decoderHasSecondary = true;
getRPM = getRPM_4G63;
getCrankAngle = getCrankAngle_4G63;
triggerSetEndTeeth = triggerSetEndTeeth_4G63;
attachInterrupt(triggerInterrupt, trigger, CHANGE); // Primary trigger connects to
attachInterrupt(triggerInterrupt2, triggerSec_4G63, FALLING);
primaryTriggerEdge = CHANGE;
secondaryTriggerEdge = FALLING;
attachInterrupt(triggerInterrupt, triggerHandler, primaryTriggerEdge);
attachInterrupt(triggerInterrupt2, triggerSecondaryHandler, secondaryTriggerEdge);
break;
case 5:
triggerSetup_24X();
trigger = triggerPri_24X;
triggerHandler = triggerPri_24X;
triggerSecondaryHandler = triggerSec_24X;
decoderHasSecondary = true;
getRPM = getRPM_24X;
getCrankAngle = getCrankAngle_24X;
triggerSetEndTeeth = triggerSetEndTeeth_24X;
if(configPage4.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { attachInterrupt(triggerInterrupt, trigger, FALLING); } // Primary trigger connects to
attachInterrupt(triggerInterrupt2, triggerSec_24X, CHANGE);
if(configPage4.TrigEdge == 0) { primaryTriggerEdge = RISING; } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { primaryTriggerEdge = FALLING; }
secondaryTriggerEdge = CHANGE; //Secondary is always on every change
attachInterrupt(triggerInterrupt, triggerHandler, primaryTriggerEdge);
attachInterrupt(triggerInterrupt2, triggerSecondaryHandler, secondaryTriggerEdge);
break;
case 6:
triggerSetup_Jeep2000();
trigger = triggerPri_Jeep2000;
triggerHandler = triggerPri_Jeep2000;
triggerSecondaryHandler = triggerSec_Jeep2000;
decoderHasSecondary = true;
getRPM = getRPM_Jeep2000;
getCrankAngle = getCrankAngle_Jeep2000;
triggerSetEndTeeth = triggerSetEndTeeth_Jeep2000;
if(configPage4.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { attachInterrupt(triggerInterrupt, trigger, FALLING); } // Primary trigger connects to
attachInterrupt(triggerInterrupt2, triggerSec_Jeep2000, CHANGE);
if(configPage4.TrigEdge == 0) { primaryTriggerEdge = RISING; } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { primaryTriggerEdge = FALLING; }
secondaryTriggerEdge = CHANGE;
attachInterrupt(triggerInterrupt, triggerHandler, primaryTriggerEdge);
attachInterrupt(triggerInterrupt2, triggerSecondaryHandler, secondaryTriggerEdge);
break;
case 7:
triggerSetup_Audi135();
trigger = triggerPri_Audi135;
triggerHandler = triggerPri_Audi135;
triggerSecondaryHandler = triggerSec_Audi135;
decoderHasSecondary = true;
getRPM = getRPM_Audi135;
getCrankAngle = getCrankAngle_Audi135;
triggerSetEndTeeth = triggerSetEndTeeth_Audi135;
if(configPage4.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { attachInterrupt(triggerInterrupt, trigger, FALLING); }
attachInterrupt(triggerInterrupt2, triggerSec_Audi135, RISING);
if(configPage4.TrigEdge == 0) { primaryTriggerEdge = RISING; } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { primaryTriggerEdge = FALLING; }
secondaryTriggerEdge = RISING; //always rising for this trigger
attachInterrupt(triggerInterrupt, triggerHandler, primaryTriggerEdge);
attachInterrupt(triggerInterrupt2, triggerSecondaryHandler, secondaryTriggerEdge);
break;
case 8:
triggerSetup_HondaD17();
trigger = triggerPri_HondaD17;
triggerHandler = triggerPri_HondaD17;
triggerSecondaryHandler = triggerSec_HondaD17;
decoderHasSecondary = true;
getRPM = getRPM_HondaD17;
getCrankAngle = getCrankAngle_HondaD17;
triggerSetEndTeeth = triggerSetEndTeeth_HondaD17;
if(configPage4.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { attachInterrupt(triggerInterrupt, trigger, FALLING); } // Primary trigger connects to
attachInterrupt(triggerInterrupt2, triggerSec_HondaD17, CHANGE);
if(configPage4.TrigEdge == 0) { primaryTriggerEdge = RISING; } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { primaryTriggerEdge = FALLING; }
secondaryTriggerEdge = CHANGE;
attachInterrupt(triggerInterrupt, triggerHandler, primaryTriggerEdge);
attachInterrupt(triggerInterrupt2, triggerSecondaryHandler, secondaryTriggerEdge);
break;
case 9:
triggerSetup_Miata9905();
trigger = triggerPri_Miata9905;
triggerHandler = triggerPri_Miata9905;
triggerSecondaryHandler = triggerSec_Miata9905;
decoderHasSecondary = true;
getRPM = getRPM_Miata9905;
getCrankAngle = getCrankAngle_Miata9905;
triggerSetEndTeeth = triggerSetEndTeeth_Miata9905;
//These may both need to change, not sure
// Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
if(configPage4.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); }
else { attachInterrupt(triggerInterrupt, trigger, FALLING); }
if(configPage4.TrigEdge == 0) { primaryTriggerEdge = RISING; } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { primaryTriggerEdge = FALLING; }
if(configPage4.TrigEdgeSec == 0) { secondaryTriggerEdge = RISING; }
else { secondaryTriggerEdge = FALLING; }
if(configPage4.TrigEdgeSec == 0) { attachInterrupt(triggerInterrupt2, triggerSec_Miata9905, RISING); }
else { attachInterrupt(triggerInterrupt2, triggerSec_Miata9905, FALLING); }
attachInterrupt(triggerInterrupt, triggerHandler, primaryTriggerEdge);
attachInterrupt(triggerInterrupt2, triggerSecondaryHandler, secondaryTriggerEdge);
break;
case 10:
triggerSetup_MazdaAU();
trigger = triggerPri_MazdaAU;
triggerHandler = triggerPri_MazdaAU;
triggerSecondaryHandler = triggerSec_MazdaAU;
decoderHasSecondary = true;
getRPM = getRPM_MazdaAU;
getCrankAngle = getCrankAngle_MazdaAU;
triggerSetEndTeeth = triggerSetEndTeeth_MazdaAU;
if(configPage4.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { attachInterrupt(triggerInterrupt, trigger, FALLING); } // Primary trigger connects to
attachInterrupt(triggerInterrupt2, triggerSec_MazdaAU, FALLING);
if(configPage4.TrigEdge == 0) { primaryTriggerEdge = RISING; } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { primaryTriggerEdge = FALLING; }
secondaryTriggerEdge = FALLING;
attachInterrupt(triggerInterrupt, triggerHandler, primaryTriggerEdge);
attachInterrupt(triggerInterrupt2, triggerSecondaryHandler, secondaryTriggerEdge);
break;
case 11:
triggerSetup_non360();
trigger = triggerPri_DualWheel; //Is identical to the dual wheel decoder, so that is used. Same goes for the secondary below
triggerHandler = triggerPri_DualWheel; //Is identical to the dual wheel decoder, so that is used. Same goes for the secondary below
triggerSecondaryHandler = triggerSec_DualWheel; //Note the use of the Dual Wheel trigger function here. No point in having the same code in twice.
decoderHasSecondary = true;
getRPM = getRPM_non360;
getCrankAngle = getCrankAngle_non360;
triggerSetEndTeeth = triggerSetEndTeeth_non360;
if(configPage4.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { attachInterrupt(triggerInterrupt, trigger, FALLING); }
attachInterrupt(triggerInterrupt2, triggerSec_DualWheel, FALLING); //Note the use of the Dual Wheel trigger function here. No point in having the same code in twice.
if(configPage4.TrigEdge == 0) { primaryTriggerEdge = RISING; } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { primaryTriggerEdge = FALLING; }
secondaryTriggerEdge = FALLING;
attachInterrupt(triggerInterrupt, triggerHandler, primaryTriggerEdge);
attachInterrupt(triggerInterrupt2, triggerSecondaryHandler, secondaryTriggerEdge);
break;
case 12:
triggerSetup_Nissan360();
trigger = triggerPri_Nissan360;
triggerHandler = triggerPri_Nissan360;
triggerSecondaryHandler = triggerSec_Nissan360;
decoderHasSecondary = true;
getRPM = getRPM_Nissan360;
getCrankAngle = getCrankAngle_Nissan360;
triggerSetEndTeeth = triggerSetEndTeeth_Nissan360;
if(configPage4.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { attachInterrupt(triggerInterrupt, trigger, FALLING); }
attachInterrupt(triggerInterrupt2, triggerSec_Nissan360, CHANGE);
if(configPage4.TrigEdge == 0) { primaryTriggerEdge = RISING; } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { primaryTriggerEdge = FALLING; }
secondaryTriggerEdge = CHANGE;
attachInterrupt(triggerInterrupt, triggerHandler, primaryTriggerEdge);
attachInterrupt(triggerInterrupt2, triggerSecondaryHandler, secondaryTriggerEdge);
break;
case 13:
triggerSetup_Subaru67();
trigger = triggerPri_Subaru67;
triggerHandler = triggerPri_Subaru67;
triggerSecondaryHandler = triggerSec_Subaru67;
decoderHasSecondary = true;
getRPM = getRPM_Subaru67;
getCrankAngle = getCrankAngle_Subaru67;
triggerSetEndTeeth = triggerSetEndTeeth_Subaru67;
if(configPage4.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { attachInterrupt(triggerInterrupt, trigger, FALLING); }
attachInterrupt(triggerInterrupt2, triggerSec_Subaru67, FALLING);
if(configPage4.TrigEdge == 0) { primaryTriggerEdge = RISING; } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { primaryTriggerEdge = FALLING; }
secondaryTriggerEdge = FALLING;
attachInterrupt(triggerInterrupt, triggerHandler, primaryTriggerEdge);
attachInterrupt(triggerInterrupt2, triggerSecondaryHandler, secondaryTriggerEdge);
break;
case 14:
triggerSetup_Daihatsu();
trigger = triggerPri_Daihatsu;
triggerHandler = triggerPri_Daihatsu;
getRPM = getRPM_Daihatsu;
getCrankAngle = getCrankAngle_Daihatsu;
triggerSetEndTeeth = triggerSetEndTeeth_Daihatsu;
if(configPage4.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { attachInterrupt(triggerInterrupt, trigger, FALLING); }
//No secondary input required for this pattern
if(configPage4.TrigEdge == 0) { primaryTriggerEdge = RISING; } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { primaryTriggerEdge = FALLING; }
attachInterrupt(triggerInterrupt, triggerHandler, primaryTriggerEdge);
break;
case 15:
triggerSetup_Harley();
trigger = triggerPri_Harley;
//triggerSecondary = triggerSec_Harley;
triggerHandler = triggerPri_Harley;
//triggerSecondaryHandler = triggerSec_Harley;
getRPM = getRPM_Harley;
getCrankAngle = getCrankAngle_Harley;
triggerSetEndTeeth = triggerSetEndTeeth_Harley;
attachInterrupt(triggerInterrupt, trigger, RISING);
// attachInterrupt(triggerInterrupt2, triggerSec_Harley, FALLING);
primaryTriggerEdge = RISING; //Always rising
attachInterrupt(triggerInterrupt, triggerHandler, primaryTriggerEdge);
break;
case 16:
//36-2-2-2
triggerSetup_ThirtySixMinus222();
trigger = triggerPri_ThirtySixMinus222;
triggerSecondary = triggerSec_ThirtySixMinus222;
triggerHandler = triggerPri_ThirtySixMinus222;
triggerSecondaryHandler = triggerSec_ThirtySixMinus222;
decoderHasSecondary = true;
getRPM = getRPM_missingTooth; //This uses the same function as the missing tooth decoder, so no need to duplicate code
getCrankAngle = getCrankAngle_missingTooth; //This uses the same function as the missing tooth decoder, so no need to duplicate code
triggerSetEndTeeth = triggerSetEndTeeth_ThirtySixMinus222;
if(configPage4.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { attachInterrupt(triggerInterrupt, trigger, FALLING); }
if(configPage4.TrigEdgeSec == 0) { attachInterrupt(triggerInterrupt2, triggerSecondary, RISING); }
else { attachInterrupt(triggerInterrupt2, triggerSecondary, FALLING); }
if(configPage4.TrigEdge == 0) { primaryTriggerEdge = RISING; } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { primaryTriggerEdge = FALLING; }
if(configPage4.TrigEdgeSec == 0) { secondaryTriggerEdge = RISING; }
else { secondaryTriggerEdge = FALLING; }
attachInterrupt(triggerInterrupt, triggerHandler, primaryTriggerEdge);
attachInterrupt(triggerInterrupt2, triggerSecondaryHandler, secondaryTriggerEdge);
break;
default:
trigger = triggerPri_missingTooth;
triggerHandler = triggerPri_missingTooth;
getRPM = getRPM_missingTooth;
getCrankAngle = getCrankAngle_missingTooth;
if(configPage4.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { attachInterrupt(triggerInterrupt, trigger, FALLING); }
if(configPage4.TrigEdge == 0) { attachInterrupt(triggerInterrupt, triggerHandler, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { attachInterrupt(triggerInterrupt, triggerHandler, FALLING); }
break;
}
}