From c7a5f0b4f78b80f28d8098931cc2c444319443cc Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Tue, 10 Feb 2015 00:04:03 +1100 Subject: [PATCH] Begin to track spark start times. Needed for overdwell protection --- scheduler.h | 1 + scheduler.ino | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/scheduler.h b/scheduler.h index 051bdbef..e33c071d 100644 --- a/scheduler.h +++ b/scheduler.h @@ -43,6 +43,7 @@ struct Schedule { volatile ScheduleStatus Status; void (*StartCallback)(); //Start Callback function for schedule void (*EndCallback)(); //Start Callback function for schedule + unsigned long startTime; }; Schedule fuelSchedule1; diff --git a/scheduler.ino b/scheduler.ino index 2297dcc7..5a208892 100644 --- a/scheduler.ino +++ b/scheduler.ino @@ -255,6 +255,7 @@ ISR(TIMER5_COMPA_vect) //ignitionSchedule1 if (ignitionSchedule1.Status == PENDING) //Check to see if this schedule is turn on { ignitionSchedule1.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback) + ignitionSchedule1.startTime = currentLoopTime; ignitionSchedule1.StartCallback(); //unsigned int absoluteTimeout = TCNT5 + (ignitionSchedule1.duration / 4); unsigned int absoluteTimeout = TCNT5 + (ignitionSchedule1.duration >> 2); //Divide by 4 @@ -273,6 +274,7 @@ ISR(TIMER5_COMPB_vect) //ignitionSchedule2 if (ignitionSchedule2.Status == PENDING) //Check to see if this schedule is turn on { ignitionSchedule2.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback) + ignitionSchedule2.startTime = currentLoopTime; ignitionSchedule2.StartCallback(); //unsigned int absoluteTimeout = TCNT5 + (ignitionSchedule2.duration / 4); unsigned int absoluteTimeout = TCNT5 + (ignitionSchedule2.duration >> 2); //Divide by 4 @@ -291,8 +293,9 @@ ISR(TIMER5_COMPC_vect) //ignitionSchedule3 noInterrupts(); if (ignitionSchedule3.Status == PENDING) //Check to see if this schedule is turn on { - ignitionSchedule3.StartCallback(); 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 / 4); unsigned int absoluteTimeout = TCNT5 + (ignitionSchedule3.duration >> 2); //Divide by 4 OCR5C = absoluteTimeout; @@ -311,8 +314,9 @@ ISR(TIMER4_COMPA_vect) //ignitionSchedule4 noInterrupts(); if (ignitionSchedule4.Status == PENDING) //Check to see if this schedule is turn on { - ignitionSchedule4.StartCallback(); ignitionSchedule4.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback) + ignitionSchedule4.startTime = currentLoopTime; + ignitionSchedule4.StartCallback(); //unsigned int absoluteTimeout = TCNT5 + (ignitionSchedule2.duration / 16); unsigned int absoluteTimeout = TCNT4 + (ignitionSchedule4.duration >> 4); //Divide by 16 OCR4A = absoluteTimeout;