Workaround for potential stray spark signals on startup
This commit is contained in:
parent
7550a6a0a0
commit
9101356c5a
|
@ -87,9 +87,14 @@
|
|||
#define FUEL7_TIMER_DISABLE() TIMSK5 &= ~(1 << OCIE5C); //
|
||||
#define FUEL8_TIMER_DISABLE() TIMSK5 &= ~(1 << OCIE5B); //
|
||||
|
||||
#define IGN1_TIMER_ENABLE() TIMSK5 |= (1 << OCIE5A) //Turn on the A compare unit (ie turn on the interrupt)
|
||||
#define IGN2_TIMER_ENABLE() TIMSK5 |= (1 << OCIE5B) //Turn on the B compare unit (ie turn on the interrupt)
|
||||
#define IGN3_TIMER_ENABLE() TIMSK5 |= (1 << OCIE5C) //Turn on the C compare unit (ie turn on the interrupt)
|
||||
//These have the TIFR5 bits set to 1 to clear the interrupt flag. This prevents a false interrupt being called the first time the channel is enabled.
|
||||
//I'm not sure why these are necessary as these should all be reset upon initialisation, but they do for the problem when added here
|
||||
#define IGN1_TIMER_ENABLE() TIFR5 |= (1<<OCF5A); TIMSK5 |= (1 << OCIE5A) //Turn on the A compare unit (ie turn on the interrupt)
|
||||
#define IGN2_TIMER_ENABLE() TIFR5 |= (1<<OCF5B); TIMSK5 |= (1 << OCIE5B) //Turn on the B compare unit (ie turn on the interrupt)
|
||||
#define IGN3_TIMER_ENABLE() TIFR5 |= (1<<OCF5C); TIMSK5 |= (1 << OCIE5C) //Turn on the C compare unit (ie turn on the interrupt)
|
||||
//#define IGN1_TIMER_ENABLE() TIMSK5 |= (1 << OCIE5A) //Turn on the B compare unit (ie turn on the interrupt)
|
||||
//#define IGN2_TIMER_ENABLE() TIMSK5 |= (1 << OCIE5B) //Turn on the B compare unit (ie turn on the interrupt)
|
||||
//#define IGN3_TIMER_ENABLE() TIMSK5 |= (1 << OCIE5C) //Turn on the C compare unit (ie turn on the interrupt)
|
||||
#define IGN4_TIMER_ENABLE() TIMSK4 |= (1 << OCIE4A) //Turn on the A compare unit (ie turn on the interrupt)
|
||||
#define IGN5_TIMER_ENABLE() TIMSK1 |= (1 << OCIE1C) //Turn on the A compare unit (ie turn on the interrupt)
|
||||
#define IGN6_TIMER_ENABLE() TIMSK4 |= (1 << OCIE4B) //Replaces injector 4
|
||||
|
|
|
@ -44,6 +44,42 @@ void initBoard()
|
|||
//Boooooooooo WDT is currently broken on Mega 2560 bootloaders :(
|
||||
//wdt_enable(WDTO_2S);
|
||||
|
||||
/*
|
||||
***********************************************************************************************************
|
||||
* Schedules
|
||||
* */
|
||||
//Much help in this from http://arduinomega.blogspot.com.au/2011/05/timer2-and-overflow-interrupt-lets-get.html
|
||||
//Fuel Schedules, which uses timer 3
|
||||
TCCR3B = 0x00; //Disable Timer3 while we set it up
|
||||
TCNT3 = 0; //Reset Timer Count
|
||||
TIFR3 = 0x00; //Timer3 INT Flag Reg: Clear Timer Overflow Flag
|
||||
TCCR3A = 0x00; //Timer3 Control Reg A: Wave Gen Mode normal
|
||||
TCCR3B = (1 << CS12); //Timer3 Control Reg B: Timer Prescaler set to 256. Refer to http://www.instructables.com/files/orig/F3T/TIKL/H3WSA4V7/F3TTIKLH3WSA4V7.jpg
|
||||
//TCCR3B = 0x03; //Timer3 Control Reg B: Timer Prescaler set to 64. Refer to http://www.instructables.com/files/orig/F3T/TIKL/H3WSA4V7/F3TTIKLH3WSA4V7.jpg
|
||||
|
||||
//Ignition Schedules, which uses timer 5. This is also used by the fast version of micros(). If the speed of this timer is changed from 4uS ticks, that MUST be changed as well. See globals.h and timers.ino
|
||||
TCCR5B = 0x00; //Disable Timer5 while we set it up
|
||||
TCNT5 = 0; //Reset Timer Count
|
||||
//TIFR5 = 0x00; //Timer5 INT Flag Reg: Clear Timer Overflow Flag
|
||||
//TIFR5 = 0xFF;
|
||||
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; //aka Divisor = 64 = 490.1Hz
|
||||
TCCR5B = (1 << CS11) | (1 << CS10); //Timer5 Control Reg B: Timer Prescaler set to 64. Refer to http://www.instructables.com/files/orig/F3T/TIKL/H3WSA4V7/F3TTIKLH3WSA4V7.jpg
|
||||
TIFR5 = 0xFF;
|
||||
|
||||
#if defined(TIMER5_MICROS)
|
||||
TIMSK5 |= (1 << TOIE5); //Enable the timer5 overflow interrupt (See timers.ino for ISR)
|
||||
TIMSK0 &= ~_BV(TOIE0); // disable timer0 overflow interrupt
|
||||
#endif
|
||||
|
||||
//The remaining Schedules (Schedules 4 for fuel and ignition) use Timer4
|
||||
TCCR4B = 0x00; //Disable Timer4 while we set it up
|
||||
TCNT4 = 0; //Reset Timer Count
|
||||
TIFR4 = 0x00; //Timer4 INT Flag Reg: Clear Timer Overflow Flag
|
||||
TCCR4A = 0x00; //Timer4 Control Reg A: Wave Gen Mode normal
|
||||
TCCR4B = (1 << CS12); //Timer4 Control Reg B: aka Divisor = 256 = 122.5HzTimer Prescaler set to 256. Refer to http://www.instructables.com/files/orig/F3T/TIKL/H3WSA4V7/F3TTIKLH3WSA4V7.jpg
|
||||
|
||||
}
|
||||
|
||||
uint16_t freeRam()
|
||||
|
|
|
@ -208,31 +208,32 @@ For each ignition channel, a check is made whether we're at the relevant tooth a
|
|||
Only if both these conditions are met will the schedule be updated with the latest timing information.
|
||||
If it's the correct tooth, but the schedule is not yet started, calculate and an end compare value (This situation occurs when both the start and end of the ignition pulse happen after the end tooth, but before the next tooth)
|
||||
*/
|
||||
#define MIN_CYCLES_FOR_ENDCOMPARE 5
|
||||
#define checkPerToothTiming(crankAngle, currentTooth) \
|
||||
{ \
|
||||
if (fixedCrankingOverride == 0) \
|
||||
if (fixedCrankingOverride == 0 && currentStatus.RPM > 0) \
|
||||
{ \
|
||||
if ( (currentTooth == ignition1EndTooth) ) \
|
||||
{ \
|
||||
if( (ignitionSchedule1.Status == RUNNING) ) { IGN1_COMPARE = IGN1_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition1EndAngle - crankAngle) ) ) ); } \
|
||||
else if(currentStatus.startRevolutions > 2) { ignitionSchedule1.endCompare = IGN1_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition1EndAngle - crankAngle) ) ) ); ignitionSchedule1.endScheduleSetByDecoder = true; } \
|
||||
else if(currentStatus.startRevolutions > MIN_CYCLES_FOR_ENDCOMPARE) { ignitionSchedule1.endCompare = IGN1_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition1EndAngle - crankAngle) ) ) ); ignitionSchedule1.endScheduleSetByDecoder = true; } \
|
||||
} \
|
||||
\
|
||||
else if ( (currentTooth == ignition2EndTooth) ) \
|
||||
{ \
|
||||
if( (ignitionSchedule2.Status == RUNNING) ) { IGN2_COMPARE = IGN2_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition2EndAngle - crankAngle) ) ) ); } \
|
||||
else { ignitionSchedule2.endCompare = IGN2_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition2EndAngle - crankAngle) ) ) ); ignitionSchedule2.endScheduleSetByDecoder = true; } \
|
||||
else if(currentStatus.startRevolutions > MIN_CYCLES_FOR_ENDCOMPARE) { ignitionSchedule2.endCompare = IGN2_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition2EndAngle - crankAngle) ) ) ); ignitionSchedule2.endScheduleSetByDecoder = true; } \
|
||||
} \
|
||||
\
|
||||
else if ( (currentTooth == ignition3EndTooth) ) \
|
||||
{ \
|
||||
if( (ignitionSchedule3.Status == RUNNING) ) { IGN3_COMPARE = IGN3_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition3EndAngle - crankAngle) ) ) ); } \
|
||||
else { ignitionSchedule3.endCompare = IGN3_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition3EndAngle - crankAngle) ) ) ); ignitionSchedule3.endScheduleSetByDecoder = true; } \
|
||||
else if(currentStatus.startRevolutions > MIN_CYCLES_FOR_ENDCOMPARE) { ignitionSchedule3.endCompare = IGN3_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition3EndAngle - crankAngle) ) ) ); ignitionSchedule3.endScheduleSetByDecoder = true; } \
|
||||
} \
|
||||
else if ( (currentTooth == ignition4EndTooth) ) \
|
||||
{ \
|
||||
if( (ignitionSchedule4.Status == RUNNING) ) { IGN4_COMPARE = IGN4_COUNTER + uS_TO_TIMER_COMPARE_SLOW( fastDegreesToUS( ignitionLimits( (ignition4EndAngle - crankAngle) ) ) ); } \
|
||||
else { ignitionSchedule4.endCompare = IGN4_COUNTER + uS_TO_TIMER_COMPARE_SLOW( fastDegreesToUS( ignitionLimits( (ignition4EndAngle - crankAngle) ) ) ); ignitionSchedule4.endScheduleSetByDecoder = true; } \
|
||||
else if(currentStatus.startRevolutions > MIN_CYCLES_FOR_ENDCOMPARE) { ignitionSchedule4.endCompare = IGN4_COUNTER + uS_TO_TIMER_COMPARE_SLOW( fastDegreesToUS( ignitionLimits( (ignition4EndAngle - crankAngle) ) ) ); ignitionSchedule4.endScheduleSetByDecoder = true; } \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
@ -276,6 +277,7 @@ void triggerPri_missingTooth()
|
|||
validTrigger = true; //Flag this pulse as being a valid trigger (ie that it passed filters)
|
||||
|
||||
//if(toothCurrentCount > checkSyncToothCount || currentStatus.hasSync == false)
|
||||
if( (toothLastToothTime > 0) && (toothLastMinusOneToothTime > 0) )
|
||||
{
|
||||
//Begin the missing tooth detection
|
||||
//If the time between the current tooth and the last is greater than 1.5x the time between the last tooth and the tooth before that, we make the assertion that we must be at the first tooth after the gap
|
||||
|
@ -287,7 +289,7 @@ void triggerPri_missingTooth()
|
|||
if ( (curGap > targetGap) || (toothCurrentCount > triggerActualTeeth) )
|
||||
{
|
||||
//Missing tooth detected
|
||||
if(toothCurrentCount < (triggerActualTeeth) && (currentStatus.hasSync == true) )
|
||||
if( (toothCurrentCount < triggerActualTeeth) && (currentStatus.hasSync == true) )
|
||||
{
|
||||
//This occurs when we're at tooth #1, but haven't seen all the other teeth. This indicates a signal issue so we flag lost sync so this will attempt to resync on the next revolution.
|
||||
currentStatus.hasSync = false;
|
||||
|
@ -297,13 +299,19 @@ void triggerPri_missingTooth()
|
|||
//else if (currentStatus.hasSync == false && toothCurrentCount < checkSyncToothCount ) { triggerFilterTime = 0; }
|
||||
else
|
||||
{
|
||||
if(currentStatus.hasSync == true)
|
||||
{
|
||||
currentStatus.startRevolutions++; //Counter
|
||||
if ( configPage4.TrigSpeed == CAM_SPEED ) { currentStatus.startRevolutions++; } //Add an extra revolution count if we're running at cam speed
|
||||
}
|
||||
else { currentStatus.startRevolutions = 0; }
|
||||
|
||||
toothCurrentCount = 1;
|
||||
revolutionOne = !revolutionOne; //Flip sequential revolution tracker
|
||||
toothOneMinusOneTime = toothOneTime;
|
||||
toothOneTime = curTime;
|
||||
currentStatus.hasSync = true;
|
||||
currentStatus.startRevolutions++; //Counter
|
||||
if ( configPage4.TrigSpeed == CAM_SPEED ) { currentStatus.startRevolutions++; } //Add an extra revolution count if we're running at cam speed
|
||||
|
||||
triggerFilterTime = 0; //This is used to prevent a condition where serious intermitent signals (Eg someone furiously plugging the sensor wire in and out) can leave the filter in an unrecoverable state
|
||||
toothLastMinusOneToothTime = toothLastToothTime;
|
||||
toothLastToothTime = curTime;
|
||||
|
@ -320,6 +328,12 @@ void triggerPri_missingTooth()
|
|||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
toothLastMinusOneToothTime = toothLastToothTime;
|
||||
toothLastToothTime = curTime;
|
||||
}
|
||||
|
||||
|
||||
//NEW IGNITION MODE
|
||||
if( (configPage2.perToothIgn == true) && (!BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK)) )
|
||||
|
@ -1083,7 +1097,8 @@ void triggerPri_4G63()
|
|||
}
|
||||
|
||||
//EXPERIMENTAL!
|
||||
if(configPage2.perToothIgn == true)
|
||||
//New ignition mode is ONLY available on 4g63 when the trigger angle is set to the stock value of 0.
|
||||
if( (configPage2.perToothIgn == true) && (configPage4.triggerAngle == 0) )
|
||||
{
|
||||
if(configPage2.nCylinders == 4)
|
||||
{
|
||||
|
|
|
@ -13,38 +13,6 @@ void initialiseSchedulers()
|
|||
{
|
||||
nullSchedule.Status = OFF;
|
||||
|
||||
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this
|
||||
//Much help in this from http://arduinomega.blogspot.com.au/2011/05/timer2-and-overflow-interrupt-lets-get.html
|
||||
//Fuel Schedules, which uses timer 3
|
||||
TCCR3B = 0x00; //Disable Timer3 while we set it up
|
||||
TCNT3 = 0; //Reset Timer Count
|
||||
TIFR3 = 0x00; //Timer3 INT Flag Reg: Clear Timer Overflow Flag
|
||||
TCCR3A = 0x00; //Timer3 Control Reg A: Wave Gen Mode normal
|
||||
TCCR3B = (1 << CS12); //Timer3 Control Reg B: Timer Prescaler set to 256. Refer to http://www.instructables.com/files/orig/F3T/TIKL/H3WSA4V7/F3TTIKLH3WSA4V7.jpg
|
||||
//TCCR3B = 0x03; //Timer3 Control Reg B: Timer Prescaler set to 64. Refer to http://www.instructables.com/files/orig/F3T/TIKL/H3WSA4V7/F3TTIKLH3WSA4V7.jpg
|
||||
|
||||
//Ignition Schedules, which uses timer 5. This is also used by the fast version of micros(). If the speed of this timer is changed from 4uS ticks, that MUST be changed as well. See globals.h and timers.ino
|
||||
TCCR5B = 0x00; //Disable Timer5 while we set it up
|
||||
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; //aka Divisor = 64 = 490.1Hz
|
||||
|
||||
#if defined(TIMER5_MICROS)
|
||||
TIMSK5 |= (1 << TOIE5); //Enable the timer5 overflow interrupt (See timers.ino for ISR)
|
||||
TIMSK0 &= ~_BV(TOIE0); // disable timer0 overflow interrupt
|
||||
#endif
|
||||
|
||||
//The remaining Schedules (Schedules 4 for fuel and ignition) use Timer4
|
||||
TCCR4B = 0x00; //Disable Timer4 while we set it up
|
||||
TCNT4 = 0; //Reset Timer Count
|
||||
TIFR4 = 0x00; //Timer4 INT Flag Reg: Clear Timer Overflow Flag
|
||||
TCCR4A = 0x00; //Timer4 Control Reg A: Wave Gen Mode normal
|
||||
TCCR4B = (1 << CS12); //Timer4 Control Reg B: aka Divisor = 256 = 122.5HzTimer Prescaler set to 256. Refer to http://www.instructables.com/files/orig/F3T/TIKL/H3WSA4V7/F3TTIKLH3WSA4V7.jpg
|
||||
|
||||
#endif
|
||||
|
||||
fuelSchedule1.Status = OFF;
|
||||
fuelSchedule2.Status = OFF;
|
||||
fuelSchedule3.Status = OFF;
|
||||
|
|
|
@ -194,7 +194,7 @@ void oneMSInterval() //Most ARM chips can simply call a function
|
|||
#if defined(CORE_AVR) //AVR chips use the ISR for this
|
||||
//Reset Timer2 to trigger in another ~1ms
|
||||
TCNT2 = 131; //Preload timer2 with 100 cycles, leaving 156 till overflow.
|
||||
TIFR2 = 0x00; //Timer2 INT Flag Reg: Clear Timer Overflow Flag
|
||||
//TIFR2 = 0x00; //Timer2 INT Flag Reg: Clear Timer Overflow Flag
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue