diff --git a/speeduino/corrections.h b/speeduino/corrections.h index 81bdf506..8de32836 100644 --- a/speeduino/corrections.h +++ b/speeduino/corrections.h @@ -34,5 +34,9 @@ static inline int8_t correctionKnock(int8_t); uint16_t correctionsDwell(uint16_t dwell); uint16_t AFRnextCycle; +unsigned long knockStartTime; +byte lastKnockCount; +int16_t knockWindowMin; //The current minimum crank angle for a knock pulse to be valid +int16_t knockWindowMax;//The current maximum crank angle for a knock pulse to be valid #endif // CORRECTIONS_H diff --git a/speeduino/corrections.ino b/speeduino/corrections.ino index f039778c..09017d41 100644 --- a/speeduino/corrections.ino +++ b/speeduino/corrections.ino @@ -29,6 +29,7 @@ void initialiseCorrections() currentStatus.flexIgnCorrection = 0; currentStatus.egoCorrection = 100; //Default value of no adjustment must be set to avoid randomness on first correction cycle after startup AFRnextCycle = 0; + currentStatus.knockActive = false; } /* @@ -511,9 +512,32 @@ static inline int8_t correctionKnock(int8_t advance) { byte knockRetard = 0; - if( (configPage10.knock_mode > 0) && (knockCounter > 0) ) + //First check is to do the window calculations (ASsuming knock is enabled) + if( configPage10.knock_mode != KNOCK_MODE_OFF ) { - + knockWindowMin = table2D_getValue(&knockWindowStartTable, currentStatus.RPM); + knockWindowMax = knockWindowMin + table2D_getValue(&knockWindowDurationTable, currentStatus.RPM); + } + + + if( (configPage10.knock_mode == KNOCK_MODE_DIGITAL) ) + { + // + if(knockCounter > configPage10.knock_count) + { + if(currentStatus.knockActive == true) + { + //Knock retard is currently + } + else + { + //Knock needs to be activated + lastKnockCount = knockCounter; + knockStartTime = micros(); + knockRetard = configPage10.knock_firstStep; + } + } + } return advance - knockRetard; diff --git a/speeduino/globals.h b/speeduino/globals.h index 2051297c..5338dd07 100644 --- a/speeduino/globals.h +++ b/speeduino/globals.h @@ -170,6 +170,10 @@ #define NITROUS_STAGE1 1 #define NITROUS_STAGE2 2 +#define KNOCK_MODE_OFF 0 +#define KNOCK_MODE_DIGITAL 1 +#define KNOCK_MODE_ANALOG 2 + #define RESET_CONTROL_DISABLED 0 #define RESET_CONTROL_PREVENT_WHEN_RUNNING 1 #define RESET_CONTROL_PREVENT_ALWAYS 2 @@ -221,6 +225,8 @@ struct table2D rotarySplitTable; //8 bin ignition split curve for rotary leading struct table2D flexFuelTable; //6 bin flex fuel correction table for fuel adjustments (2D) struct table2D flexAdvTable; //6 bin flex fuel correction table for timing advance (2D) struct table2D flexBoostTable; //6 bin flex fuel correction table for boost adjustments (2D) +struct table2D knockWindowStartTable; +struct table2D knockWindowDurationTable; //These are for the direct port manipulation of the injectors, coils and aux outputs volatile byte *inj1_pin_port; @@ -393,6 +399,7 @@ struct statuses { bool fuelPumpOn; //The current status of the fuel pump byte syncLossCounter; byte knockRetard; + bool knockActive; //Helpful bitwise operations: //Useful reference: http://playground.arduino.cc/Code/BitMath diff --git a/speeduino/scheduler.ino b/speeduino/scheduler.ino index c8a20cde..bf04ebb3 100644 --- a/speeduino/scheduler.ino +++ b/speeduino/scheduler.ino @@ -1184,8 +1184,8 @@ static inline void ignitionSchedule1Interrupt() //Most ARM chips can simply call } else if (ignitionSchedule1.Status == RUNNING) { - //ignitionSchedule1.EndCallback(); - *ign1_pin_port &= ~(ign1_pin_mask); + ignitionSchedule1.EndCallback(); + //*ign1_pin_port &= ~(ign1_pin_mask); ignitionSchedule1.Status = OFF; //Turn off the schedule ignitionSchedule1.schedulesSet = 0; ignitionSchedule1.hasNextSchedule = false; diff --git a/speeduino/sensors.ino b/speeduino/sensors.ino index 538c70f0..dfeb2120 100644 --- a/speeduino/sensors.ino +++ b/speeduino/sensors.ino @@ -353,9 +353,11 @@ void flexPulse() */ void knockPulse() { + //Check if this the start of a knock. if(knockCounter == 0) { //knockAngle = crankAngle + fastTimeToAngle( (micros() - lastCrankAngleCalc) ); + knockStartTime = micros(); knockCounter = 1; } else { ++knockCounter; } //Knock has already started, so just increment the counter for this