Initial work on 4G63 decoder
This commit is contained in:
parent
4f6421a65e
commit
138a89c48f
|
@ -11,7 +11,14 @@ volatile unsigned long toothOneMinusOneTime = 0; //The 2nd to last time (micros(
|
|||
volatile int toothHistory[512];
|
||||
volatile int toothHistoryIndex = 0;
|
||||
|
||||
volatile byte secondaryToothCount; //Used for identifying the current secondary (Usually cam) tooth for patterns with multiple secondary teeth
|
||||
volatile unsigned long secondaryLastToothTime = 0; //The time (micros()) that the last tooth was registered (Cam input)
|
||||
|
||||
volatile int triggerActualTeeth;
|
||||
unsigned int triggerFilterTime; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering)
|
||||
unsigned int triggerToothAngle; //The number of crank degrees that elapse per tooth
|
||||
unsigned long revolutionTime; //The time in uS that one revolution would take at current speed (The time tooth 1 was last seen, minus the time it was seen prior to that)
|
||||
|
||||
//Used for identifying long and short pulses on the 4G63 (And possibly other) trigger patterns
|
||||
#define LONG 0;
|
||||
#define SHORT 1;
|
||||
|
|
66
decoders.ino
66
decoders.ino
|
@ -254,3 +254,69 @@ int getCrankAngle_GM7X(int timePerDegree)
|
|||
}
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Name: Mitsubishi 4G63 / NA/NB Miata + MX-5 / 4/2
|
||||
Desc: TBA
|
||||
Note: TBA
|
||||
*/
|
||||
void triggerSetup_4G63()
|
||||
{
|
||||
triggerToothAngle = 180; //The number of degrees that passes from tooth to tooth (primary)
|
||||
}
|
||||
|
||||
void triggerPri_4G63()
|
||||
{
|
||||
curTime = micros();
|
||||
|
||||
if(toothCurrentCount == 1) { toothCurrentCount == 2; }
|
||||
else
|
||||
{
|
||||
toothCurrentCount = 1; //Reset the counter
|
||||
toothOneMinusOneTime = toothOneTime;
|
||||
toothOneTime = curTime;
|
||||
currentStatus.hasSync = true;
|
||||
startRevolutions++; //Counter
|
||||
}
|
||||
|
||||
//High speed tooth logging history
|
||||
toothHistory[toothHistoryIndex] = curGap;
|
||||
if(toothHistoryIndex == 511)
|
||||
{ toothHistoryIndex = 0; }
|
||||
else
|
||||
{ toothHistoryIndex++; }
|
||||
|
||||
toothLastMinusOneToothTime = toothLastToothTime;
|
||||
toothLastToothTime = curTime;
|
||||
}
|
||||
void triggerSec_4G63()
|
||||
{
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int getRPM_4G63()
|
||||
{
|
||||
noInterrupts();
|
||||
revolutionTime = (toothOneTime - toothOneMinusOneTime); //The time in uS that one revolution would take at current speed (The time tooth 1 was last seen, minus the time it was seen prior to that)
|
||||
interrupts();
|
||||
return ldiv(US_IN_MINUTE, revolutionTime).quot; //Calc RPM based on last full revolution time (uses ldiv rather than div as US_IN_MINUTE is a long)
|
||||
}
|
||||
int getCrankAngle_4G63(int timePerDegree)
|
||||
{
|
||||
//This is the current angle ATDC the engine is at. This is the last known position based on what tooth was last 'seen'. It is only accurate to the resolution of the trigger wheel (Eg 36-1 is 10 degrees)
|
||||
unsigned long tempToothLastToothTime;
|
||||
int tempToothCurrentCount;
|
||||
//Grab some variables that are used in the trigger code and assign them to temp variables.
|
||||
noInterrupts();
|
||||
tempToothCurrentCount = toothCurrentCount;
|
||||
tempToothLastToothTime = toothLastToothTime;
|
||||
interrupts();
|
||||
|
||||
int crankAngle = (tempToothCurrentCount - 1) * triggerToothAngle + configPage2.triggerAngle; //Number of teeth that have passed since tooth 1, multiplied by the angle each tooth represents, plus the angle that tooth 1 is ATDC. This gives accuracy only to the nearest tooth.
|
||||
crankAngle += ldiv( (micros() - tempToothLastToothTime), timePerDegree).quot; //Estimate the number of degrees travelled since the last tooth
|
||||
if (crankAngle > 360) { crankAngle -= 360; }
|
||||
|
||||
return crankAngle;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue