diff --git a/globals.h b/globals.h index 12da1c29..96dddbe6 100644 --- a/globals.h +++ b/globals.h @@ -97,7 +97,7 @@ struct config1 { byte aseCount; //Afterstart enrichment cycles. This is the number of ignition cycles that the afterstart enrichment % lasts for byte wueValues[10]; //Warm up enrichment array (10 bytes) byte crankingPct; //Cranking enrichment - byte unused95; + byte pinMapping; // The board / ping mapping to be used byte unused96; byte unused97; byte taeColdA; @@ -248,65 +248,23 @@ struct config3 { }; -/* -//Pin mappings as per the v0.3 shield -#define pinInjector1 8 //Output pin injector 1 is on -#define pinInjector2 9 //Output pin injector 2 is on -#define pinInjector3 10 //Output pin injector 3 is on -#define pinInjector4 11 //Output pin injector 4 is on -#define pinCoil1 28 //Pin for coil 1 -#define pinCoil2 24 //Pin for coil 2 -#define pinCoil3 40 //Pin for coil 3 -#define pinCoil4 36 //Pin for coil 4 -#define pinTrigger 18 //The CAS pin -#define pinTrigger2 19 //The Cam Sensor pin -#define pinTPS A2 //TPS input pin -#define pinMAP A3 //MAP sensor pin -#define pinIAT A0 //IAT sensor pin -#define pinCLT A1 //CLS sensor pin -#define pinO2 A8 //O2 Sensor pin -#define pinBat A4 //O2 Sensor pin -#define pinDisplayReset 48 // OLED reset pin -*/ - -//Pin mappings as per the v0.2 shield - -#define pinInjector1 8 //Output pin injector 1 is on -#define pinInjector2 9 //Output pin injector 2 is on -#define pinInjector3 10 //Output pin injector 3 is on -#define pinInjector4 11 //Output pin injector 4 is on -#define pinCoil1 28 //Pin for coil 1 -#define pinCoil2 24 //Pin for coil 2 -#define pinCoil3 40 //Pin for coil 3 -#define pinCoil4 36 //Pin for coil 4 -#define pinTrigger 20 //The CAS pin -#define pinTrigger2 21 //The Cam Sensor pin -#define pinTPS A2 //TPS input pin -#define pinMAP A3 //MAP sensor pin -#define pinIAT A0 //IAT sensor pin -#define pinCLT A1 //CLS sensor pin -#define pinO2 A8 //O2 Sensor pin -#define pinBat A4 //O2 Sensor pin -#define pinDisplayReset 48 // OLED reset pin - - -//Pin mappings as per the v0.1 shield -/* -#define pinInjector1 8 //Output pin injector 1 is on -#define pinInjector2 9 //Output pin injector 2 is on -#define pinInjector3 11 //Output pin injector 3 is on -#define pinInjector4 10 //Output pin injector 4 is on -#define pinCoil1 6 //Pin for coil 1 -#define pinCoil2 7 //Pin for coil 2 -#define pinCoil3 12 //Pin for coil 3 -#define pinCoil4 13 //Pin for coil 4 -#define pinTrigger 2 //The CAS pin -#define pinTPS A0 //TPS input pin -#define pinMAP A1 //MAP sensor pin -#define pinIAT A2 //IAT sensor pin -#define pinCLT A3 //CLS sensor pin -#define pinO2 A4 //O2 Sensor pin -*/ +byte pinInjector1; //Output pin injector 1 +byte pinInjector2; //Output pin injector 2 +byte pinInjector3; //Output pin injector 3 is on +byte pinInjector4; //Output pin injector 4 is on +byte pinCoil1; //Pin for coil 1 +byte pinCoil2; //Pin for coil 2 +byte pinCoil3; //Pin for coil 3 +byte pinCoil4; //Pin for coil 4 +byte pinTrigger; //The CAS pin +byte pinTrigger2; //The Cam Sensor pin +byte pinTPS;//TPS input pin +byte pinMAP; //MAP sensor pin +byte pinIAT; //IAT sensor pin +byte pinCLT; //CLS sensor pin +byte pinO2; //O2 Sensor pin +byte pinBat; //O2 Sensor pin +byte pinDisplayReset; // OLED reset pin // global variables // from speeduino.ino extern struct statuses currentStatus; // from speeduino.ino diff --git a/reference/speeduino 0.2.ini b/reference/speeduino 0.2.ini index 6216bbf7..6e0c4f59 100644 --- a/reference/speeduino 0.2.ini +++ b/reference/speeduino 0.2.ini @@ -91,7 +91,7 @@ page = 1 aseCount = scalar, U08, 83, "s", 1.0, 0.0, 0.0, 255, 0 wueBins = array, U08, 84, [ 10], "%", 1.0, 0.0, 0.0, 255, 0 crankingPct= scalar, U08, 94, "%", 1.0, 0.0, 0.0, 255, 0 - unused95 = scalar, U08, 95, "ms", 0.1, 0.0, 0.0, 25.5, 1 + pinLayout = bits, U08, 95, [0:7], "Speeduino v0.1", "Speeduino v0.2", "Speeduino v0.3", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" unused96 = scalar, U08, 96, "ms", 0.1, 0.0, 0.0, 25.5, 1 unused97 = scalar, U08, 97, "ms", 0.1, 0.0, 0.0, 25.5, 1 taeColdA = scalar, U08, 98, "ms", 0.1, 0.0, 0.0, 25.5, 1 @@ -290,6 +290,12 @@ page = 3 ;unused127 = scalar, U08, 127, "none", 0, 0, 0, 0, 0 ;------------------------------------------------------------------------------- +[ConstantsExtensions] + requiresPowerCycle = nCylinders + requiresPowerCycle = pinLayout + + defaultValue = pinLayout, 1 + [Menu] ;---------------------------------------------------------------------------- @@ -317,7 +323,8 @@ page = 3 ;---------------------------------------------------------------------------- menu = "&Settings" - subMenu = std_injection, "&Constants" + ;subMenu = std_injection, "&Constants" + subMenu = engine_constants, "Engine Constants" subMenu = injChars, "Injector Characteristics" subMenu = triggerSettings, "&Trigger Setup" subMenu = OLED, "OLED Setup" @@ -386,6 +393,14 @@ page = 3 ; dialog which will be added. ; dialogs can be nested and can be mixed with fields + dialog = engine_constants_south + field = "Board Layout", pinLayout + + dialog = engine_constants, "" + panel = std_injection, North + panel = engine_constants_south, South + + dialog = accelEnrichments_south, "" field = "TPSdot Threshold", tpsThresh field = "Accel Time", taeTime @@ -940,6 +955,7 @@ help = helpEnrichments, "Enrichments Help" ; egoVoltage = { egoADC / 255.0 * 5.0 } ; EGO sensor voltage. time = { timeNow } ; "timeNow" is a parameterless built-in function. ;loopsPerSecond = { loopsPerSecond10*10 } ; True number of mainloops per second + seconds = { secl }; afrtarget = { 0 } ; #include "lambdaSensors.ini" diff --git a/speeduino.ino b/speeduino.ino index c29e955e..ec653b82 100644 --- a/speeduino.ino +++ b/speeduino.ino @@ -13,13 +13,18 @@ #include "table.h" #include "testing.h" #include "scheduler.h" -#include "storage.h" #include "comms.h" #include "math.h" #include "corrections.h" #include "timers.h" #include "display.h" +#ifdef __SAM3X8E__ + //Do stuff for ARM based CPUs +#else + #include "storage.h" +#endif + #include "fastAnalog.h" #define DIGITALIO_NO_MIX_ANALOGWRITE #include @@ -112,6 +117,8 @@ void setup() //Setup the calibration tables loadCalibration(); + //Set the pin mappings + setPinMapping(configPage1.pinMapping); //Need to check early on whether the coil charging is inverted. If this is not set straight away it can cause an unwanted spark at bootup if(configPage2.IgInv == 1) { coilHIGH = LOW, coilLOW = HIGH; } diff --git a/utils.h b/utils.h index 49746fae..ebb98eb2 100644 --- a/utils.h +++ b/utils.h @@ -9,6 +9,7 @@ These are some utility functions and variables used through the main code #define US_IN_MINUTE 60000000 int freeRam (); +void setPinMapping(byte boardID); int AIRDEN(); unsigned int PW(); unsigned int PW_SD(); diff --git a/utils.ino b/utils.ino index 6f23a144..3b493f94 100644 --- a/utils.ino +++ b/utils.ino @@ -10,6 +10,91 @@ int freeRam () return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); } +void setPinMapping(byte boardID) +{ + switch(boardID) + { + case 0: + //Pin mappings as per the v0.1 shield + pinInjector1 = 8; //Output pin injector 1 is on + pinInjector2 = 9; //Output pin injector 2 is on + pinInjector3 = 11; //Output pin injector 3 is on + pinInjector4 = 10; //Output pin injector 4 is on + pinCoil1 = 6; //Pin for coil 1 + pinCoil2 = 7; //Pin for coil 2 + pinCoil3 = 12; //Pin for coil 3 + pinCoil4 = 13; //Pin for coil 4 + pinTrigger = 2; //The CAS pin + pinTPS = A0; //TPS input pin + pinMAP = A1; //MAP sensor pin + pinIAT = A2; //IAT sensor pin + pinCLT = A3; //CLS sensor pin + pinO2 = A4; //O2 Sensor pin + break; + case 1: + //Pin mappings as per the v0.2 shield + pinInjector1 = 8; //Output pin injector 1 is on + pinInjector2 = 9; //Output pin injector 2 is on + pinInjector3 = 10; //Output pin injector 3 is on + pinInjector4 = 11; //Output pin injector 4 is on + pinCoil1 = 28; //Pin for coil 1 + pinCoil2 = 24; //Pin for coil 2 + pinCoil3 = 40; //Pin for coil 3 + pinCoil4 = 36; //Pin for coil 4 + pinTrigger = 20; //The CAS pin + pinTrigger2 = 21; //The Cam Sensor pin + pinTPS = A2; //TPS input pin + pinMAP = A3; //MAP sensor pin + pinIAT = A0; //IAT sensor pin + pinCLT = A1; //CLS sensor pin + pinO2 = A8; //O2 Sensor pin + pinBat = A4; //O2 Sensor pin + pinDisplayReset = 48; // OLED reset pin + break; + case 2: + //Pin mappings as per the v0.3 shield + pinInjector1 = 8; //Output pin injector 1 is on + pinInjector2 = 9; //Output pin injector 2 is on + pinInjector3 = 10; //Output pin injector 3 is on + pinInjector4 = 11; //Output pin injector 4 is on + pinCoil1 = 28; //Pin for coil 1 + pinCoil2 = 24; //Pin for coil 2 + pinCoil3 = 40; //Pin for coil 3 + pinCoil4 = 36; //Pin for coil 4 + pinTrigger = 18; //The CAS pin + pinTrigger2 = 19; //The Cam Sensor pin + pinTPS = A2;//TPS input pin + pinMAP = A3; //MAP sensor pin + pinIAT = A0; //IAT sensor pin + pinCLT = A1; //CLS sensor pin + pinO2 = A8; //O2 Sensor pin + pinBat = A4; //O2 Sensor pin + pinDisplayReset = 48; // OLED reset pin + break; + + default: + //Pin mappings as per the v0.2 shield + pinInjector1 = 8; //Output pin injector 1 is on + pinInjector2 = 9; //Output pin injector 2 is on + pinInjector3 = 10; //Output pin injector 3 is on + pinInjector4 = 11; //Output pin injector 4 is on + pinCoil1 = 28; //Pin for coil 1 + pinCoil2 = 24; //Pin for coil 2 + pinCoil3 = 40; //Pin for coil 3 + pinCoil4 = 36; //Pin for coil 4 + pinTrigger = 20; //The CAS pin + pinTrigger2 = 21; //The Cam Sensor pin + pinTPS = A2; //TPS input pin + pinMAP = A3; //MAP sensor pin + pinIAT = A0; //IAT sensor pin + pinCLT = A1; //CLS sensor pin + pinO2 = A8; //O2 Sensor pin + pinBat = A4; //O2 Sensor pin + pinDisplayReset = 48; // OLED reset pin + break; + } +} + /* The following functions help determine the required fuel constant. For more information about these calculations, please refer to http://www.megamanual.com/v22manual/mfuel.htm Calc below are for metric inputs of temp (degrees C) and MAP (kPa) to produce kg/m3.