Consistency improvements to Audi135 and 4G63 decoders

This commit is contained in:
Josh Stewart 2017-03-01 10:30:23 +11:00
parent 707d65cac8
commit 26a6945856
2 changed files with 36 additions and 10 deletions

View File

@ -3,10 +3,12 @@
#include <limits.h>
static inline void addToothLogEntry(unsigned long toothTime);
#define READ_PRI_TRIGGER() (*triggerPri_pin_port & (1 << triggerPri_pin_mask) ? HIGH : LOW)
static inline void addToothLogEntry(unsigned long);
static inline int stdGetRPM();
static inline void setFilter(unsigned long curGap);
static inline int crankingGetRPM(byte totalTeeth);
static inline void setFilter(unsigned long);
static inline int crankingGetRPM(byte);
void triggerSetup_missingTooth();
void triggerPri_missingTooth();
void triggerSec_missingTooth();
@ -18,14 +20,14 @@ void triggerSec_DualWheel();
int getRPM_DualWheel();
int getCrankAngle_DualWheel(int timePerDegree);
unsigned long MAX_STALL_TIME = 500000UL; //The maximum time (in uS) that the system will continue to function before the engine is considered stalled/stopped. This is unique to each decoder, depending on the number of teeth etc. 500000 (half a second) is used as the default value, most decoders will be much less.
unsigned long MAX_STALL_TIME = 500000UL; //The maximum time (in uS) that the system will continue to function before the engine is considered stalled/stopped. This is unique to each decoder, depending on the number of teeth etc. 500000 (half a second) is used as the default value, most decoders will be much less.
volatile unsigned long curTime;
volatile unsigned long curGap;
volatile unsigned long curTime2;
volatile unsigned long curGap2;
volatile unsigned long lastGap;
volatile unsigned long targetGap;
volatile unsigned long targetGap;
volatile int toothCurrentCount = 0; //The current number of teeth (Onec sync has been achieved, this can never actually be 0
volatile byte toothSystemCount = 0; //Used for decoders such as Audi 135 where not every tooth is used for calculating crank angle. This variable stores the actual number of teeth, not the number being used to calculate crank angle

View File

@ -519,7 +519,7 @@ void triggerPri_4G63()
toothLastToothTime = curTime;
toothCurrentCount++;
if(toothCurrentCount == 1 || toothCurrentCount == 5) //Trigger is on CHANGE, hence 4 pulses = 1 crank rev
if(toothCurrentCount == 1 || toothCurrentCount > 4) //Trigger is on CHANGE, hence 4 pulses = 1 crank rev
{
toothCurrentCount = 1; //Reset the counter
toothOneMinusOneTime = toothOneTime;
@ -560,6 +560,7 @@ void triggerPri_4G63()
}
void triggerSec_4G63()
{
//byte crankState = READ_PRI_TRIGGER();
curTime2 = micros();
curGap2 = curTime2 - toothLastSecToothTime;
if ( curGap2 < triggerSecFilterTime ) { return; }
@ -571,7 +572,7 @@ void triggerSec_4G63()
//Check the status of the crank trigger
bool crank = digitalRead(pinTrigger);
if(crank == HIGH)
if(crank)
{
toothCurrentCount = 4; //If the crank trigger is currently HIGH, it means we're on tooth #1
/* High-res mode
@ -581,6 +582,19 @@ void triggerSec_4G63()
*/
}
}
/*
else
{
//triggerSecFilterTime = curGap2 >> 1; //Only set the filter when we have sync
//if(toothCurrentCount != 2)
{
if(crankState)// && (crankState == digitalRead(pinTrigger)))
{
toothCurrentCount = 4; //If the crank trigger is currently HIGH, it means we're on tooth #1
}
}
}
*/
//else { triggerFilterTime = 1500; } //reset filter time (ugly)
return;
}
@ -865,6 +879,7 @@ void triggerPri_Audi135()
toothCurrentCount = 1;
toothOneMinusOneTime = toothOneTime;
toothOneTime = curTime;
revolutionOne = !revolutionOne;
currentStatus.startRevolutions++; //Counter
}
@ -887,6 +902,10 @@ void triggerSec_Audi135()
currentStatus.hasSync = true;
toothSystemCount = 3; //Need to set this to 3 so that the next primary tooth is counted
}
else{
toothCurrentCount = 0;
}
revolutionOne = 1; //Sequential revolution reset
}
int getRPM_Audi135()
@ -896,13 +915,15 @@ int getRPM_Audi135()
int getCrankAngle_Audi135(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)
//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)
unsigned long tempToothLastToothTime;
int tempToothCurrentCount;
bool tempRevolutionOne;
//Grab some variables that are used in the trigger code and assign them to temp variables.
noInterrupts();
tempToothCurrentCount = toothCurrentCount;
tempToothLastToothTime = toothLastToothTime;
tempRevolutionOne = revolutionOne;
interrupts();
//Handle case where the secondary tooth was the last one seen
@ -914,9 +935,12 @@ int getCrankAngle_Audi135(int timePerDegree)
if(elapsedTime < SHRT_MAX ) { crankAngle += div((int)elapsedTime, timePerDegree).quot; } //This option is much faster, but only available for smaller values of elapsedTime
else { crankAngle += ldiv(elapsedTime, timePerDegree).quot; }
//Sequential check (simply sets whether we're on the first or 2nd revoltuion of the cycle)
if (tempRevolutionOne) { crankAngle += 360; }
if (crankAngle >= 720) { crankAngle -= 720; }
if (crankAngle > CRANK_ANGLE_MAX) { crankAngle -= CRANK_ANGLE_MAX; }
if (crankAngle < 0) { crankAngle += 360; }
else if (crankAngle > CRANK_ANGLE_MAX) { crankAngle -= CRANK_ANGLE_MAX; }
if (crankAngle < 0) { crankAngle += CRANK_ANGLE_MAX; }
return crankAngle;
}