diff --git a/auxiliaries.h b/auxiliaries.h new file mode 100644 index 00000000..1114457c --- /dev/null +++ b/auxiliaries.h @@ -0,0 +1,14 @@ + + +volatile byte *boost_pin_port; +volatile byte boost_pin_mask; +volatile byte *vvt_pin_port; +volatile byte vvt_pin_mask; + +volatile bool boost_pwm_state; +unsigned int boost_pwm_max_count; //Used for variable PWM frequency +unsigned int boost_pwm_cur_value; + +volatile bool vvt_pwm_state; +unsigned int vvt_pwm_max_count; //Used for variable PWM frequency +unsigned int vvt_pwm_cur_value; diff --git a/auxiliaries.ino b/auxiliaries.ino index e1a9c337..fc47ef76 100644 --- a/auxiliaries.ino +++ b/auxiliaries.ino @@ -20,6 +20,28 @@ void fanControl() else if (currentStatus.coolant <= (configPage4.fanSP - configPage4.fanHyster)) { digitalWrite(pinFan, fanLOW); } } - +void initialiseAuxPWM() +{ + TCCR1B = 0x00; //Disbale Timer1 while we set it up + TCNT1 = 0; //Reset Timer Count + TIFR1 = 0x00; //Timer3 INT Flag Reg: Clear Timer Overflow Flag + TCCR1A = 0x00; //Timer3 Control Reg A: Wave Gen Mode normal + TCCR1B = (1 << CS12); //Timer3 Control Reg B: Timer Prescaler set to 256. 1 tick = 16uS. Refer to http://www.instructables.com/files/orig/F3T/TIKL/H3WSA4V7/F3TTIKLH3WSA4V7.jpg + + boost_pin_port = portOutputRegister(digitalPinToPort(pinBoost)); + boost_pin_mask = digitalPinToBitMask(pinBoost); + boost_pin_port = portOutputRegister(digitalPinToPort(pinBoost)); + boost_pin_mask = digitalPinToBitMask(pinBoost); + + boost_pwm_max_count = 1000000L / (16 * configPage3.boostFreq * 2); //Converts the frequency in Hz to the number of ticks (at 16uS) it takes to complete 1 cycle. The x2 is there because the frequency is stored at half value (in a byte) + vvt_pwm_max_count = 1000000L / (16 * configPage3.vvtFreq * 2);; //Converts the frequency in Hz to the number of ticks (at 16uS) it takes to complete 1 cycle + TIMSK1 |= (1 << OCIE1A); //Turn on the A compare unit (ie turn on the interrupt) + TIMSK1 |= (1 << OCIE1B); //Turn on the B compare unit (ie turn on the interrupt) +} + +void boostControl() +{ + +} diff --git a/globals.h b/globals.h index b835e0a3..1f8f79b5 100644 --- a/globals.h +++ b/globals.h @@ -244,7 +244,9 @@ struct config3 { byte egoAlgorithm : 2; byte egoType : 2; - byte unused : 4; + byte boostEnabled : 1; + byte vvtEnabled : 1; + byte unused : 2; byte egoKP; byte egoKI; @@ -264,8 +266,8 @@ struct config3 { byte injVoltageCorrectionValues[6]; //Correction table for injector PW vs battery voltage byte airDenBins[9]; byte airDenRates[9]; - byte unused45; - byte unused46; + byte boostFreq; //Frequency of the boost PWM valve + byte vvtFreq; //Frequency of the vvt PWM valve byte unused47; byte unused48; byte unused49; diff --git a/reference/speeduino.ini b/reference/speeduino.ini index ae21345f..0ec6cfdd 100644 --- a/reference/speeduino.ini +++ b/reference/speeduino.ini @@ -279,6 +279,8 @@ page = 5 page = 6 egoAlgorithm= bits , U08, 0, [0:1], "Simple", "INVALID", "PID", "No correction" ; * ( 1 byte) egoType = bits , U08, 0, [2:3], "Disabled", "Narrow Band", "Wide Band", "INVALID" ; egoOption + boostEnabled= bits, U08, 0, [4:4], "Off", "On" + vvtEnabled = bits, U08, 0, [5:5], "Off", "On" egoKP = scalar, U08, 1, "%", 1.0, 0.0, 0.0, 200.0, 0 ; * ( 1 byte) egoKI = scalar, U08, 2, "%", 1.0, 0.0, 0.0, 200.0, 0 ; * ( 1 byte) egoKD = scalar, U08, 3, "%", 1.0, 0.0, 0.0, 200.0, 0 ; * ( 1 byte) @@ -287,24 +289,24 @@ page = 6 #else egoTemp = scalar, U08, 4, "°F", 1.0, -40, -40, 215.0, 0 #endif - egoCount = scalar, U08, 5, "", 4.0, 0.0, 4.0, 255.0, 0 ; * ( 1 byte) - egoDelta = scalar, U08, 6, "%", 1.0, 0.0, 0.0, 255.0, 0 ; * ( 1 byte) - egoLimit = scalar, U08, 7, "", 1, 0, 0, 16, 0 - ego_min = scalar, U08, 8, "AFR", 0.1, 0.0, 7, 25, 1 - ego_max = scalar, U08, 9, "AFR", 0.1, 0.0, 7, 25, 1 - ego_sdelay = scalar, U08, 10, "sec", 1, 0, 0, 120, 0 - egoRPM = scalar, U08, 11, "rpm", 100, 0.0, 100, 25500, 0 - egoTPSMax = scalar, U08, 12, "%", 1, 0, 0, 120, 0 - egoLoadMax = scalar, U08, 13, "%", 1, 0, 0, 120, 0 - egoLoadMin = scalar, U08, 14, "%", 1, 0, 0, 120, 0 - brvBins = array, U08, 15, [6], "V", 0.1, 0, 6, 24, 1 ; Bins for the battery reference voltage - injBatRates = array, U08, 21, [6], "%", 1, 0, 0, 255, 0 ;Values for injector pulsewidth vs voltage - airDenBins = array, U08, 27, [9], "C", 1.0, -40, -40, 215, 0 ; Bins for the air density correction curve - airDenRates = array, U08, 36, [9], "%", 1.0, 0.0, 0, 255, 0 ; Values for the air density correction curve - unused45 = scalar, U08, 45, "RPM", 100.0, 0.0, 100, 25500, 0 - unused46 = scalar, U08, 46, "RPM", 100.0, 0.0, 100, 25500, 0 - unused47 = scalar, U08, 47, "RPM", 100.0, 0.0, 100, 25500, 0 - unused48 = scalar, U08, 48, "RPM", 100.0, 0.0, 100, 25500, 0 + egoCount = scalar, U08, 5, "", 4.0, 0.0, 4.0, 255.0, 0 ; * ( 1 byte) + egoDelta = scalar, U08, 6, "%", 1.0, 0.0, 0.0, 255.0, 0 ; * ( 1 byte) + egoLimit = scalar, U08, 7, "", 1, 0, 0, 16, 0 + ego_min = scalar, U08, 8, "AFR", 0.1, 0.0, 7, 25, 1 + ego_max = scalar, U08, 9, "AFR", 0.1, 0.0, 7, 25, 1 + ego_sdelay = scalar, U08, 10, "sec", 1, 0, 0, 120, 0 + egoRPM = scalar, U08, 11, "rpm", 100, 0.0, 100, 25500, 0 + egoTPSMax = scalar, U08, 12, "%", 1, 0, 0, 120, 0 + egoLoadMax = scalar, U08, 13, "%", 1, 0, 0, 120, 0 + egoLoadMin = scalar, U08, 14, "%", 1, 0, 0, 120, 0 + brvBins = array, U08, 15, [6], "V", 0.1, 0, 6, 24, 1 ; Bins for the battery reference voltage + injBatRates = array, U08, 21, [6], "%", 1, 0, 0, 255, 0 ;Values for injector pulsewidth vs voltage + airDenBins = array, U08, 27, [9], "C", 1.0, -40, -40, 215, 0 ; Bins for the air density correction curve + airDenRates = array, U08, 36, [9], "%", 1.0, 0.0, 0, 255, 0 ; Values for the air density correction curve + boostFreq = scalar, U08, 45, "Hz", 2.0, 0.0, 0, 511, 0 + vvtFreq = scalar, U08, 46, "Hz", 2.0, 0.0, 100, 25500, 0 + boostEnabled= bits, U08, 47, [0:0], "Off", "On" + vvtEnabled = bits, U08, 47, [1:1], "Off", "On" unused49 = scalar, U08, 49, "RPM", 100.0, 0.0, 100, 25500, 0 unused50 = scalar, U08, 50, "RPM", 100.0, 0.0, 100, 25500, 0 unused51 = scalar, U08, 51, "RPM", 100.0, 0.0, 100, 25500, 0 @@ -386,6 +388,8 @@ page = 8 requiresPowerCycle = IgInv requiresPowerCycle = fanInv requiresPowerCycle = iacAlgorithm + requiresPowerCycle = boostEnabled + requiresPowerCycle = vvtEnabled defaultValue = pinLayout, 1 defaultValue = TrigPattern, 0 diff --git a/speeduino.ino b/speeduino.ino index 0396b8bc..82b1f37a 100644 --- a/speeduino.ino +++ b/speeduino.ino @@ -34,6 +34,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "display.h" #include "decoders.h" #include "idle.h" +#include "auxiliaries.h" #ifdef __SAM3X8E__ //Do stuff for ARM based CPUs @@ -113,11 +114,13 @@ void setup() table3D_setSize(&fuelTable, 16); table3D_setSize(&ignitionTable, 16); table3D_setSize(&afrTable, 16); - table3D_setSize(&boostTable, 8); - table3D_setSize(&vvtTable, 8); loadConfig(); + //Boost and vvt tables are only created if they are turned on + if(configPage3.boostEnabled) { table3D_setSize(&boostTable, 8); } + if(configPage3.vvtEnabled) { table3D_setSize(&vvtTable, 8); } + //Repoint the 2D table structs to the config pages that were just loaded taeTable.valueSize = SIZE_BYTE; //Set this table to use byte values taeTable.xSize = 4;