Revert ignition schedules to high precision

This commit is contained in:
Josh Stewart 2015-08-29 21:16:03 +10:00
parent 7c74df590a
commit b22be1aa86
1 changed files with 8 additions and 7 deletions

View File

@ -27,8 +27,8 @@ void initialiseSchedulers()
TCNT5 = 0; //Reset Timer Count
TIFR5 = 0x00; //Timer5 INT Flag Reg: Clear Timer Overflow Flag
TCCR5A = 0x00; //Timer5 Control Reg A: Wave Gen Mode normal
TCCR5B = (1 << CS12); //Timer5 Control Reg B: Timer Prescaler set to 256. Refer to http://www.instructables.com/files/orig/F3T/TIKL/H3WSA4V7/F3TTIKLH3WSA4V7.jpg
//TCCR5B = 0x03; //Reverting this for now due to issue with low RPM overflow
//TCCR5B = (1 << CS12); //Timer5 Control Reg B: Timer Prescaler set to 256. Refer to http://www.instructables.com/files/orig/F3T/TIKL/H3WSA4V7/F3TTIKLH3WSA4V7.jpg
TCCR5B = 0x03; //Reverting this for now due to issue with low RPM overflow
ignitionSchedule1.Status = OFF;
ignitionSchedule2.Status = OFF;
ignitionSchedule3.Status = OFF;
@ -105,7 +105,8 @@ void setFuelSchedule4(void (*startCallback)(), unsigned long timeout, unsigned l
//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 = TCNT3 + (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 = TCNT4 + (timeout >> 4); //As above, but with bit shift instead of / 16
//unsigned int absoluteTimeout = TCNT4 + (timeout >> 4); //As above, but with bit shift instead of / 16
unsigned int absoluteTimeout = TCNT4 + (timeout >> 2); //As above, but with bit shift instead of / 16
OCR4B = absoluteTimeout; //Use the B compare unit of timer 4
fuelSchedule4.duration = duration;
fuelSchedule4.StartCallback = startCallback; //Name the start callback function
@ -124,8 +125,8 @@ void setIgnitionSchedule1(void (*startCallback)(), unsigned long timeout, unsign
//unsigned char sreg;
//sreg = SREG;
//noInterrupts();
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
OCR5A = absoluteTimeout;
//SREG = sreg;
ignitionSchedule1.duration = duration;
@ -263,9 +264,9 @@ ISR(TIMER5_COMPA_vect, ISR_NOBLOCK) //ignitionSchedule1
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 >> 4);
ign1LastRev = startRevolutions;
//unsigned int absoluteTimeout = TCNT5 + (ignitionSchedule1.duration >> 2); //Divide by 4
unsigned int absoluteTimeout = TCNT5 + (ignitionSchedule1.duration >> 2); //Divide by 4
OCR5A = absoluteTimeout;
}
else if (ignitionSchedule1.Status == RUNNING)