Complete, but untested, 'Basic Distributor' decoder
This commit is contained in:
parent
30caaada2b
commit
73b8979dfc
|
@ -11,4 +11,5 @@ volatile int toothHistory[512];
|
|||
volatile int toothHistoryIndex = 0;
|
||||
|
||||
volatile int triggerActualTeeth;
|
||||
unsigned int triggerFilterTime, triggerToothAngle; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering)
|
||||
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
|
||||
|
|
62
decoders.ino
62
decoders.ino
|
@ -3,6 +3,7 @@ This file contains the various crank and cam wheel decoder functions.
|
|||
|
||||
Each decoder must have the following 4 functions (Where xxxx is the decoder name):
|
||||
|
||||
* triggerSetup_xxx - Called once from within setup() and configures any required variables
|
||||
* triggerPri_xxxx - Called each time the primary (No. 1) crank/cam signal is triggered (Called as an interrupt, so variables must be declared volatile)
|
||||
* triggerSec_xxxx - Called each time the secondary (No. 2) crank/cam signal is triggered (Called as an interrupt, so variables must be declared volatile)
|
||||
* getRPM_xxxx - Returns the current RPM, as calculated by the decoder
|
||||
|
@ -19,6 +20,12 @@ Name: Missing tooth wheel
|
|||
Desc: A multi-tooth wheel with one of more 'missing' teeth. The first tooth after the missing one is considered number 1 and isthe basis for the trigger angle
|
||||
Note: This does not currently support dual wheel (ie missing tooth + single tooth on cam)
|
||||
*/
|
||||
void triggerSetup_missingTooth()
|
||||
{
|
||||
triggerToothAngle = 360 / configPage2.triggerTeeth; //The number of degrees that passes from tooth to tooth
|
||||
triggerActualTeeth = configPage2.triggerTeeth - configPage2.triggerMissingTeeth; //The number of physical teeth on the wheel. Doing this here saves us a calculation each time in the interrupt
|
||||
}
|
||||
|
||||
void triggerPri_missingTooth()
|
||||
{
|
||||
// http://www.msextra.com/forums/viewtopic.php?f=94&t=22976
|
||||
|
@ -87,3 +94,58 @@ void triggerPri_DualWheel()
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Name: Basic Distributor
|
||||
Desc: Tooth equal to the number of cylinders are evenly spaced on the cam. No position sensing (Distributor is retained) so crank angle is a made up figure based purely on the first teeth to be seen
|
||||
Note: This is a very simple decoder. See http://www.megamanual.com/ms2/GM_7pinHEI.htm
|
||||
*/
|
||||
void triggerSetup_BasicDistributor()
|
||||
{
|
||||
triggerToothAngle = 360 / (configPage1.nCylinders / 2); //The number of degrees that passes from tooth to tooth
|
||||
}
|
||||
|
||||
void triggerPri_BasicDistributor()
|
||||
{
|
||||
curTime = micros();
|
||||
|
||||
toothCurrentCount++; //Increment the tooth counter
|
||||
if(toothCurrentCount > 8) //Check if we're back to the beginning of a cycle
|
||||
{
|
||||
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_BasicDistributor() { return; } //Not required
|
||||
int getRPM_BasicDistributor()
|
||||
{
|
||||
noInterrupts();
|
||||
unsigned long 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_BasicDistributor(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)
|
||||
int crankAngle = (toothCurrentCount - 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() - toothLastToothTime), timePerDegree).quot; //Estimate the number of degrees travelled since the last tooth
|
||||
if (crankAngle > 360) { crankAngle -= 360; }
|
||||
|
||||
return crankAngle;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -177,7 +177,7 @@ page = 2
|
|||
TrigSpeed = bits, U08, 85[1:1], "Crank Speed", "Cam Speed"
|
||||
IgInv = bits, U08, 85[2:2], "No", "Yes"
|
||||
oddfire = bits, U08, 85[3:3], "No", "Yes"
|
||||
TrigPattern= bits, U08, 85[4:7], "Missing Tooth", "Dual Wheel", "HEI", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID"
|
||||
TrigPattern= bits, U08, 85[4:7], "Missing Tooth", "Basic Distributor", "Dual Wheel", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID"
|
||||
IdleAdv = scalar, U08, 86, "Deg", 0.352,-28.4, -10, 80, 0
|
||||
IdleAdvTPS = scalar, U08, 87, "ADC", 1, 0, 0, 255, 0
|
||||
IdleAdvRPM = scalar, U08, 88, "RPM", 100, 0, 0, 1200, 0
|
||||
|
@ -458,10 +458,10 @@ page = 3
|
|||
dialog = triggerSettings,"Trigger Settings",3
|
||||
topicHelp = Shelp3
|
||||
field = "Trigger Pattern", TrigPattern
|
||||
field = "Primary base teeth", numteeth
|
||||
field = "Primary trigger speed", TrigSpeed
|
||||
field = "Primary base teeth", numteeth, { TrigPattern != 1 }
|
||||
field = "Primary trigger speed", TrigSpeed, { TrigPattern != 1 }
|
||||
field = "Missing teeth", onetwo, { TrigPattern == 0 }
|
||||
field = "Secondary teeth", onetwo, { TrigPattern == 1 }
|
||||
field = "Secondary teeth", onetwo, { TrigPattern == 2 }
|
||||
field = "Trigger Angle ", TrigAng
|
||||
field = "This number represents the angle ATDC when "
|
||||
field = "tooth #1 passes the primary sensor."
|
||||
|
|
|
@ -141,8 +141,6 @@ void setup()
|
|||
|
||||
//Once the configs have been loaded, a number of one time calculations can be completed
|
||||
req_fuel_uS = configPage1.reqFuel * 100; //Convert to uS and an int. This is the only variable to be used in calculations
|
||||
triggerToothAngle = 360 / configPage2.triggerTeeth; //The number of degrees that passes from tooth to tooth
|
||||
triggerActualTeeth = configPage2.triggerTeeth - configPage2.triggerMissingTeeth; //The number of physical teeth on the wheel. Doing this here saves us a calculation each time in the interrupt
|
||||
inj_opentime_uS = configPage1.injOpen * 100; //Injector open time. Comes through as ms*10 (Eg 15.5ms = 155).
|
||||
|
||||
//Begin the main crank trigger interrupt pin setup
|
||||
|
@ -181,6 +179,7 @@ void setup()
|
|||
{
|
||||
case 0:
|
||||
//Missing tooth decoder
|
||||
triggerSetup_missingTooth();
|
||||
trigger = triggerPri_missingTooth;
|
||||
triggerSecondary = triggerSec_missingTooth;
|
||||
getRPM = getRPM_missingTooth;
|
||||
|
@ -188,11 +187,15 @@ void setup()
|
|||
break;
|
||||
|
||||
case 1:
|
||||
trigger = triggerPri_DualWheel;
|
||||
// Basic distributor
|
||||
triggerSetup_BasicDistributor();
|
||||
trigger = triggerPri_BasicDistributor;
|
||||
getRPM = getRPM_BasicDistributor;
|
||||
getCrankAngle = getCrankAngle_BasicDistributor;
|
||||
break;
|
||||
|
||||
|
||||
case 2:
|
||||
trigger = triggerPri_missingTooth;
|
||||
trigger = triggerPri_DualWheel;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue