Seemingly working TunerStudio tooth logger

This commit is contained in:
Josh Stewart 2014-10-03 14:19:37 +10:00
parent 13f0b78e1d
commit 8a5888edc3
3 changed files with 47 additions and 31 deletions

View File

@ -93,32 +93,24 @@ void command()
Serial.flush();
break;
case 'T': //Totally non-standard testing function. Will be removed once calibration testing is completed.
unsigned long tempToothHistory[256];
byte tempToothHistoryIndex;
case 'T': //Send 256 tooth log entries to TunerStudio
while(1)
{
tempToothHistoryIndex = toothHistoryIndex;
//We need 256 records to send to TunerStudio. If there aren't that many in the buffer (Buffer is 512 long) then we just return and wait for the next call
//if (toothHistoryIndex < 256) { return; } //Don't believe this is the best way to go. Just display whatever is in the buffer
for(byte x=0; x<tempToothHistoryIndex; x++)
{
tempToothHistory[x] = toothHistory[x];
}
//Catch any remaining ones that triggered whilst the above loop was running
for(byte x=tempToothHistoryIndex; x<toothHistoryIndex; x++)
{
tempToothHistory[x] = toothHistory[x];
tempToothHistoryIndex++;
}
int tempToothHistory[512]; //Create a temporary array that will contain a copy of what is in the main toothHistory array
//Copy the working history into the temporary buffer array. This is done so that, if the history loops whilst the values are being sent over serial, it doesn't affect the values
memcpy( (void*)tempToothHistory, (void*)toothHistory, sizeof(tempToothHistory) );
toothHistoryIndex = 0; //Reset the history index
for(byte x=0; x<tempToothHistoryIndex; x++)
//Loop only needs to go to 256 (Even though the buffer is 512 long) as we only ever send 256 entries at a time
for(int x=0; x<256; x++)
{
Serial.println(tempToothHistory[x]);
Serial.write(highByte(tempToothHistory[x]));
Serial.write(lowByte(tempToothHistory[x]));
}
Serial.flush();
}
break;
default:

View File

@ -165,7 +165,7 @@
TrigAng = scalar, U08, 80, "Deg", 4, 0, 0, 360, 0
FixAng = scalar, U08, 81, "Deg", 0.352, -28.4, -10, 80, 0
Trim = scalar, S08, 82, "Deg", 0.352, 0, -45, 45, 0
CrankAng = scalar, U08, 83, "Deg", 0.352, -28.4, -10, 80, 0
CrankAng = scalar, U08, 83, "Deg", 1, -28.4, -10, 80, 0
IgHold = scalar, U08, 84, "", 1, 0, 0, 100, 0
Trig_plus = bits, U08, 85[0:1], "0", "+22.5", "INVALID", "+45"
TrigCrank = bits, U08, 85[2:2], "Trigger Return", "Time Based"
@ -880,3 +880,21 @@ help = helpEnrichments, "Enrichments Help"
entry = blank1, "tpsMin", int, "%d"
entry = blank2, "tpsMax", int, "%d"
entry = TPSdot, "TPS DOT", int, "%d"
[LoggerDefinition]
; valid logger types: composite, tooth, trigger, csv
;loggerDef = uniqueName, Display Name, type
loggerDef = tooth, "Tooth Logger", tooth
;dataReadCommand = "r\\x00\\xf4\\x00\\x00\\x04\\x00" ; standard TS command format
dataReadCommand = "T" ; Basic TS command format
dataReadTimeout = 10000 ; time in ms
;dataReadyCondition = { ( status3 & 0x02 ) == 0x02 }
;dataLength = 1024 ; in bytes, including headers, footers and data (not used)
;recordDef = headerLen. footerLen, recordLen
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, 8, 1.0, "uS"

View File

@ -36,8 +36,8 @@ volatile unsigned long toothLastToothTime = 0; //The time (micros()) that the la
volatile unsigned long toothLastMinusOneToothTime = 0; //The time (micros()) that the tooth before the last tooth was registered
volatile unsigned long toothOneTime = 0; //The time (micros()) that tooth 1 last triggered
volatile unsigned long toothOneMinusOneTime = 0; //The 2nd to last time (micros()) that tooth 1 last triggered
volatile unsigned long toothHistory[256];
volatile byte toothHistoryIndex = 0;
volatile int toothHistory[512];
volatile int toothHistoryIndex = 0;
volatile byte startRevolutions = 0; //A counter for how many revolutions have been completed since sync was achieved.
volatile bool ignitionOn = true; //The current state of the ignition system
@ -311,7 +311,7 @@ void loop()
//Determine the current crank angle
//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 + (int)(configPage2.triggerAngle*4); //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. Needs to be multipled by 4 as the trigger angle is divided by 4 for the serial protocol
int crankAngle = (toothCurrentCount - 1) * triggerToothAngle + ((int)(configPage2.triggerAngle)*4); //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. Needs to be multipled by 4 as the trigger angle is divided by 4 for the serial protocol
if (crankAngle > 360) { crankAngle -= 360; }
//How fast are we going? Need to know how long (uS) it will take to get from one tooth to the next. We then use that to estimate how far we are between the last tooth and the next one
@ -422,15 +422,21 @@ void trigger()
noInterrupts(); //Turn off interrupts whilst in this routine
volatile unsigned long curTime = micros();
if ( (curTime - toothLastToothTime) < triggerFilterTime) { interrupts(); return; } //Debounce check. Pulses should never be less than triggerFilterTime, so if they are it means a false trigger. (A 36-1 wheel at 8000pm will have triggers approx. every 200uS)
volatile int curGap = curTime - toothLastToothTime;
if ( curGap < triggerFilterTime) { interrupts(); return; } //Debounce check. Pulses should never be less than triggerFilterTime, so if they are it means a false trigger. (A 36-1 wheel at 8000pm will have triggers approx. every 200uS)
toothCurrentCount++; //Increment the tooth counter
toothHistory[toothHistoryIndex] = curTime;
toothHistoryIndex++;
//High speed tooth logging history
toothHistory[toothHistoryIndex] = curGap;
if(toothHistoryIndex == 511)
{ toothHistoryIndex = 0; }
else
{ toothHistoryIndex++; }
//Begin the missing tooth detection
//If the time between the current tooth and the last is greater than 1.5x the time between the last tooth and the tooth before that, we make the assertion that we must be at the first tooth after the gap
//if ( (curTime - toothLastToothTime) > (1.5 * (toothLastToothTime - toothLastMinusOneToothTime))) { toothCurrentCount = 1; }
if ( (curTime - toothLastToothTime) > ((3 * (toothLastToothTime - toothLastMinusOneToothTime))>>1)) //Same as above, but uses bitshift instead of multiplying by 1.5
if ( curGap > ((3 * (toothLastToothTime - toothLastMinusOneToothTime))>>1)) //Same as above, but uses bitshift instead of multiplying by 1.5
{
toothCurrentCount = 1;
toothOneMinusOneTime = toothOneTime;