Add in missing bits to allow up to 8 ignition channels

This commit is contained in:
Josh Stewart 2019-01-27 10:56:27 +13:00
parent 847d7d0c28
commit d337eed783
3 changed files with 115 additions and 5 deletions

View File

@ -6,7 +6,9 @@
#include "scheduler.h"
#include "HardwareTimer.h"
#if defined(STM32F4)
//These should really be in the stm32GENERIC libs, but for somereason they only have timers 1-4
#include <stm32_TIM_variant_11.h>
HardwareTimer Timer5(TIM5, chip_tim5, sizeof(chip_tim5) / sizeof(chip_tim5[0]));
HardwareTimer Timer8(TIM8, chip_tim8, sizeof(chip_tim8) / sizeof(chip_tim8[0]));
#endif
@ -103,13 +105,28 @@ void initBoard()
Timer3.setMode(4, TIMER_OUTPUT_COMPARE);
Timer1.setMode(1, TIMER_OUTPUT_COMPARE);
//Attach interupt functions
//Injection
Timer2.attachInterrupt(1, fuelSchedule1Interrupt);
Timer2.attachInterrupt(2, fuelSchedule2Interrupt);
Timer2.attachInterrupt(3, fuelSchedule3Interrupt);
Timer2.attachInterrupt(4, fuelSchedule4Interrupt);
#if (INJ_CHANNELS >= 5)
Timer5.attachInterrupt(1, fuelSchedule5Interrupt);
#endif
#if (INJ_CHANNELS >= 6)
Timer5.attachInterrupt(2, fuelSchedule6Interrupt);
#endif
#if (INJ_CHANNELS >= 7)
Timer5.attachInterrupt(3, fuelSchedule7Interrupt);
#endif
#if (INJ_CHANNELS >= 8)
Timer5.attachInterrupt(4, fuelSchedule8Interrupt);
#endif
#if (IGN_CHANNELS >= 1)
Timer3.attachInterrupt(1, ignitionSchedule1Interrupt);
//Ignition
#if (IGN_CHANNELS >= 1)
Timer3.attachInterrupt(1, ignitionSchedule1Interrupt);
#endif
#if (IGN_CHANNELS >= 2)
Timer3.attachInterrupt(2, ignitionSchedule2Interrupt);
@ -121,12 +138,27 @@ void initBoard()
Timer3.attachInterrupt(4, ignitionSchedule4Interrupt);
#endif
#if (IGN_CHANNELS >= 5)
Timer1.attachInterrupt(1, ignitionSchedule5Interrupt);
Timer4.attachInterrupt(1, ignitionSchedule5Interrupt);
#endif
#if (IGN_CHANNELS >= 6)
Timer4.attachInterrupt(2, ignitionSchedule6Interrupt);
#endif
#if (IGN_CHANNELS >= 7)
Timer4.attachInterrupt(3, ignitionSchedule7Interrupt);
#endif
#if (IGN_CHANNELS >= 8)
Timer4.attachInterrupt(4, ignitionSchedule8Interrupt);
#endif
Timer1.resume();
Timer2.resume();
Timer3.resume();
#if (IGN_CHANNELS >= 5)
Timer4.resume();
#endif
#if (INJ_CHANNELS >= 5)
Timer5.resume();
#endif
}
uint16_t freeRam()

View File

@ -1112,7 +1112,7 @@ static inline void ignitionSchedule4Interrupt() //Most ARM chips can simply call
#endif
#if IGN_CHANNELS >= 5
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this
#if defined(CORE_AVR) //AVR chips use the ISR for this
ISR(TIMER1_COMPC_vect) //ignitionSchedule5
#else
static inline void ignitionSchedule5Interrupt() //Most ARM chips can simply call a function
@ -1137,6 +1137,84 @@ static inline void ignitionSchedule5Interrupt() //Most ARM chips can simply call
}
#endif
#if IGN_CHANNELS >= 6
#if defined(CORE_AVR) //AVR chips use the ISR for this
ISR(TIMER1_COMPC_vect) //ignitionSchedule6 NOT CORRECT!!!
#else
static inline void ignitionSchedule6Interrupt() //Most ARM chips can simply call a function
#endif
{
if (ignitionSchedule6.Status == PENDING) //Check to see if this schedule is turn on
{
ignitionSchedule6.StartCallback();
ignitionSchedule6.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
ignitionSchedule6.startTime = micros();
IGN6_COMPARE = IGN6_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule6.duration); //Doing this here prevents a potential overflow on restarts
}
else if (ignitionSchedule6.Status == RUNNING)
{
ignitionSchedule6.Status = OFF; //Turn off the schedule
ignitionSchedule6.EndCallback();
ignitionSchedule6.schedulesSet = 0;
ignitionSchedule6.endScheduleSetByDecoder = false;
ignitionCount += 1; //Increment the igintion counter
IGN6_TIMER_DISABLE();
}
}
#endif
#if IGN_CHANNELS >= 7
#if defined(CORE_AVR) //AVR chips use the ISR for this
ISR(TIMER1_COMPC_vect) //ignitionSchedule6 NOT CORRECT!!!
#else
static inline void ignitionSchedule7Interrupt() //Most ARM chips can simply call a function
#endif
{
if (ignitionSchedule7.Status == PENDING) //Check to see if this schedule is turn on
{
ignitionSchedule7.StartCallback();
ignitionSchedule7.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
ignitionSchedule7.startTime = micros();
IGN7_COMPARE = IGN7_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule7.duration); //Doing this here prevents a potential overflow on restarts
}
else if (ignitionSchedule7.Status == RUNNING)
{
ignitionSchedule7.Status = OFF; //Turn off the schedule
ignitionSchedule7.EndCallback();
ignitionSchedule7.schedulesSet = 0;
ignitionSchedule7.endScheduleSetByDecoder = false;
ignitionCount += 1; //Increment the igintion counter
IGN7_TIMER_DISABLE();
}
}
#endif
#if IGN_CHANNELS >= 8
#if defined(CORE_AVR) //AVR chips use the ISR for this
ISR(TIMER1_COMPC_vect) //ignitionSchedule8 NOT CORRECT!!!
#else
static inline void ignitionSchedule8Interrupt() //Most ARM chips can simply call a function
#endif
{
if (ignitionSchedule8.Status == PENDING) //Check to see if this schedule is turn on
{
ignitionSchedule8.StartCallback();
ignitionSchedule8.Status = RUNNING; //Set the status to be in progress (ie The start callback has been called, but not the end callback)
ignitionSchedule8.startTime = micros();
IGN8_COMPARE = IGN8_COUNTER + uS_TO_TIMER_COMPARE(ignitionSchedule8.duration); //Doing this here prevents a potential overflow on restarts
}
else if (ignitionSchedule8.Status == RUNNING)
{
ignitionSchedule8.Status = OFF; //Turn off the schedule
ignitionSchedule8.EndCallback();
ignitionSchedule8.schedulesSet = 0;
ignitionSchedule8.endScheduleSetByDecoder = false;
ignitionCount += 1; //Increment the igintion counter
IGN8_TIMER_DISABLE();
}
}
#endif
#if defined(CORE_TEENSY)
void ftm0_isr(void)

View File

@ -1060,7 +1060,7 @@ void loop()
if ( tempStartAngle < 0) { tempStartAngle += CRANK_ANGLE_MAX_IGN; }
{
unsigned long ignition6StartTime = 0;
if(tempStartAngle > tempCrankAngle) { ignition6StartTime = angleToTime((tempStartAngle - tempCrankAngle)); }
if(tempStartAngle > tempCrankAngle) { ignition6StartTime = angleToTime((tempStartAngle - tempCrankAngle), CRANKMATH_METHOD_INTERVAL_REV); }
else { ignition6StartTime = 0; }
if( (ignition6StartTime > 0) && (curRollingCut != 2) )