Add degreesOver argument for cranking rpm function (Matches regular rpm function)

This commit is contained in:
Josh Stewart 2021-02-22 10:44:12 +11:00
parent b36cf51fe0
commit f866114b22
2 changed files with 12 additions and 11 deletions

View File

@ -38,7 +38,7 @@ void loggerPrimaryISR();
void loggerSecondaryISR(); void loggerSecondaryISR();
static inline uint16_t stdGetRPM(uint16_t); static inline uint16_t stdGetRPM(uint16_t);
static inline void setFilter(unsigned long); static inline void setFilter(unsigned long);
static inline int crankingGetRPM(byte); static inline int crankingGetRPM(byte, uint16_t);
//static inline void doPerToothTiming(uint16_t); //static inline void doPerToothTiming(uint16_t);
//All of the below are the 6 required functions for each decoder / pattern //All of the below are the 6 required functions for each decoder / pattern

View File

@ -250,7 +250,7 @@ This gives much more volatile reading, but is quite useful during cranking, part
It can only be used on patterns where the teeth are evently spaced It can only be used on patterns where the teeth are evently spaced
It takes an argument of the full (COMPLETE) number of teeth per revolution. For a missing tooth wheel, this is the number if the tooth had NOT been missing (Eg 36-1 = 36) It takes an argument of the full (COMPLETE) number of teeth per revolution. For a missing tooth wheel, this is the number if the tooth had NOT been missing (Eg 36-1 = 36)
*/ */
static inline int crankingGetRPM(byte totalTeeth) static inline int crankingGetRPM(byte totalTeeth, uint16_t degreesOver)
{ {
uint16_t tempRPM = 0; uint16_t tempRPM = 0;
if( (currentStatus.startRevolutions >= configPage4.StgCycles) && (currentStatus.hasSync == true) ) if( (currentStatus.startRevolutions >= configPage4.StgCycles) && (currentStatus.hasSync == true) )
@ -260,6 +260,7 @@ static inline int crankingGetRPM(byte totalTeeth)
noInterrupts(); noInterrupts();
revolutionTime = (toothLastToothTime - toothLastMinusOneToothTime) * totalTeeth; revolutionTime = (toothLastToothTime - toothLastMinusOneToothTime) * totalTeeth;
interrupts(); interrupts();
if(degreesOver == 720) { revolutionTime = revolutionTime / 2; }
tempRPM = (US_IN_MINUTE / revolutionTime); tempRPM = (US_IN_MINUTE / revolutionTime);
if( tempRPM >= MAX_RPM ) { tempRPM = currentStatus.RPM; } //Sanity check. This can prevent spiking caused by noise on individual teeth. The new RPM should never be above 4x the cranking setting value (Remembering that this function is only called is the current RPM is less than the cranking setting) if( tempRPM >= MAX_RPM ) { tempRPM = currentStatus.RPM; } //Sanity check. This can prevent spiking caused by noise on individual teeth. The new RPM should never be above 4x the cranking setting value (Remembering that this function is only called is the current RPM is less than the cranking setting)
} }
@ -531,8 +532,8 @@ uint16_t getRPM_missingTooth()
{ {
if(toothCurrentCount != 1) if(toothCurrentCount != 1)
{ {
if(configPage4.TrigSpeed == CAM_SPEED) { tempRPM = crankingGetRPM(configPage4.triggerTeeth/2); } //Account for cam speed if(configPage4.TrigSpeed == CAM_SPEED) { tempRPM = crankingGetRPM(configPage4.triggerTeeth, 720); } //Account for cam speed
else { tempRPM = crankingGetRPM(configPage4.triggerTeeth); } else { tempRPM = crankingGetRPM(configPage4.triggerTeeth, 360); }
} }
else { tempRPM = currentStatus.RPM; } //Can't do per tooth RPM if we're at tooth #1 as the missing tooth messes the calculation else { tempRPM = currentStatus.RPM; } //Can't do per tooth RPM if we're at tooth #1 as the missing tooth messes the calculation
} }
@ -739,7 +740,7 @@ uint16_t getRPM_DualWheel()
uint16_t tempRPM = 0; uint16_t tempRPM = 0;
if( currentStatus.hasSync == true ) if( currentStatus.hasSync == true )
{ {
if(currentStatus.RPM < currentStatus.crankRPM) { tempRPM = crankingGetRPM(configPage4.triggerTeeth); } if(currentStatus.RPM < currentStatus.crankRPM) { tempRPM = crankingGetRPM(configPage4.triggerTeeth, 360); }
else { tempRPM = stdGetRPM(360); } else { tempRPM = stdGetRPM(360); }
} }
return tempRPM; return tempRPM;
@ -925,7 +926,7 @@ uint16_t getRPM_BasicDistributor()
uint16_t tempRPM; uint16_t tempRPM;
if( currentStatus.RPM < currentStatus.crankRPM) if( currentStatus.RPM < currentStatus.crankRPM)
{ {
tempRPM = crankingGetRPM( (triggerActualTeeth / 2) ); //crankGetRPM uses teeth per 360 degrees. As triggerActualTeeh is total teeth in 720 degrees, we divide the tooth count by 2 tempRPM = crankingGetRPM(triggerActualTeeth, 720);
} }
else { tempRPM = stdGetRPM(720); } else { tempRPM = stdGetRPM(720); }
@ -2457,7 +2458,7 @@ uint16_t getRPM_non360()
uint16_t tempRPM = 0; uint16_t tempRPM = 0;
if( (currentStatus.hasSync == true) && (toothCurrentCount != 0) ) if( (currentStatus.hasSync == true) && (toothCurrentCount != 0) )
{ {
if(currentStatus.RPM < currentStatus.crankRPM) { tempRPM = crankingGetRPM(configPage4.triggerTeeth); } if(currentStatus.RPM < currentStatus.crankRPM) { tempRPM = crankingGetRPM(configPage4.triggerTeeth, 360); }
else { tempRPM = stdGetRPM(360); } else { tempRPM = stdGetRPM(360); }
} }
return tempRPM; return tempRPM;
@ -3404,11 +3405,11 @@ uint16_t getRPM_ThirtySixMinus222()
if( (configPage2.nCylinders == 4) && (toothCurrentCount != 19) && (toothCurrentCount != 16) && (toothCurrentCount != 34) && (triggerToothAngleIsCorrect == true) ) if( (configPage2.nCylinders == 4) && (toothCurrentCount != 19) && (toothCurrentCount != 16) && (toothCurrentCount != 34) && (triggerToothAngleIsCorrect == true) )
{ {
tempRPM = crankingGetRPM(36); tempRPM = crankingGetRPM(36, 360);
} }
else if( (configPage2.nCylinders == 6) && (toothCurrentCount != 9) && (toothCurrentCount != 12) && (toothCurrentCount != 33) && (triggerToothAngleIsCorrect == true) ) else if( (configPage2.nCylinders == 6) && (toothCurrentCount != 9) && (toothCurrentCount != 12) && (toothCurrentCount != 33) && (triggerToothAngleIsCorrect == true) )
{ {
tempRPM = crankingGetRPM(36); tempRPM = crankingGetRPM(36, 360);
} }
else { tempRPM = currentStatus.RPM; } //Can't do per tooth RPM if we're at and of the missing teeth as it messes the calculation else { tempRPM = currentStatus.RPM; } //Can't do per tooth RPM if we're at and of the missing teeth as it messes the calculation
} }
@ -3564,7 +3565,7 @@ uint16_t getRPM_ThirtySixMinus21()
{ {
if( (toothCurrentCount != 20) && (triggerToothAngleIsCorrect == true) ) if( (toothCurrentCount != 20) && (triggerToothAngleIsCorrect == true) )
{ {
tempRPM = crankingGetRPM(36); tempRPM = crankingGetRPM(36, 360);
} }
else { tempRPM = currentStatus.RPM; } //Can't do per tooth RPM if we're at tooth #1 as the missing tooth messes the calculation else { tempRPM = currentStatus.RPM; } //Can't do per tooth RPM if we're at tooth #1 as the missing tooth messes the calculation
} }
@ -3963,7 +3964,7 @@ uint16_t getRPM_FordST170()
{ {
if(toothCurrentCount != 1) if(toothCurrentCount != 1)
{ {
tempRPM = crankingGetRPM(36); tempRPM = crankingGetRPM(36, 360);
} }
else { tempRPM = currentStatus.RPM; } //Can't do per tooth RPM if we're at tooth #1 as the missing tooth messes the calculation else { tempRPM = currentStatus.RPM; } //Can't do per tooth RPM if we're at tooth #1 as the missing tooth messes the calculation
} }