From 5cd8b6852ece3128497e37c50191f74ac34e4013 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Mon, 26 Oct 2015 06:21:12 +1100 Subject: [PATCH] Improvements to tooth logger --- comms.ino | 7 +++--- decoders.ino | 63 ++++++++++++++++------------------------------------ globals.h | 3 +++ 3 files changed, 25 insertions(+), 48 deletions(-) diff --git a/comms.ino b/comms.ino index 0a28cc7d..06d73461 100644 --- a/comms.ino +++ b/comms.ino @@ -822,7 +822,7 @@ void sendToothLog(bool useChar) { //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 < 255) { + if (toothHistoryIndex < TOOTH_LOG_SIZE) { return; //This should no longer ever occur } unsigned int tempToothHistory[512]; //Create a temporary array that will contain a copy of what is in the main toothHistory array @@ -834,21 +834,20 @@ void sendToothLog(bool useChar) //Loop only needs to go to 256 (Even though the buffer is 512 long) as we only ever send 256 entries at a time if (useChar) { - for (int x = 0; x < 256; x++) + for (int x = 0; x < TOOTH_LOG_SIZE; x++) { Serial.println(tempToothHistory[x]); } } else { - for (int x = 0; x < 256; x++) + for (int x = 0; x < TOOTH_LOG_SIZE; x++) { Serial.write(highByte(tempToothHistory[x])); Serial.write(lowByte(tempToothHistory[x])); } BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_TOOTHLOG1READY); } - //Serial.flush(); } diff --git a/decoders.ino b/decoders.ino index 6581c827..617dd8c6 100644 --- a/decoders.ino +++ b/decoders.ino @@ -21,6 +21,16 @@ toothLastToothTime - The time (In uS) that the last primary tooth was 'seen' */ +inline void addToothLogEntry(unsigned long time) +{ + //High speed tooth logging history + toothHistory[toothHistoryIndex] = curGap; + if(toothHistoryIndex == 511) + { toothHistoryIndex = 0; BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_TOOTHLOG1READY); } //The tooth log ready bit is cleared to ensure that we only get a true 255 values, all concurrent. + else + { toothHistoryIndex++; } +} + /* Name: Missing tooth wheel Desc: A multi-tooth wheel with one of more 'missing' teeth. The first tooth after the missing one is considered number 1 and isthe basis for the trigger angle @@ -43,12 +53,7 @@ void triggerPri_missingTooth() if ( curGap < triggerFilterTime ) { 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 - //High speed tooth logging history - toothHistory[toothHistoryIndex] = curGap; - if(toothHistoryIndex == 511) - { toothHistoryIndex = 0; } - else - { toothHistoryIndex++; } + addToothLogEntry(curGap); //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 @@ -128,12 +133,7 @@ void triggerPri_DualWheel() if ((startRevolutions & 63) == 1) { currentStatus.hasSync = false; } //Every 64 revolutions, force a resync with the cam } - //High speed tooth logging history - toothHistory[toothHistoryIndex] = curGap; - if(toothHistoryIndex == 511) - { toothHistoryIndex = 0; BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_TOOTHLOG1READY); } //The tooth log ready bit is cleared to ensure that we only get a true 255 values, all concurrent. - else - { toothHistoryIndex++; } + addToothLogEntry(curGap); toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; @@ -212,15 +212,10 @@ void triggerPri_BasicDistributor() } else { toothCurrentCount++; } //Increment the tooth counter - //High speed tooth logging history - toothHistory[toothHistoryIndex] = curGap; - if(toothHistoryIndex == 511) - { toothHistoryIndex = 0; BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_TOOTHLOG1READY); } //The tooth log ready bit is cleared to ensure that we only get a true 255 values, all concurrent. - else - { toothHistoryIndex++; } + addToothLogEntry(curGap); - toothLastMinusOneToothTime = toothLastToothTime; - toothLastToothTime = curTime; + toothLastMinusOneToothTime = toothLastToothTime; + toothLastToothTime = curTime; } void triggerSec_BasicDistributor() { return; } //Not required int getRPM_BasicDistributor() @@ -265,12 +260,7 @@ void triggerPri_GM7X() curGap = curTime - toothLastToothTime; toothCurrentCount++; //Increment the tooth counter - //High speed tooth logging history - toothHistory[toothHistoryIndex] = curGap; - if(toothHistoryIndex == 511) - { toothHistoryIndex = 0; BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_TOOTHLOG1READY); } //The tooth log ready bit is cleared to ensure that we only get a true 255 values, all concurrent. - else - { toothHistoryIndex++; } + addToothLogEntry(curGap); // if( toothCurrentCount > 7 ) @@ -382,12 +372,7 @@ void triggerPri_4G63() else if (!currentStatus.hasSync) { return; } else { toothCurrentCount++; } - //High speed tooth logging history - toothHistory[toothHistoryIndex] = curGap; - if(toothHistoryIndex == 511) - { toothHistoryIndex = 0; BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_TOOTHLOG1READY); } //The tooth log ready bit is cleared to ensure that we only get a true 255 values, all concurrent. - else - { toothHistoryIndex++; } + addToothLogEntry(curGap); toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; @@ -494,12 +479,7 @@ void triggerPri_24X() toothCurrentCount++; //Increment the tooth counter } - //High speed tooth logging history - toothHistory[toothHistoryIndex] = curGap; - if(toothHistoryIndex == 511) - { toothHistoryIndex = 0; BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_TOOTHLOG1READY); } //The tooth log ready bit is cleared to ensure that we only get a true 255 values, all concurrent. - else - { toothHistoryIndex++; } + addToothLogEntry(curGap); toothLastToothTime = curTime; } @@ -581,12 +561,7 @@ void triggerPri_Jeep2000() toothCurrentCount++; //Increment the tooth counter } - //High speed tooth logging history - toothHistory[toothHistoryIndex] = curGap; - if(toothHistoryIndex == 511) - { toothHistoryIndex = 0; BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_TOOTHLOG1READY); } //The tooth log ready bit is cleared to ensure that we only get a true 255 values, all concurrent. - else - { toothHistoryIndex++; } + addToothLogEntry(curGap); toothLastToothTime = curTime; } diff --git a/globals.h b/globals.h index 9032691f..7c4e91a6 100644 --- a/globals.h +++ b/globals.h @@ -33,6 +33,9 @@ const int map_page_size = 288; #define BIT_SQUIRT_TOOTHLOG1READY 6 //Used to flag if tooth log 1 is ready #define BIT_SQUIRT_TOOTHLOG2READY 7 //Used to flag if tooth log 2 is ready (Log is not currently used) +#define TOOTH_LOG_SIZE 256 +#define TOOTH_LOG_BUFFER 512 + #define SIZE_BYTE 8 #define SIZE_INT 16