Complete but untested 4G63 / Miata decoder

This commit is contained in:
Josh Stewart 2015-07-26 21:49:22 +10:00
parent 4ea46c201c
commit 322f0f6795
2 changed files with 24 additions and 8 deletions

View File

@ -257,26 +257,35 @@ int getCrankAngle_GM7X(int timePerDegree)
/* -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Name: Mitsubishi 4G63 / NA/NB Miata + MX-5 / 4/2
Desc: TBA
Note: TBA
Note: http://i39.photobucket.com/albums/e191/Archiqtechnik/DSM/Diagrams/Evo8CrankCamphase_zps8a91152d.jpg
Tooth #1 is defined as the one where the signal is HIGH when the cam signal is falling. (Isthe 3rd crank pulse in the above diamgram)
*/
void triggerSetup_4G63()
{
triggerToothAngle = 180; //The number of degrees that passes from tooth to tooth (primary)
toothCurrentCount = 99; //Fake tooth count represents no sync
//Note that these angles are for every rising and falling edge
toothAngles[0] = 355; //Falling edge of tooth #1
toothAngles[1] = 105; //Rising edge of tooth #2
toothAngles[2] = 175; //Falling edge of tooth #2
toothAngles[3] = 285; //Rising edge of tooth #1
}
void triggerPri_4G63()
{
curTime = micros();
if(toothCurrentCount == 1) { toothCurrentCount == 2; }
else
if(toothCurrentCount == 0 || toothCurrentCount == 4)
{
toothCurrentCount = 1; //Reset the counter
toothOneMinusOneTime = toothOneTime;
toothOneTime = curTime;
currentStatus.hasSync = true;
startRevolutions++; //Counter
}
}
else { toothCurrentCount++; }
//High speed tooth logging history
toothHistory[toothHistoryIndex] = curGap;
@ -290,8 +299,13 @@ void triggerPri_4G63()
}
void triggerSec_4G63()
{
return;
if(!currentStatus.hasSync)
{
//Check the status of the crank trigger
bool crank = digitalRead(pinTrigger);
if(crank) { toothCurrentCount = 0; } //If the crank trigger is currently HIGH, it means we're on tooth #1
}
return;
}
@ -313,7 +327,7 @@ int getCrankAngle_4G63(int timePerDegree)
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.
int crankAngle = toothAngles[(tempToothCurrentCount - 1)] + configPage2.triggerAngle; //Perform a lookup of the fixed toothAngles array to find what the angle of the last tooth passed was.
crankAngle += ldiv( (micros() - tempToothLastToothTime), timePerDegree).quot; //Estimate the number of degrees travelled since the last tooth
if (crankAngle > 360) { crankAngle -= 360; }
@ -412,6 +426,7 @@ int getCrankAngle_24X(int timePerDegree)
int crankAngle;
if (toothCurrentCount == 0) { crankAngle = 0 + configPage2.triggerAngle; } //This is the special case to handle when the 'last tooth' seen was the cam tooth. 0 is the angle at which the crank tooth goes high (Within 360 degrees).
else { crankAngle = toothAngles[(tempToothCurrentCount - 1)] + configPage2.triggerAngle;} //Perform a lookup of the fixed toothAngles array to find what the angle of the last tooth passed was.
crankAngle += ldiv( (micros() - tempToothLastToothTime), timePerDegree).quot; //Estimate the number of degrees travelled since the last tooth
if (crankAngle > 360) { crankAngle -= 360; }
return crankAngle;

View File

@ -261,9 +261,10 @@ void setup()
getRPM = getRPM_4G63;
getCrankAngle = getCrankAngle_4G63;
//These may both need to change, not sure
if(configPage2.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_4G63, CHANGE);
attachInterrupt(triggerInterrupt2, triggerSec_4G63, FALLING);
break;
case 5: