Minor cleanups to missing tooth per tooth calc

This commit is contained in:
Josh Stewart 2018-09-04 17:07:21 +10:00
parent bf6c7b19d4
commit b555392636
5 changed files with 10 additions and 15 deletions

View File

@ -3037,7 +3037,7 @@ cmdtestspk450dc = "E\x03\x0C"
recordDef = 0, 0, 2; in bytes, the recordLen is for each record, currently limited to 4 bytes
;recordField = Name, HeaderName, startBit, bitCount, scale, units, updateCondition
recordField = toothGap, "ToothTime", 0, 16, 1.0, "uS"
recordField = toothTime, "ToothTime", 0, 16, 1.0, "uS"
[Tools]

View File

@ -159,7 +159,6 @@ void triggerSetup_missingTooth()
{
triggerSecFilterTime = (int)(1000000 / (MAX_RPM / 60));
}
//triggerSecFilterTime = (int)((configPage4.trigPatternSec == SEC_TRIGGER_4_1 ) ? 1000000 * 60 / MAX_RPM / 4 / 2 : 1000000 * 60 / MAX_RPM / 2 / 2); //For 4-1 came wheel. Same as above, but fixed at 2 teeth on the secondary input and divided by 2 (for cam speed)
secondDerivEnabled = false;
decoderIsSequential = false;
checkSyncToothCount = (configPage4.triggerTeeth) >> 1; //50% of the total teeth.
@ -341,22 +340,22 @@ void triggerSetEndTeeth_missingTooth()
ignition1EndTooth = ( (ignition1EndAngle - configPage4.triggerAngle) / triggerToothAngle ) - 1;
if(ignition1EndTooth > (configPage4.triggerTeeth + toothAdder)) { ignition1EndTooth -= (configPage4.triggerTeeth + toothAdder); }
if(ignition1EndTooth <= 0) { ignition1EndTooth += configPage4.triggerTeeth; }
if(ignition1EndTooth <= 0) { ignition1EndTooth += (configPage4.triggerTeeth + toothAdder); }
if(ignition1EndTooth > (triggerActualTeeth + toothAdder)) { ignition1EndTooth = (triggerActualTeeth + toothAdder); }
ignition2EndTooth = ( (ignition2EndAngle - configPage4.triggerAngle) / triggerToothAngle ) - 1;
if(ignition2EndTooth > (configPage4.triggerTeeth + toothAdder)) { ignition2EndTooth -= (configPage4.triggerTeeth + toothAdder); }
if(ignition2EndTooth <= 0) { ignition2EndTooth += configPage4.triggerTeeth; }
if(ignition2EndTooth <= 0) { ignition2EndTooth += (configPage4.triggerTeeth + toothAdder); }
if(ignition1EndTooth > (triggerActualTeeth + toothAdder)) { ignition3EndTooth = (triggerActualTeeth + toothAdder); }
ignition3EndTooth = ( (ignition3EndAngle - configPage4.triggerAngle) / triggerToothAngle ) - 1;
if(ignition3EndTooth > (configPage4.triggerTeeth + toothAdder)) { ignition3EndTooth -= (configPage4.triggerTeeth + toothAdder); }
if(ignition3EndTooth <= 0) { ignition3EndTooth += configPage4.triggerTeeth; }
if(ignition3EndTooth <= 0) { ignition3EndTooth += (configPage4.triggerTeeth + toothAdder); }
if(ignition3EndTooth > (triggerActualTeeth + toothAdder)) { ignition3EndTooth = (triggerActualTeeth + toothAdder); }
ignition4EndTooth = ( (ignition4EndAngle - configPage4.triggerAngle) / triggerToothAngle ) - 1;
if(ignition4EndTooth > (configPage4.triggerTeeth + toothAdder)) { ignition4EndTooth -= (configPage4.triggerTeeth + toothAdder); }
if(ignition4EndTooth <= 0) { ignition4EndTooth += configPage4.triggerTeeth; }
if(ignition4EndTooth <= 0) { ignition4EndTooth += (configPage4.triggerTeeth + toothAdder); }
if(ignition4EndTooth > (triggerActualTeeth + toothAdder)) { ignition4EndTooth = (triggerActualTeeth + toothAdder); }
lastToothCalcAdvance = currentStatus.advance;

View File

@ -25,7 +25,7 @@ See page 136 of the processors datasheet: http://www.atmel.com/Images/doc2549.pd
#ifndef SCHEDULER_H
#define SCHEDULER_H
//#define USE_IGN_REFRESH
#define USE_IGN_REFRESH
#define IGNITION_REFRESH_THRESHOLD 30 //Time in uS that the refresh functions will check to ensure there is enough time before changing the end compare
#if defined(CORE_AVR)
#include <avr/interrupt.h>

View File

@ -665,12 +665,8 @@ static inline void refreshIgnitionSchedule1(unsigned long timeToEnd)
//Must have the threshold check here otherwise it can cause a condition where the compare fires twice, once after the other, both for the end
//if( (timeToEnd < ignitionSchedule1.duration) && (timeToEnd > IGNITION_REFRESH_THRESHOLD) )
{
unsigned long adjustedTimeToEnd = timeToEnd;
noInterrupts();
//unsigned long timeSinceLastCrankAngleCalc = (micros() - lastCrankAngleCalc);
//Take into account any time that has passed since the last crank angle calculation
//if(timeToEnd > timeSinceLastCrankAngleCalc) { adjustedTimeToEnd = timeToEnd - timeSinceLastCrankAngleCalc; }
ignitionSchedule1.endCompare = IGN1_COUNTER + uS_TO_TIMER_COMPARE(adjustedTimeToEnd);
ignitionSchedule1.endCompare = IGN1_COUNTER + uS_TO_TIMER_COMPARE(timeToEnd);
IGN1_COMPARE = ignitionSchedule1.endCompare;
interrupts();
}
@ -1184,8 +1180,8 @@ static inline void ignitionSchedule1Interrupt() //Most ARM chips can simply call
}
else if (ignitionSchedule1.Status == RUNNING)
{
ignitionSchedule1.EndCallback();
//*ign1_pin_port &= ~(ign1_pin_mask);
//ignitionSchedule1.EndCallback();
*ign1_pin_port &= ~(ign1_pin_mask);
ignitionSchedule1.Status = OFF; //Turn off the schedule
ignitionSchedule1.schedulesSet = 0;
ignitionSchedule1.hasNextSchedule = false;

View File

@ -1768,7 +1768,7 @@ void loop()
#endif
#if defined(USE_IGN_REFRESH)
if( (ignitionSchedule1.Status == RUNNING) && (ignition1EndAngle > crankAngle) && (configPage4.StgCycles == 0) )
if( (ignitionSchedule1.Status == RUNNING) && (ignition1EndAngle > crankAngle) && (configPage4.StgCycles == 0) && (configPage2.perToothIgn != true) )
{
unsigned long uSToEnd = 0;