From 95104451bdb1ad81f0269d3a46f9432b26abb917 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Sun, 13 Sep 2015 21:16:30 +1000 Subject: [PATCH] Filter improvements --- decoders.h | 2 +- decoders.ino | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/decoders.h b/decoders.h index 25b81d0..83cd74a 100644 --- a/decoders.h +++ b/decoders.h @@ -20,7 +20,7 @@ volatile byte secondaryToothCount; //Used for identifying the current secondary volatile unsigned long secondaryLastToothTime = 0; //The time (micros()) that the last tooth was registered (Cam input) volatile int triggerActualTeeth; -unsigned int triggerFilterTime; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering) +volatile unsigned long triggerFilterTime; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering) unsigned int triggerSecFilterTime; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering) for the secondary input unsigned int triggerToothAngle; //The number of crank degrees that elapse per tooth unsigned long revolutionTime; //The time in uS that one revolution would take at current speed (The time tooth 1 was last seen, minus the time it was seen prior to that) diff --git a/decoders.ino b/decoders.ino index 69c04ea..1a58959 100644 --- a/decoders.ino +++ b/decoders.ino @@ -352,11 +352,12 @@ void triggerSetup_4G63() toothAngles[1] = 105; //Rising edge of tooth #2 toothAngles[2] = 175; //Falling edge of tooth #2 toothAngles[3] = 285; //Rising edge of tooth #1 - + /* toothAngles[0] = 105; //Falling edge of tooth #1 toothAngles[1] = 175; //Rising edge of tooth #2 toothAngles[2] = 285; //Falling edge of tooth #2 toothAngles[3] = 355; //Rising edge of tooth #1 + */ 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) @@ -394,14 +395,15 @@ void triggerSec_4G63() { curTime2 = micros(); curGap2 = curTime2 - toothLastSecToothTime; - if ( curGap2 < triggerSecFilterTime ) { return; } + //if ( curGap2 < triggerSecFilterTime ) { return; } toothLastSecToothTime = curTime2; if(!currentStatus.hasSync) { //Check the status of the crank trigger bool crank = digitalRead(pinTrigger); - if(crank == HIGH) { toothCurrentCount = 0; } //If the crank trigger is currently HIGH, it means we're on tooth #1 + triggerFilterTime = 1; + if(crank == HIGH) { toothCurrentCount = 4; } //If the crank trigger is currently HIGH, it means we're on tooth #1 } return; } @@ -411,7 +413,8 @@ int getRPM_4G63() { noInterrupts(); revolutionTime = (toothOneTime - toothOneMinusOneTime); //The time in uS that one revolution would take at current speed (The time tooth 1 was last seen, minus the time it was seen prior to that) - interrupts(); + interrupts(); + triggerFilterTime = revolutionTime >> 5; return ldiv(US_IN_MINUTE, revolutionTime).quot; //Calc RPM based on last full revolution time (uses ldiv rather than div as US_IN_MINUTE is a long) } int getCrankAngle_4G63(int timePerDegree)