Fix bug that could cause RPM to spike when first cranking on missing tooth patterns

This commit is contained in:
Josh Stewart 2017-10-24 21:07:22 +11:00
parent 2ec972948f
commit 91bea0766f
5 changed files with 30 additions and 23 deletions

View File

@ -5,14 +5,11 @@ A full copy of the license may be found in the projects root directory
*/
/*
This is called when a command is received over serial from TunerStudio / Megatune
It parses the command and calls the relevant function
A detailed description of each call can be found at: http://www.msextra.com/doc/ms1extra/COM_RS232.htm
Processes the data on the serial buffer.
Can be either a new command or a continuation of one that is already in progress:
* cmdPending = If a command has started but is wairing on further data to complete
* chunkPending = Specifically for the new receive value method where TS will send a known number of contiguous bytes to be written to a table
*/
//#include "comms.h"
//#include "globals.h"
//#include "storage.h"
void command()
{

View File

@ -62,6 +62,7 @@ volatile int triggerToothAngle; //The number of crank degrees that elapse per to
bool secondDerivEnabled; //The use of the 2nd derivative calculation is limited to certain decoders. This is set to either true or false in each decoders setup routine
bool decoderIsSequential; //Whether or not the decoder supports sequential operation
bool decoderIsLowRes = false; //Is set true, certain extra calculations are performed for better timing accuracy
bool decoderHasFixedCrankingTiming = false; //Whether or not the decoder supports fixed cranking timing
byte checkSyncToothCount; //How many teeth must've been seen on this revolution before we try to confirm sync (Useful for missing tooth type decoders)
int16_t ignition1EndTooth = 0;

View File

@ -51,7 +51,8 @@ static inline uint16_t stdGetRPM()
if( currentStatus.hasSync == true )
{
if( (BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK)) && (currentStatus.startRevolutions == 0) ) { tempRPM = 0; } //Prevents crazy RPM spike when there has been less than 1 full revolution
if( (currentStatus.RPM < currentStatus.crankRPM) && (currentStatus.startRevolutions == 0) ) { tempRPM = 0; } //Prevents crazy RPM spike when there has been less than 1 full revolution
else if( (toothOneTime == 0) || (toothOneMinusOneTime == 0) ) { tempRPM = 0; }
else
{
noInterrupts();
@ -88,9 +89,9 @@ It takes an argument of the full (COMPLETE) number of teeth per revolution. For
static inline int crankingGetRPM(byte totalTeeth)
{
uint16_t tempRPM = 0;
if( currentStatus.startRevolutions >= 2 )
if( (currentStatus.startRevolutions >= configPage2.StgCycles) && (currentStatus.hasSync == true) )
{
if( (toothLastToothTime > 0) && (toothLastMinusOneToothTime > 0) )
if( (toothLastToothTime > 0) && (toothLastMinusOneToothTime > 0) && (toothLastToothTime > toothLastMinusOneToothTime) )
{
noInterrupts();
revolutionTime = (toothLastToothTime - toothLastMinusOneToothTime) * totalTeeth;
@ -130,6 +131,10 @@ void triggerSetup_missingTooth()
secondDerivEnabled = false;
decoderIsSequential = false;
checkSyncToothCount = (configPage2.triggerTeeth) >> 1; //50% of the total teeth.
toothLastMinusOneToothTime = 0;
toothCurrentCount = 0;
toothOneTime = 0;
toothOneMinusOneTime = 0;
MAX_STALL_TIME = (3333UL * triggerToothAngle * (configPage2.triggerMissingTeeth + 1)); //Minimum 50rpm. (3333uS is the time per degree at 50rpm)
}
@ -150,6 +155,8 @@ void triggerPri_missingTooth()
if(configPage2.triggerMissingTeeth == 1) { targetGap = (3 * (toothLastToothTime - toothLastMinusOneToothTime)) >> 1; } //Multiply by 1.5 (Checks for a gap 1.5x greater than the last one) (Uses bitshift to multiply by 3 then divide by 2. Much faster than multiplying by 1.5)
else { targetGap = ((toothLastToothTime - toothLastMinusOneToothTime)) * 2; } //Multiply by 2 (Checks for a gap 2x greater than the last one)
if( (toothLastToothTime == 0) || (toothLastMinusOneToothTime == 0) ) { curGap = 0; }
if ( (curGap > targetGap) || (toothCurrentCount > triggerActualTeeth) )
{
if(toothCurrentCount < (triggerActualTeeth) && (currentStatus.hasSync == true) ) { currentStatus.hasSync = false; } //This occurs when we're at tooth #1, but haven't seen all the other teeth. This indicates a signal issue so we flag lost sync so this will attempt to resync on the next revolution.
@ -195,10 +202,14 @@ void triggerSec_missingTooth()
uint16_t getRPM_missingTooth()
{
uint16_t tempRPM = 0;
if( (currentStatus.RPM < currentStatus.crankRPM) && (toothCurrentCount != 1) ) //Can't do per tooth RPM if we're at tooth #1 as the missing tooth messes the calculation
if( (currentStatus.RPM < currentStatus.crankRPM) )
{
if(configPage2.TrigSpeed == 1) { crankingGetRPM(configPage2.triggerTeeth/2); } //Account for cam speed
else { tempRPM = crankingGetRPM(configPage2.triggerTeeth); }
if(toothCurrentCount != 1)
{
if(configPage2.TrigSpeed == 1) { tempRPM = crankingGetRPM(configPage2.triggerTeeth/2); } //Account for cam speed
else { tempRPM = crankingGetRPM(configPage2.triggerTeeth); }
}
else { tempRPM = currentStatus.RPM; } //Can't do per tooth RPM if we're at tooth #1 as the missing tooth messes the calculation
}
else
{
@ -425,7 +436,7 @@ void triggerSetup_BasicDistributor()
secondDerivEnabled = false;
decoderIsSequential = false;
toothCurrentCount = 0; //Default value
decoderHasFixedCrankingTiming = true;
if(configPage1.nCylinders <= 4) { MAX_STALL_TIME = (1851UL * triggerToothAngle); }//Minimum 90rpm. (1851uS is the time per degree at 90rpm). This uses 90rpm rather than 50rpm due to the potentially very high stall time on a 4 cylinder if we wait that long.
else { MAX_STALL_TIME = (3200UL * triggerToothAngle); } //Minimum 50rpm. (3200uS is the time per degree at 50rpm).
@ -636,6 +647,7 @@ void triggerSetup_4G63()
toothCurrentCount = 99; //Fake tooth count represents no sync
secondDerivEnabled = false;
decoderIsSequential = true;
decoderHasFixedCrankingTiming = true;
MAX_STALL_TIME = 366667UL; //Minimum 50rpm based on the 110 degree tooth spacing
if(initialisationComplete == false) { toothLastToothTime = micros(); } //Set a startup value here to avoid filter errors when starting. This MUST have the initi check to prevent the fuel pump just staying on all the time
//decoderIsLowRes = true;
@ -1395,6 +1407,7 @@ void triggerSetup_Miata9905()
MAX_STALL_TIME = (3333UL * triggerToothAngle); //Minimum 50rpm. (3333uS is the time per degree at 50rpm)
triggerFilterTime = 1500; //10000 rpm, assuming we're triggering on both edges off the crank tooth.
triggerSecFilterTime = 0; //Need to figure out something better for this
decoderHasFixedCrankingTiming = true;
}
void triggerPri_Miata9905()
@ -1570,6 +1583,7 @@ void triggerSetup_MazdaAU()
MAX_STALL_TIME = (3333UL * triggerToothAngle); //Minimum 50rpm. (3333uS is the time per degree at 50rpm)
triggerFilterTime = 1500; //10000 rpm, assuming we're triggering on both edges off the crank tooth.
triggerSecFilterTime = (int)(1000000 / (MAX_RPM / 60 * 2)) / 2; //Same as above, but fixed at 2 teeth on the secondary input and divided by 2 (for cam speed)
decoderHasFixedCrankingTiming = true;
}
void triggerPri_MazdaAU()

View File

@ -64,7 +64,7 @@
#define BIT_ENGINE_MAPDCC 7 // MAP decelleration mode
//Define masks for Status1
#define BIT_STATUS1_INJ1 0 //inj1
#define BIT_STATUS1_INJ1 0 //inj1
#define BIT_STATUS1_INJ2 1 //inj2
#define BIT_STATUS1_INJ3 2 //inj3
#define BIT_STATUS1_INJ4 3 //inj4
@ -132,6 +132,7 @@
#define ODD_FIRE 1
#define MAX_RPM 18000 //This is the maximum rpm that the ECU will attempt to run at. It is NOT related to the rev limiter, but is instead dictates how fast certain operations will be allowed to run. Lower number gives better performance
#define engineSquirtsPerCycle 2 //Would be 1 for a 2 stroke
//Table sizes
#define CALIBRATION_TABLE_SIZE 512

View File

@ -17,13 +17,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//**************************************************************************************************
// Config section
#define engineSquirtsPerCycle 2 //Would be 1 for a 2 stroke
//**************************************************************************************************
//https://developer.mbed.org/handbook/C-Data-Types
#include <stdint.h>
#include <stdint.h> //https://developer.mbed.org/handbook/C-Data-Types
//************************************************
#include "speeduino.h"
#include "globals.h"
@ -1320,7 +1314,7 @@ void loop()
//Likewise for the ignition
//fixedCrankingOverride is used to extend the dwell during cranking so that the decoder can trigger the spark upon seeing a certain tooth. Currently only available on the basic distributor and 4g63 decoders.
if ( configPage2.ignCranklock && BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK)) { fixedCrankingOverride = currentStatus.dwell * 3; }
if ( configPage2.ignCranklock && BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK) && (decoderHasFixedCrankingTiming == true) ) { fixedCrankingOverride = currentStatus.dwell * 3; }
else { fixedCrankingOverride = 0; }
//Perform an initial check to see if the ignition is turned on (Ignition only turns on after a preset number of cranking revolutions and: