From c9ed48aa6dc1bfe6737526d0a8445c0e4feaafa6 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Fri, 2 Oct 2015 15:52:09 +1000 Subject: [PATCH] Fix error on ignition 3 schedule --- scheduler.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scheduler.ino b/scheduler.ino index 31dcbbf..e25eb17 100644 --- a/scheduler.ino +++ b/scheduler.ino @@ -159,8 +159,8 @@ void setIgnitionSchedule3(void (*startCallback)(), unsigned long timeout, unsign //We need to calculate the value to reset the timer to (preload) in order to achieve the desired overflow time //As the timer is ticking every 16uS (Time per Tick = (Prescale)*(1/Frequency)) //unsigned int absoluteTimeout = TCNT5 + (timeout / 16); //Each tick occurs every 16uS with the 256 prescaler, so divide the timeout by 16 to get ther required number of ticks. Add this to the current tick count to get the target time. This will automatically overflow as required - unsigned int absoluteTimeout = TCNT5 + (timeout >> 4); //As above, but with bit shift instead of / 16 - //unsigned int absoluteTimeout = TCNT5 + (timeout >> 2); //As above, but with bit shift instead of / 16 + //unsigned int absoluteTimeout = TCNT5 + (timeout >> 4); //As above, but with bit shift instead of / 16 + unsigned int absoluteTimeout = TCNT5 + (timeout >> 2); //As above, but with bit shift instead of / 16 OCR5C = absoluteTimeout; ignitionSchedule3.duration = duration; ignitionSchedule3.StartCallback = startCallback; //Name the start callback function @@ -307,7 +307,7 @@ ISR(TIMER5_COMPC_vect, ISR_NOBLOCK) //ignitionSchedule3 ignitionSchedule3.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback) ignitionSchedule3.startTime = currentLoopTime; ignitionSchedule3.StartCallback(); - unsigned int absoluteTimeout = TCNT5 + (ignitionSchedule2.duration >> 2); + unsigned int absoluteTimeout = TCNT5 + (ignitionSchedule3.duration >> 2); ign3LastRev = startRevolutions; OCR5C = absoluteTimeout; }