From d306e8aee7a4e845103367352131b40269f8d42a Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Mon, 7 Jul 2014 22:48:50 +1000 Subject: [PATCH] Tweak trigger filter time to better value for 36-1 --- scheduler.ino | 12 ++++++++++++ speeduino.ino | 5 +++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/scheduler.ino b/scheduler.ino index 853670c..8136b10 100644 --- a/scheduler.ino +++ b/scheduler.ino @@ -212,6 +212,7 @@ ISR(TIMER3_COMPB_vect) //fuelSchedule2 } ISR(TIMER3_COMPC_vect) //fuelSchedule3 { + noInterrupts(); if (fuelSchedule3.Status == PENDING) //Check to see if this schedule is turn on { fuelSchedule3.StartCallback(); @@ -226,9 +227,11 @@ ISR(TIMER3_COMPC_vect) //fuelSchedule3 fuelSchedule3.Status = OFF; //Turn off the schedule TIMSK3 &= ~(1 << OCIE3C); //Turn off this output compare unit (This simply writes 0 to the OCIE3A bit of TIMSK3) } + interrupts(); } ISR(TIMER4_COMPB_vect) //fuelSchedule4 { + noInterrupts(); if (fuelSchedule4.Status == PENDING) //Check to see if this schedule is turn on { fuelSchedule4.StartCallback(); @@ -243,9 +246,11 @@ ISR(TIMER4_COMPB_vect) //fuelSchedule4 fuelSchedule4.Status = OFF; //Turn off the schedule TIMSK4 &= ~(1 << OCIE4B); //Turn off this output compare unit (This simply writes 0 to the OCIE3A bit of TIMSK3) } + interrupts(); } ISR(TIMER5_COMPA_vect) //ignitionSchedule1 { + noInterrupts(); if (ignitionSchedule1.Status == PENDING) //Check to see if this schedule is turn on { ignitionSchedule1.StartCallback(); @@ -260,9 +265,11 @@ ISR(TIMER5_COMPA_vect) //ignitionSchedule1 ignitionSchedule1.Status = OFF; //Turn off the schedule TIMSK5 &= ~(1 << OCIE5A); //Turn off this output compare unit (This simply writes 0 to the OCIE3A bit of TIMSK3) } + interrupts(); } ISR(TIMER5_COMPB_vect) //ignitionSchedule2 { + noInterrupts(); if (ignitionSchedule2.Status == PENDING) //Check to see if this schedule is turn on { ignitionSchedule2.StartCallback(); @@ -277,9 +284,11 @@ ISR(TIMER5_COMPB_vect) //ignitionSchedule2 ignitionSchedule2.Status = OFF; //Turn off the schedule TIMSK5 &= ~(1 << OCIE5B); //Turn off this output compare unit (This simply writes 0 to the OCIE3A bit of TIMSK3) } + interrupts(); } ISR(TIMER5_COMPC_vect) //ignitionSchedule3 { + noInterrupts(); if (ignitionSchedule3.Status == PENDING) //Check to see if this schedule is turn on { ignitionSchedule3.StartCallback(); @@ -294,9 +303,11 @@ ISR(TIMER5_COMPC_vect) //ignitionSchedule3 ignitionSchedule3.Status = OFF; //Turn off the schedule TIMSK5 &= ~(1 << OCIE5C); //Turn off this output compare unit (This simply writes 0 to the OCIE3A bit of TIMSK3) } + interrupts(); } ISR(TIMER4_COMPA_vect) //ignitionSchedule4 { + noInterrupts(); if (ignitionSchedule4.Status == PENDING) //Check to see if this schedule is turn on { ignitionSchedule4.StartCallback(); @@ -311,4 +322,5 @@ ISR(TIMER4_COMPA_vect) //ignitionSchedule4 ignitionSchedule4.Status = OFF; //Turn off the schedule TIMSK5 &= ~(1 << OCIE4A); //Turn off this output compare unit (This simply writes 0 to the OCIE3A bit of TIMSK3) } + interrupts(); } diff --git a/speeduino.ino b/speeduino.ino index 7e66751..60e19aa 100644 --- a/speeduino.ino +++ b/speeduino.ino @@ -44,7 +44,7 @@ struct config2 configPage2; int req_fuel_uS, triggerToothAngle; volatile int triggerActualTeeth; -unsigned int triggerFilterTime = 500; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering) +unsigned int triggerFilterTime = 200; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering) volatile int toothCurrentCount = 0; //The current number of teeth (Onec sync has been achieved, this can never actually be 0 volatile unsigned long toothLastToothTime = 0; //The time (micros()) that the last tooth was registered @@ -316,7 +316,8 @@ void loop() //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 int timePerDegree = ldiv( (toothOneTime - toothOneMinusOneTime) , 360).quot; //The time (uS) it is currently taking to move 1 degree - crankAngle += div( (int)(micros() - toothLastToothTime), timePerDegree).quot; //Estimate the number of degrees travelled since the last tooth + //crankAngle += div( (int)(micros() - toothLastToothTime), timePerDegree).quot; //Estimate the number of degrees travelled since the last tooth + crankAngle += ldiv( (micros() - toothLastToothTime), timePerDegree).quot; //Estimate the number of degrees travelled since the last tooth //Determine next firing angles //1