From d140cd74ff86c3221db2d8392741312c59b4ee1f Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Wed, 19 Oct 2016 11:00:48 +1100 Subject: [PATCH 01/15] Prevent potential misses caused during initial connection to TS --- comms.ino | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/comms.ino b/comms.ino index dd20fa0..c1e58ff 100644 --- a/comms.ino +++ b/comms.ino @@ -748,9 +748,12 @@ void sendPage(bool useChar) //MS format has origin (0,0) in the bottom left corner, we use the top left for efficiency reasons byte response[map_page_size]; - for (int x = 0; x < 256; x++) { response[x] = currentTable.values[15 - x / 16][x % 16]; } //This is slightly non-intuitive, but essentially just flips the table vertically (IE top line becomes the bottom line etc). Columns are unchanged + for (int x = 0; x < 256; x++) { response[x] = currentTable.values[15 - x / 16][x % 16]; if ( (x & 31) == 1) { loop(); } } //This is slightly non-intuitive, but essentially just flips the table vertically (IE top line becomes the bottom line etc). Columns are unchanged + loop(); for (int x = 256; x < 272; x++) { response[x] = byte(currentTable.axisX[(x - 256)] / 100); } //RPM Bins for VE table (Need to be dvidied by 100) + loop(); for (int y = 272; y < 288; y++) { response[y] = byte(currentTable.axisY[15 - (y - 272)]); } //MAP or TPS bins for VE table + loop(); Serial.write((byte *)&response, sizeof(response)); } } @@ -773,6 +776,7 @@ void sendPage(bool useChar) for (byte x = 0; x < page_size; x++) { response[x] = *((byte *)pnt_configPage + x); //Each byte is simply the location in memory of the configPage + the offset + the variable number (x) + if ( (x & 31) == 1) { loop(); } } Serial.write((byte *)&response, sizeof(response)); // } From a4593ae3395ce2644fbf1d85713f2c87fdfafeba Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Wed, 19 Oct 2016 13:12:08 +1100 Subject: [PATCH 02/15] Better tooth log handling --- comms.ino | 7 ++++--- decoders.h | 1 + decoders.ino | 14 +++++++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/comms.ino b/comms.ino index c1e58ff..42f59fc 100644 --- a/comms.ino +++ b/comms.ino @@ -661,7 +661,7 @@ void sendPage(bool useChar) } case seqFuelPage: { - byte response[200]; //Bit hacky, but the size is: (8x8 + 8 + 8) + (8x8 + 8 + 8) = 160 + byte response[200]; //The size is: (6x6 + 6 + 6) * 4 + 8 (Leftover values) for (int x = 0; x < 200; x++) { 0; } @@ -748,7 +748,7 @@ void sendPage(bool useChar) //MS format has origin (0,0) in the bottom left corner, we use the top left for efficiency reasons byte response[map_page_size]; - for (int x = 0; x < 256; x++) { response[x] = currentTable.values[15 - x / 16][x % 16]; if ( (x & 31) == 1) { loop(); } } //This is slightly non-intuitive, but essentially just flips the table vertically (IE top line becomes the bottom line etc). Columns are unchanged + for (int x = 0; x < 256; x++) { response[x] = currentTable.values[15 - x / 16][x % 16]; if ( (x & 15) == 1) { loop(); } } //This is slightly non-intuitive, but essentially just flips the table vertically (IE top line becomes the bottom line etc). Columns are unchanged. Every 16 loops, manually call loop() to avoid potential misses loop(); for (int x = 256; x < 272; x++) { response[x] = byte(currentTable.axisX[(x - 256)] / 100); } //RPM Bins for VE table (Need to be dvidied by 100) loop(); @@ -776,7 +776,7 @@ void sendPage(bool useChar) for (byte x = 0; x < page_size; x++) { response[x] = *((byte *)pnt_configPage + x); //Each byte is simply the location in memory of the configPage + the offset + the variable number (x) - if ( (x & 31) == 1) { loop(); } + if ( (x & 31) == 1) { loop(); } //Every 32 loops, do a manual call to loop() to ensure that there is no misses } Serial.write((byte *)&response, sizeof(response)); // } @@ -915,6 +915,7 @@ void sendToothLog(bool useChar) } BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_TOOTHLOG1READY); } + toothLogRead = true; } void testComm() diff --git a/decoders.h b/decoders.h index c2185a5..de07111 100644 --- a/decoders.h +++ b/decoders.h @@ -18,6 +18,7 @@ volatile unsigned long toothOneMinusOneTime = 0; //The 2nd to last time (micros( volatile bool revolutionOne = 0; // For sequential operation, this tracks whether the current revolution is 1 or 2 (not 1) volatile unsigned int toothHistory[TOOTH_LOG_BUFFER]; volatile unsigned int toothHistoryIndex = 0; +volatile bool toothLogRead = false; //Flag to indicate whether the current tooth log values have been read out yet volatile byte secondaryToothCount; //Used for identifying the current secondary (Usually cam) tooth for patterns with multiple secondary teeth volatile unsigned long secondaryLastToothTime = 0; //The time (micros()) that the last tooth was registered (Cam input) diff --git a/decoders.ino b/decoders.ino index d2db252..734db7e 100644 --- a/decoders.ino +++ b/decoders.ino @@ -21,12 +21,19 @@ toothLastToothTime - The time (In uS) that the last primary tooth was 'seen' */ -static inline void addToothLogEntry(unsigned long time) +static inline void addToothLogEntry(unsigned long toothTime) { //High speed tooth logging history - toothHistory[toothHistoryIndex] = time; + toothHistory[toothHistoryIndex] = toothTime; if(toothHistoryIndex == (TOOTH_LOG_BUFFER-1)) - { toothHistoryIndex = 0; BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_TOOTHLOG1READY); } //The tooth log ready bit is cleared to ensure that we only get a set of concurrent values. + { + if (toothLogRead) + { + toothHistoryIndex = 0; + BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_TOOTHLOG1READY); + toothLogRead = false; //The tooth log ready bit is cleared to ensure that we only get a set of concurrent values. + } + } else { toothHistoryIndex++; } } @@ -106,6 +113,7 @@ void triggerPri_missingTooth() if ( curGap > targetGap || toothCurrentCount > triggerActualTeeth) { + if(toothCurrentCount < (triggerActualTeeth) && currentStatus.hasSync) { currentStatus.hasSync = false; return; } //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. toothCurrentCount = 1; revolutionOne = !revolutionOne; //Flip sequential revolution tracker toothOneMinusOneTime = toothOneTime; From 1f87c31e0109782261e72afa46f16b6d1cf6d4a4 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Tue, 25 Oct 2016 17:31:44 +1100 Subject: [PATCH 03/15] Load and save routines for the 4 fuel trim tables --- reference/speeduino.ini | 91 ++++++++++++++++++++++------- speeduino.ino | 23 +++++++- storage.h | 73 ++++++++++++++--------- storage.ino | 126 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 266 insertions(+), 47 deletions(-) diff --git a/reference/speeduino.ini b/reference/speeduino.ini index 05da121..100cc25 100644 --- a/reference/speeduino.ini +++ b/reference/speeduino.ini @@ -496,7 +496,15 @@ page = 9 fuelTrim4loadBins = array, U08, 186,[ 6], "TPS", 1.0, 0.0, 0.0, 255.0, 0 #endif - unused9-192 = scalar, U08, 192, "RPM", 100.0, 0.0, 100, 25500, 0 + fuelTrimEnabled = bits, U08, 192, [0:0], "No", "Yes" + unused9-192b = bits, U08, 192, [1:1], "No", "Yes" + unused9-192c = bits, U08, 192, [2:2], "No", "Yes" + unused9-192d = bits, U08, 192, [3:3], "No", "Yes" + unused9-192e = bits, U08, 192, [4:4], "No", "Yes" + unused9-192f = bits, U08, 192, [5:5], "No", "Yes" + unused9-192g = bits, U08, 192, [6:6], "No", "Yes" + unused9-192h = bits, U08, 192, [7:7], "No", "Yes" + unused9-193 = scalar, U08, 193, "RPM", 100.0, 0.0, 100, 25500, 0 unused9-194 = scalar, U08, 194, "RPM", 100.0, 0.0, 100, 25500, 0 unused9-195 = scalar, U08, 195, "RPM", 100.0, 0.0, 100, 25500, 0 @@ -1000,13 +1008,13 @@ menuDialog = main ;Fuel trim composite dialog dialog = inj_trim1TblTitle, "Channel #1" - panel = fuelTrimTable1Tbl, Center + panel = fuelTrimTable1Tbl, Center, { fuelTrimEnabled } dialog = inj_trim2TblTitle, "Channel #2" - panel = fuelTrimTable1Tbl + panel = fuelTrimTable2Tbl, { fuelTrimEnabled } dialog = inj_trim3TblTitle, "Channel #3" - panel = fuelTrimTable1Tbl + panel = fuelTrimTable3Tbl, { fuelTrimEnabled } dialog = inj_trim4TblTitle, "Channel #4" - panel = fuelTrimTable1Tbl + panel = fuelTrimTable4Tbl, { fuelTrimEnabled } dialog = inj_trimadt, "", xAxis panel = inj_trim1TblTitle @@ -1016,9 +1024,9 @@ menuDialog = main panel = inj_trim4TblTitle dialog = inj_trimad,"Injector Cyl 1-4 Trims", yAxis - topicHelp = "file://$getProjectsDirPath()/docs/Megasquirt3_TunerStudio_MS_Lite_Reference-1.4.pdf#injtrim1-4" - panel = inj_trimadt - panel = inj_trimadb + field = "Individual fuel trim enabled", fuelTrimEnabled + panel = inj_trimadt, North + panel = inj_trimadb, South ;------------------------------------------------------------------------------- ; General help text @@ -1198,19 +1206,62 @@ menuDialog = main upDownLabel = "HIGHER", "LOWER" ;--------- Sequential fuel trim maps ----------- - table = fuelTrimTable1Tbl, fuelTrimTable1Map, "Fuel trim Table", 9 - topicHelp = "http://speeduino.com/wiki/index.php/Tuning" - xBins = fuelTrim1rpmBins, rpm - #if SPEED_DENSITY - yBins = fuelTrim1loadBins, map - #else - yBins = fuelTrim1loadBins, throttle - #endif - zBins = fuelTrim1Table + table = fuelTrimTable1Tbl, fuelTrimTable1Map, "Fuel trim Table", 9 + topicHelp = "http://speeduino.com/wiki/index.php/Tuning" + xBins = fuelTrim1rpmBins, rpm + #if SPEED_DENSITY + yBins = fuelTrim1loadBins, map + #else + yBins = fuelTrim1loadBins, throttle + #endif + zBins = fuelTrim1Table - gridHeight = 2.0 - gridOrient = 250, 0, 340 ; Space 123 rotation of grid in degrees. - upDownLabel = "(RICHER)", "(LEANER)" + gridHeight = 2.0 + gridOrient = 250, 0, 340 ; Space 123 rotation of grid in degrees. + upDownLabel = "(RICHER)", "(LEANER)" + + table = fuelTrimTable2Tbl, fuelTrimTable2Map, "Fuel trim Table", 9 + topicHelp = "http://speeduino.com/wiki/index.php/Tuning" + xBins = fuelTrim2rpmBins, rpm + #if SPEED_DENSITY + yBins = fuelTrim2loadBins, map + #else + yBins = fuelTrim2loadBins, throttle + #endif + zBins = fuelTrim2Table + + gridHeight = 2.0 + gridOrient = 250, 0, 340 ; Space 123 rotation of grid in degrees. + upDownLabel = "(RICHER)", "(LEANER)" + + table = fuelTrimTable3Tbl, fuelTrimTable3Map, "Fuel trim Table", 9 + topicHelp = "http://speeduino.com/wiki/index.php/Tuning" + xBins = fuelTrim3rpmBins, rpm + #if SPEED_DENSITY + yBins = fuelTrim3loadBins, map + #else + yBins = fuelTrim3loadBins, throttle + #endif + zBins = fuelTrim3Table + + gridHeight = 2.0 + gridOrient = 250, 0, 340 ; Space 123 rotation of grid in degrees. + upDownLabel = "(RICHER)", "(LEANER)" + + table = fuelTrimTable4Tbl, fuelTrimTable4Map, "Fuel trim Table", 9 + topicHelp = "http://speeduino.com/wiki/index.php/Tuning" + xBins = fuelTrim4rpmBins, rpm + #if SPEED_DENSITY + yBins = fuelTrim4loadBins, map + #else + yBins = fuelTrim4loadBins, throttle + #endif + zBins = fuelTrim4Table + + gridHeight = 2.0 + gridOrient = 250, 0, 340 ; Space 123 rotation of grid in degrees. + upDownLabel = "(RICHER)", "(LEANER)" + ;------------------------------------------------------------------------------- diff --git a/speeduino.ino b/speeduino.ino index 528a541..59f22f0 100644 --- a/speeduino.ino +++ b/speeduino.ino @@ -74,6 +74,10 @@ struct table3D ignitionTable; //16x16 ignition map struct table3D afrTable; //16x16 afr target map struct table3D boostTable; //8x8 boost map struct table3D vvtTable; //8x8 vvt map +struct table3D trim1Table; //6x6 Fuel trim 1 map +struct table3D trim2Table; //6x6 Fuel trim 2 map +struct table3D trim3Table; //6x6 Fuel trim 3 map +struct table3D trim4Table; //6x6 Fuel trim 4 map struct table2D taeTable; //4 bin TPS Acceleration Enrichment map (2D) struct table2D WUETable; //10 bin Warm Up Enrichment map (2D) struct table2D dwellVCorrectionTable; //6 bin dwell voltage correction (2D) @@ -163,6 +167,10 @@ void setup() table3D_setSize(&afrTable, 16); table3D_setSize(&boostTable, 8); table3D_setSize(&vvtTable, 8); + table3D_setSize(&trim1Table, 6); + table3D_setSize(&trim2Table, 6); + table3D_setSize(&trim3Table, 6); + table3D_setSize(&trim4Table, 6); loadConfig(); @@ -738,6 +746,19 @@ void setup() ign5EndFunction = endCoil5Charge; } break; + + case IGN_MODE_SEQUENTIAL: + ign1StartFunction = beginCoil1Charge; + ign1EndFunction = endCoil1Charge; + ign2StartFunction = beginCoil2Charge; + ign2EndFunction = endCoil2Charge; + ign3StartFunction = beginCoil3Charge; + ign3EndFunction = endCoil3Charge; + ign4StartFunction = beginCoil4Charge; + ign4EndFunction = endCoil4Charge; + ign5StartFunction = beginCoil5Charge; + ign5EndFunction = endCoil5Charge; + break; default: //Wasted spark (Shouldn't ever happen anyway) @@ -873,7 +894,7 @@ void loop() //And check whether the tooth log buffer is ready if(toothHistoryIndex > TOOTH_LOG_SIZE) { BIT_SET(currentStatus.squirt, BIT_SQUIRT_TOOTHLOG1READY); } } - + if(toothHistoryIndex > TOOTH_LOG_SIZE) { BIT_SET(currentStatus.squirt, BIT_SQUIRT_TOOTHLOG1READY); } //The IAT and CLT readings can be done less frequently. This still runs about 4 times per second if ((mainLoopCount & 255) == 1) { diff --git a/storage.h b/storage.h index 0ec4fad..3f562ed 100644 --- a/storage.h +++ b/storage.h @@ -39,40 +39,61 @@ Current layout of EEPROM data (Version 3) is as follows (All sizes are in bytes) ----------------------------------------------------- */ -#define EEPROM_CONFIG1_XSIZE 1 -#define EEPROM_CONFIG1_YSIZE 2 -#define EEPROM_CONFIG1_MAP 3 -#define EEPROM_CONFIG1_XBINS 259 -#define EEPROM_CONFIG1_YBINS 275 -#define EEPROM_CONFIG2_START 291 -#define EEPROM_CONFIG2_END 355 // +64 131 -#define EEPROM_CONFIG3_XSIZE 355 -#define EEPROM_CONFIG3_YSIZE 356 -#define EEPROM_CONFIG3_MAP 357 -#define EEPROM_CONFIG3_XBINS 613 -#define EEPROM_CONFIG3_YBINS 629 -#define EEPROM_CONFIG4_START 645 -#define EEPROM_CONFIG4_END 709 -#define EEPROM_CONFIG5_XSIZE 709 -#define EEPROM_CONFIG5_YSIZE 710 -#define EEPROM_CONFIG5_MAP 711 -#define EEPROM_CONFIG5_XBINS 967 -#define EEPROM_CONFIG5_YBINS 983 -#define EEPROM_CONFIG6_START 999 -#define EEPROM_CONFIG6_END 1063 -#define EEPROM_CONFIG7_START 1063 -#define EEPROM_CONFIG7_END 1127 +#define EEPROM_CONFIG1_XSIZE 1 +#define EEPROM_CONFIG1_YSIZE 2 +#define EEPROM_CONFIG1_MAP 3 +#define EEPROM_CONFIG1_XBINS 259 +#define EEPROM_CONFIG1_YBINS 275 +#define EEPROM_CONFIG2_START 291 +#define EEPROM_CONFIG2_END 355 // +64 131 +#define EEPROM_CONFIG3_XSIZE 355 +#define EEPROM_CONFIG3_YSIZE 356 +#define EEPROM_CONFIG3_MAP 357 +#define EEPROM_CONFIG3_XBINS 613 +#define EEPROM_CONFIG3_YBINS 629 +#define EEPROM_CONFIG4_START 645 +#define EEPROM_CONFIG4_END 709 +#define EEPROM_CONFIG5_XSIZE 709 +#define EEPROM_CONFIG5_YSIZE 710 +#define EEPROM_CONFIG5_MAP 711 +#define EEPROM_CONFIG5_XBINS 967 +#define EEPROM_CONFIG5_YBINS 983 +#define EEPROM_CONFIG6_START 999 +#define EEPROM_CONFIG6_END 1063 +#define EEPROM_CONFIG7_START 1063 +#define EEPROM_CONFIG7_END 1127 #define EEPROM_CONFIG8_XSIZE1 1127 #define EEPROM_CONFIG8_YSIZE1 1128 -#define EEPROM_CONFIG8_MAP1 1129 +#define EEPROM_CONFIG8_MAP1 1129 #define EEPROM_CONFIG8_XBINS1 1193 #define EEPROM_CONFIG8_YBINS1 1201 #define EEPROM_CONFIG8_XSIZE2 1209 #define EEPROM_CONFIG8_YSIZE2 1210 -#define EEPROM_CONFIG8_MAP2 1211 +#define EEPROM_CONFIG8_MAP2 1211 #define EEPROM_CONFIG8_XBINS2 1275 #define EEPROM_CONFIG8_YBINS2 1283 -#define EEPROM_CONFIG8_END 1291 +#define EEPROM_CONFIG8_END 1291 +#define EEPROM_CONFIG9_XSIZE1 1291 +#define EEPROM_CONFIG9_YSIZE1 1292 +#define EEPROM_CONFIG9_MAP1 1293 +#define EEPROM_CONFIG9_XBINS1 1329 +#define EEPROM_CONFIG9_YBINS1 1335 +#define EEPROM_CONFIG9_XSIZE2 1341 +#define EEPROM_CONFIG9_YSIZE2 1342 +#define EEPROM_CONFIG9_MAP2 1343 +#define EEPROM_CONFIG9_XBINS2 1379 +#define EEPROM_CONFIG9_YBINS2 1385 +//BELOW VALUES NOT YET RIGHT!! +#define EEPROM_CONFIG9_XSIZE3 1341 +#define EEPROM_CONFIG9_YSIZE3 1342 +#define EEPROM_CONFIG9_MAP3 1343 +#define EEPROM_CONFIG9_XBINS3 1379 +#define EEPROM_CONFIG9_YBINS3 1385 +#define EEPROM_CONFIG9_XSIZE4 1341 +#define EEPROM_CONFIG9_YSIZE4 1342 +#define EEPROM_CONFIG9_MAP4 1343 +#define EEPROM_CONFIG9_XBINS4 1379 +#define EEPROM_CONFIG9_YBINS4 1385 //Calibration data is stored at the end of the EEPROM (This is in case any further calibration tables are needed as they are large blocks) #define EEPROM_CALIBRATION_O2 2559 diff --git a/storage.ino b/storage.ino index 54ae45d..dc7f013 100644 --- a/storage.ino +++ b/storage.ino @@ -196,6 +196,74 @@ void writeConfig() if(EEPROM.read(y) != vvtTable.axisY[offset]) { EEPROM.write(y, vvtTable.axisY[offset]); } y++; } + + /*--------------------------------------------------- + | Fuel trim tables (See storage.h for data layout) - Page 9 + | 6x6 tables itself + the 6 values along each of the axis + -----------------------------------------------------*/ + //Begin writing the 2 tables, basically the same thing as above but we're doing these 2 together (2 tables per page instead of 1) + EEPROM.update(EEPROM_CONFIG9_XSIZE1,trim1Table.xSize); //Write the boost Table RPM dimension size + EEPROM.update(EEPROM_CONFIG9_YSIZE1,trim1Table.ySize); //Write the boost Table MAP/TPS dimension size + EEPROM.update(EEPROM_CONFIG9_XSIZE2,trim2Table.xSize); //Write the boost Table RPM dimension size + EEPROM.update(EEPROM_CONFIG9_YSIZE2,trim2Table.ySize); //Write the boost Table MAP/TPS dimension size + EEPROM.update(EEPROM_CONFIG9_XSIZE3,trim3Table.xSize); //Write the boost Table RPM dimension size + EEPROM.update(EEPROM_CONFIG9_YSIZE3,trim3Table.ySize); //Write the boost Table MAP/TPS dimension size + EEPROM.update(EEPROM_CONFIG9_XSIZE4,trim4Table.xSize); //Write the boost Table RPM dimension size + EEPROM.update(EEPROM_CONFIG9_YSIZE4,trim4Table.ySize); //Write the boost Table MAP/TPS dimension size + + y = EEPROM_CONFIG9_MAP2; //We do the 4 maps together in the same loop + int z = EEPROM_CONFIG9_MAP3; //We do the 4 maps together in the same loop + int i = EEPROM_CONFIG9_MAP4; //We do the 4 maps together in the same loop + for(int x=EEPROM_CONFIG9_MAP1; x Date: Tue, 25 Oct 2016 23:35:39 +1100 Subject: [PATCH 04/15] Revert "do while loop" This reverts commit 7c91a0bbb91a057e3e056f19df91eee9dae4949c. --- speeduino.ino | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/speeduino.ino b/speeduino.ino index b5ef973..4e17552 100644 --- a/speeduino.ino +++ b/speeduino.ino @@ -772,8 +772,6 @@ void setup() } void loop() -{ -do { mainLoopCount++; //Check for any requets from serial. Serial operations are checked under 2 scenarios: @@ -1405,8 +1403,7 @@ do } - }while(1); //Some tests result this in a 1.2% faster at 8500RPM -} + } //************************************************************************************************ //Interrupts From 1a5635d7954ad130796b68e86c5277efecb7e774 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Wed, 26 Oct 2016 00:24:40 +1100 Subject: [PATCH 05/15] Store previous baro value in EEPROM. Having this in a variable is insufficient --- speeduino.ino | 9 +++++---- storage.h | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/speeduino.ino b/speeduino.ino index eb91e56..256f7c7 100644 --- a/speeduino.ino +++ b/speeduino.ino @@ -100,7 +100,6 @@ unsigned long previousLoopTime; //The time the previous loop started (uS) unsigned long MAPrunningValue; //Used for tracking either the total of all MAP readings in this cycle (Event average) or the lowest value detected in this cycle (event minimum) unsigned int MAPcount; //Number of samples taken in the current MAP cycle byte MAPcurRev = 0; //Tracks which revolution we're sampling on -int LastBaro; //Used for ignore correction if powered on a ruuning engine int CRANK_ANGLE_MAX = 720; int CRANK_ANGLE_MAX_IGN = 360, CRANK_ANGLE_MAX_INJ = 360; // The number of crank degrees that the system track over. 360 for wasted / timed batch and 720 for sequential @@ -234,9 +233,11 @@ void setup() * The lowest measurable sea-level pressure is found at the centers of tropical cyclones and tornadoes, with a record low of 87 kPa; */ if ((currentStatus.MAP >= 87) && (currentStatus.MAP <= 108)) //Check if engine isn't running - LastBaro = currentStatus.baro = currentStatus.MAP; - else - currentStatus.baro = LastBaro; //last baro correction + { + currentStatus.baro = currentStatus.MAP; + EEPROM.update(EEPROM_LAST_BARO, currentStatus.baro); + } + else { currentStatus.baro = EEPROM.read(EEPROM_LAST_BARO); //last baro correction } //Perform all initialisations initialiseSchedulers(); diff --git a/storage.h b/storage.h index 3f562ed..d929aff 100644 --- a/storage.h +++ b/storage.h @@ -96,6 +96,7 @@ Current layout of EEPROM data (Version 3) is as follows (All sizes are in bytes) #define EEPROM_CONFIG9_YBINS4 1385 //Calibration data is stored at the end of the EEPROM (This is in case any further calibration tables are needed as they are large blocks) +#define EEPROM_LAST_BARO 2558 #define EEPROM_CALIBRATION_O2 2559 #define EEPROM_CALIBRATION_IAT 3071 #define EEPROM_CALIBRATION_CLT 3583 From 2af90436c1612c0157796e4a6c1f1851b66c54f6 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Wed, 26 Oct 2016 00:33:19 +1100 Subject: [PATCH 06/15] Fix type corrections that were overwritten --- globals.h | 2 +- sensors.h | 2 ++ sensors.ino | 2 -- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/globals.h b/globals.h index ccf3051..a7f2006 100644 --- a/globals.h +++ b/globals.h @@ -147,7 +147,7 @@ struct statuses { unsigned int PW; //In uS volatile byte runSecs; //Counter of seconds since cranking commenced (overflows at 255 obviously) volatile byte secl; //Continous - volatile int loopsPerSecond; + volatile unsigned int loopsPerSecond; boolean launchingSoft; //True when in launch control soft limit mode boolean launchingHard; //True when in launch control hard limit mode int freeRAM; diff --git a/sensors.h b/sensors.h index 5d87415..a5ae7cf 100644 --- a/sensors.h +++ b/sensors.h @@ -21,4 +21,6 @@ volatile byte flexCounter = 0; void instanteneousMAPReading(); void readMAP(); +unsigned int tempReading; + #endif // SENSORS_H diff --git a/sensors.ino b/sensors.ino index c320e9c..3b1eb66 100644 --- a/sensors.ino +++ b/sensors.ino @@ -4,8 +4,6 @@ Copyright (C) Josh Stewart A full copy of the license may be found in the projects root directory */ -int tempReading; - void instanteneousMAPReading() { //Instantaneous MAP readings From 3bdeec43f50f2f2be6740c792bcfcaa48fdb35d1 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Wed, 26 Oct 2016 00:37:26 +1100 Subject: [PATCH 07/15] I'm reverting these changes as there is no benefit to them. The lines are written this way for clarity as both the 16 and the 2 have specific meanings (See comment) --- auxiliaries.ino | 5 ++--- idle.ino | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/auxiliaries.ino b/auxiliaries.ino index 14c3d70..17e4673 100644 --- a/auxiliaries.ino +++ b/auxiliaries.ino @@ -35,9 +35,8 @@ void initialiseAuxPWM() vvt_pin_port = portOutputRegister(digitalPinToPort(pinVVT_1)); vvt_pin_mask = digitalPinToBitMask(pinVVT_1); - //(16 * configPage3.boostFreq * 2) = (configPage3.boostFreq * 16 * 2) = (configPage3.boostFreq * 32) = (configPage3.boostFreq << 5) - boost_pwm_max_count = 1000000L / (configPage3.boostFreq << 5); //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) to allow freqneucies up to 511Hz - vvt_pwm_max_count = 1000000L / (configPage3.vvtFreq << 5); //Converts the frequency in Hz to the number of ticks (at 16uS) it takes to complete 1 cycle + 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) to allow freqneucies up to 511Hz + 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) //Shouldn't be needed with closed loop as its turned on below TIMSK1 |= (1 << OCIE1B); //Turn on the B compare unit (ie turn on the interrupt) diff --git a/idle.ino b/idle.ino index 79eedb9..cefb7b6 100644 --- a/idle.ino +++ b/idle.ino @@ -52,8 +52,7 @@ void initialiseIdle() idle_pin_mask = digitalPinToBitMask(pinIdle1); idle2_pin_port = portOutputRegister(digitalPinToPort(pinIdle2)); idle2_pin_mask = digitalPinToBitMask(pinIdle2); - //(16 * configPage3.idleFreq * 2) = (configPage3.idleFreq * 16 * 2) = (configPage3.idleFreq * 32) = (configPage3.idleFreq << 5) - idle_pwm_max_count = 1000000L / (configPage3.idleFreq << 5); //Converts the frequency in Hz to the number of ticks (at 16uS) it takes to complete 1 cycle. Note that the frequency is divided by 2 coming from TS to allow for up to 512hz + idle_pwm_max_count = 1000000L / (16 * configPage3.idleFreq * 2); //Converts the frequency in Hz to the number of ticks (at 16uS) it takes to complete 1 cycle. Note that the frequency is divided by 2 coming from TS to allow for up to 512hz enableIdle(); break; From 6e50a6fc57a8be6645363ed44ee1031c33ddfc46 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Wed, 26 Oct 2016 00:42:20 +1100 Subject: [PATCH 08/15] Updates per style guide --- idle.ino | 2 +- table.ino | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/idle.ino b/idle.ino index cefb7b6..3b8e431 100644 --- a/idle.ino +++ b/idle.ino @@ -72,7 +72,7 @@ void initialiseIdle() idle_pin_mask = digitalPinToBitMask(pinIdle1); idle2_pin_port = portOutputRegister(digitalPinToPort(pinIdle2)); idle2_pin_mask = digitalPinToBitMask(pinIdle2); - idle_pwm_max_count = 1000000L / (configPage3.idleFreq << 5); //Converts the frequency in Hz to the number of ticks (at 16uS) it takes to complete 1 cycle. Note that the frequency is divided by 2 coming from TS to allow for up to 512hz + idle_pwm_max_count = 1000000L / (16 * configPage3.idleFreq * 2); //Converts the frequency in Hz to the number of ticks (at 16uS) it takes to complete 1 cycle. Note that the frequency is divided by 2 coming from TS to allow for up to 512hz idlePID.SetOutputLimits(0, idle_pwm_max_count); idlePID.SetTunings(configPage3.idleKP, configPage3.idleKI, configPage3.idleKD); idlePID.SetMode(AUTOMATIC); //Turn PID on diff --git a/table.ino b/table.ino index 0a56176..f277032 100644 --- a/table.ino +++ b/table.ino @@ -362,16 +362,12 @@ int get3DTableValue(struct table3D *fromTable, int Y, int X) //Initial check incase the values were hit straight on long p; - if (xMaxValue == xMinValue) - p = ((long)(X - xMinValue) << 8); //This only occurs if the requested X value was equal to one of the X axis bins - else - p = ((long)(X - xMinValue) << 8) / (xMaxValue - xMinValue); //This is the standard case + if (xMaxValue == xMinValue) { p = ((long)(X - xMinValue) << 8); } //This only occurs if the requested X value was equal to one of the X axis bins + else { p = ((long)(X - xMinValue) << 8) / (xMaxValue - xMinValue); } //This is the standard case long q; - if (yMaxValue == yMinValue) - q = ((long)(Y - yMinValue) << 8); - else - q = 256 - (((long)(Y - yMaxValue) << 8) / (yMinValue - yMaxValue)); + if (yMaxValue == yMinValue) { q = ((long)(Y - yMinValue) << 8); } + else { q = 256 - (((long)(Y - yMaxValue) << 8) / (yMinValue - yMaxValue)); } int m = ((256-p) * (256-q)) >> 8; int n = (p * (256-q)) >> 8; From 991f7c17718495f44d529d40b995fff1bfaed275 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Wed, 26 Oct 2016 01:04:37 +1100 Subject: [PATCH 09/15] Number of scope check fixes --- auxiliaries.h | 1 + corrections.h | 2 ++ sensors.h | 1 + sensors.ino | 2 +- speeduino.ino | 20 ++++++++++---------- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/auxiliaries.h b/auxiliaries.h index 42cdf2a..6168e6c 100644 --- a/auxiliaries.h +++ b/auxiliaries.h @@ -4,6 +4,7 @@ void initialiseAuxPWM(); void boostControl(); void vvtControl(); +void initialiseFan(); volatile byte *boost_pin_port; volatile byte boost_pin_mask; diff --git a/corrections.h b/corrections.h index 5344257..134a731 100644 --- a/corrections.h +++ b/corrections.h @@ -5,6 +5,8 @@ All functions in the gamma file return #ifndef CORRECTIONS_H #define CORRECTIONS_H +void initialiseCorrections(); + byte correctionsTotal(); byte correctionWUE(); //Warmup enrichment byte correctionASE(); //After Start Enrichment diff --git a/sensors.h b/sensors.h index a5ae7cf..00b7d4f 100644 --- a/sensors.h +++ b/sensors.h @@ -20,6 +20,7 @@ volatile byte flexCounter = 0; void instanteneousMAPReading(); void readMAP(); +void flexPulse(); unsigned int tempReading; diff --git a/sensors.ino b/sensors.ino index 3b1eb66..5578ac2 100644 --- a/sensors.ino +++ b/sensors.ino @@ -139,7 +139,7 @@ void readBat() * The interrupt function for reading the flex sensor frequency * This value is incremented with every pulse and reset back to 0 once per second */ - void flexPulse() +void flexPulse() { ++flexCounter; } diff --git a/speeduino.ino b/speeduino.ino index 256f7c7..7e67feb 100644 --- a/speeduino.ino +++ b/speeduino.ino @@ -209,18 +209,18 @@ void setup() //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; } else { coilHIGH = HIGH, coilLOW = LOW; } - endCoil1Charge(); - endCoil2Charge(); - endCoil3Charge(); - endCoil4Charge(); - endCoil5Charge(); + digitalWrite(pinCoil1, coilLOW); + digitalWrite(pinCoil2, coilLOW); + digitalWrite(pinCoil3, coilLOW); + digitalWrite(pinCoil4, coilLOW); + digitalWrite(pinCoil5, coilLOW); //Similar for injectors, make sure they're turned off - closeInjector1(); - closeInjector2(); - closeInjector3(); - closeInjector4(); - closeInjector5(); + digitalWrite(pinInjector1, HIGH); + digitalWrite(pinInjector2, HIGH); + digitalWrite(pinInjector3, HIGH); + digitalWrite(pinInjector4, HIGH); + digitalWrite(pinInjector5, HIGH); //Set the tacho output default state digitalWrite(pinTachOut, HIGH); From 1d699d18bc25126498d1c10bbbb9a4a971cf6517 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Wed, 26 Oct 2016 01:07:47 +1100 Subject: [PATCH 10/15] Fix injector start state being the wrong way in previous commit --- speeduino.ino | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/speeduino.ino b/speeduino.ino index 7e67feb..be0a02a 100644 --- a/speeduino.ino +++ b/speeduino.ino @@ -216,11 +216,11 @@ void setup() digitalWrite(pinCoil5, coilLOW); //Similar for injectors, make sure they're turned off - digitalWrite(pinInjector1, HIGH); - digitalWrite(pinInjector2, HIGH); - digitalWrite(pinInjector3, HIGH); - digitalWrite(pinInjector4, HIGH); - digitalWrite(pinInjector5, HIGH); + digitalWrite(pinInjector1, LOW); + digitalWrite(pinInjector2, LOW); + digitalWrite(pinInjector3, LOW); + digitalWrite(pinInjector4, LOW); + digitalWrite(pinInjector5, LOW); //Set the tacho output default state digitalWrite(pinTachOut, HIGH); From 2b902edc75961541d1b6d187cdf992a27986cfef Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Wed, 26 Oct 2016 10:21:46 +1100 Subject: [PATCH 11/15] Function prototypes for decoders --- decoders.h | 21 ++++++++++++++++++++- decoders.ino | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/decoders.h b/decoders.h index de07111..797077a 100644 --- a/decoders.h +++ b/decoders.h @@ -1,5 +1,24 @@ +#ifndef DECODERS_H +#define DECODERS_H + #include +static inline void addToothLogEntry(unsigned long toothTime); +static inline int stdGetRPM(); +static inline void setFilter(unsigned long curGap); +static inline int crankingGetRPM(byte totalTeeth); +void triggerSetup_missingTooth(); +void triggerPri_missingTooth(); +void triggerSec_missingTooth(); +int getRPM_missingTooth(); +int getCrankAngle_missingTooth(int timePerDegree); +void triggerSetup_DualWheel(); +void triggerPri_DualWheel(); +void triggerSec_DualWheel(); +int getRPM_DualWheel(); +int getCrankAngle_DualWheel(int timePerDegree); + + volatile unsigned long curTime; volatile unsigned long curGap; volatile unsigned long curTime2; @@ -37,4 +56,4 @@ int toothAngles[24]; //An array for storing fixed tooth angles. Currently sized #define LONG 0; #define SHORT 1; - +#endif diff --git a/decoders.ino b/decoders.ino index 734db7e..4d05485 100644 --- a/decoders.ino +++ b/decoders.ino @@ -71,7 +71,7 @@ This gives much more volatile reading, but is quite useful during cranking, part It can only be used on patterns where the teeth are evently spaced It takes an argument of the full (COMPLETE) number of teeth per revolution. For a missing tooth wheel, this is the number if the tooth had NOT been missing (Eg 36-1 = 36) */ -inline int crankingGetRPM(byte totalTeeth) +static inline int crankingGetRPM(byte totalTeeth) { noInterrupts(); revolutionTime = (toothLastToothTime - toothLastMinusOneToothTime) * totalTeeth; From 8d9ff50eaef17dd3b634be15132cb7ac94476fb0 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Wed, 26 Oct 2016 10:30:12 +1100 Subject: [PATCH 12/15] Define the bar max and min values --- sensors.h | 3 +++ speeduino.ino | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/sensors.h b/sensors.h index 00b7d4f..731c852 100644 --- a/sensors.h +++ b/sensors.h @@ -9,6 +9,9 @@ #define ADCFILTER_O2 128 #define ADCFILTER_BAT 128 +#define BARO_MIN 87 +#define BARO_MAX 108 + volatile byte flexCounter = 0; /* diff --git a/speeduino.ino b/speeduino.ino index be0a02a..4f62fad 100644 --- a/speeduino.ino +++ b/speeduino.ino @@ -232,12 +232,12 @@ void setup() * with record highs close to 108.5 kPa. * The lowest measurable sea-level pressure is found at the centers of tropical cyclones and tornadoes, with a record low of 87 kPa; */ - if ((currentStatus.MAP >= 87) && (currentStatus.MAP <= 108)) //Check if engine isn't running + if ((currentStatus.MAP >= BARO_MIN) && (currentStatus.MAP <= BARO_MAX)) //Check if engine isn't running { currentStatus.baro = currentStatus.MAP; EEPROM.update(EEPROM_LAST_BARO, currentStatus.baro); } - else { currentStatus.baro = EEPROM.read(EEPROM_LAST_BARO); //last baro correction } + else { currentStatus.baro = EEPROM.read(EEPROM_LAST_BARO); } //last baro correction //Perform all initialisations initialiseSchedulers(); From 7345b73167912f8905b55cc58bf19290ca540cfc Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Wed, 26 Oct 2016 10:38:39 +1100 Subject: [PATCH 13/15] Add digitalWriteFast to src directory (It's effectively a lib) --- speeduino.ino | 1 + digitalWriteFast.h => src/DigitalWriteFast/digitalWriteFast.h | 0 2 files changed, 1 insertion(+) rename digitalWriteFast.h => src/DigitalWriteFast/digitalWriteFast.h (100%) diff --git a/speeduino.ino b/speeduino.ino index 4f62fad..9bccc6c 100644 --- a/speeduino.ino +++ b/speeduino.ino @@ -38,6 +38,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "fastAnalog.h" #include "sensors.h" #include "src/PID_v1/PID_v1.h" +//#include "src/DigitalWriteFast/digitalWriteFast.h" #include "errors.h" #ifdef __SAM3X8E__ diff --git a/digitalWriteFast.h b/src/DigitalWriteFast/digitalWriteFast.h similarity index 100% rename from digitalWriteFast.h rename to src/DigitalWriteFast/digitalWriteFast.h From 216aec6590e2cc46ce1e2e9249fe92a167d6ae04 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Wed, 26 Oct 2016 10:41:23 +1100 Subject: [PATCH 14/15] Setup math.h properly --- math.h | 96 ++------------------------------------------------------ math.ino | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 94 deletions(-) create mode 100644 math.ino diff --git a/math.h b/math.h index 128ddb9..bf94c51 100644 --- a/math.h +++ b/math.h @@ -1,98 +1,6 @@ #ifndef MATH_H #define MATH_H -//Replace the standard arduino map() function to use the div function instead -int fastMap(unsigned long x, int in_min, int in_max, int out_min, int out_max) -{ - return ldiv( ((x - in_min) * (out_max - out_min)) , (in_max - in_min) ).quot + out_min; - //return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; -} +int fastMap1023toX(unsigned long x, int out_max); -//This is a dedicated function that specifically handles the case of mapping 0-1023 values into a 0 to X range -//This is a common case because it means converting from a standard 10-bit analog input to a byte or 10-bit analog into 0-511 (Eg the temperature readings) -//int fastMap1023toX(unsigned long x, int in_min, int in_max, int out_min, int out_max) -//removed ununsed variables, in_min and out_min is aways 0, in_max is aways 1023 -int fastMap1023toX(unsigned long x, int out_max) -{ - return (x * out_max) >> 10; -} - -/* -The following are all fast versions of specific divisions -Ref: http://www.hackersdelight.org/divcMore.pdf -*/ - -//Unsigned divide by 10 -unsigned int divu10(unsigned int n) { - unsigned long q, r; - q = (n >> 1) + (n >> 2); - q = q + (q >> 4); - q = q + (q >> 8); - q = q + (q >> 16); - q = q >> 3; - r = n - q*10; - return q + ((r + 6) >> 4); -// return q + (r > 9); -} - -//Signed divide by 10 -int divs10(long n) { - long q, r; - n = n + (n>>31 & 9); - q = (n >> 1) + (n >> 2); - q = q + (q >> 4); - q = q + (q >> 8); - q = q + (q >> 16); - q = q >> 3; - r = n - q*10; - return q + ((r + 6) >> 4); -// return q + (r > 9); -} - -//Signed divide by 100 -int divs100(long n) { - return (n / 100); // Amazingly, gcc is producing a better /divide by 100 function than this - long q, r; - n = n + (n>>31 & 99); - q = (n >> 1) + (n >> 3) + (n >> 6) - (n >> 10) + - (n >> 12) + (n >> 13) - (n >> 16); - q = q + (q >> 20); - q = q >> 6; - r = n - q*100; - return q + ((r + 28) >> 7); -// return q + (r > 99); -} - -//Unsigned divide by 100 -unsigned long divu100(unsigned long n) { - //return (n / 100); // No difference with this on/off - unsigned long q, r; - q = (n >> 1) + (n >> 3) + (n >> 6) - (n >> 10) + - (n >> 12) + (n >> 13) - (n >> 16); - q = q + (q >> 20); - q = q >> 6; - r = n - q*100; - return q + ((r + 28) >> 7); -// return q + (r > 99); -} - -//Return x percent of y -//This is a relatively fast approximation of a percentage value. -unsigned long percentage(byte x, unsigned long y) -{ - return (y * x) / 100; //For some reason this is faster - //return divu100(y * x); -} - -/* - * Calculates integer power values. Same as pow() but with ints - */ -inline long powint(int factor, unsigned int exponent) -{ - long product = 1; - while (exponent--) - product *= factor; - return product; -} - -#endif // MATH_H +#endif diff --git a/math.ino b/math.ino new file mode 100644 index 0000000..3237a19 --- /dev/null +++ b/math.ino @@ -0,0 +1,95 @@ + + +//Replace the standard arduino map() function to use the div function instead +int fastMap(unsigned long x, int in_min, int in_max, int out_min, int out_max) +{ + return ldiv( ((x - in_min) * (out_max - out_min)) , (in_max - in_min) ).quot + out_min; + //return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; +} + +//This is a dedicated function that specifically handles the case of mapping 0-1023 values into a 0 to X range +//This is a common case because it means converting from a standard 10-bit analog input to a byte or 10-bit analog into 0-511 (Eg the temperature readings) +//int fastMap1023toX(unsigned long x, int in_min, int in_max, int out_min, int out_max) +//removed ununsed variables, in_min and out_min is aways 0, in_max is aways 1023 +int fastMap1023toX(unsigned long x, int out_max) +{ + return (x * out_max) >> 10; +} + +/* +The following are all fast versions of specific divisions +Ref: http://www.hackersdelight.org/divcMore.pdf +*/ + +//Unsigned divide by 10 +unsigned int divu10(unsigned int n) { + unsigned long q, r; + q = (n >> 1) + (n >> 2); + q = q + (q >> 4); + q = q + (q >> 8); + q = q + (q >> 16); + q = q >> 3; + r = n - q*10; + return q + ((r + 6) >> 4); +// return q + (r > 9); +} + +//Signed divide by 10 +int divs10(long n) { + long q, r; + n = n + (n>>31 & 9); + q = (n >> 1) + (n >> 2); + q = q + (q >> 4); + q = q + (q >> 8); + q = q + (q >> 16); + q = q >> 3; + r = n - q*10; + return q + ((r + 6) >> 4); +// return q + (r > 9); +} + +//Signed divide by 100 +int divs100(long n) { + return (n / 100); // Amazingly, gcc is producing a better /divide by 100 function than this + long q, r; + n = n + (n>>31 & 99); + q = (n >> 1) + (n >> 3) + (n >> 6) - (n >> 10) + + (n >> 12) + (n >> 13) - (n >> 16); + q = q + (q >> 20); + q = q >> 6; + r = n - q*100; + return q + ((r + 28) >> 7); +// return q + (r > 99); +} + +//Unsigned divide by 100 +unsigned long divu100(unsigned long n) { + //return (n / 100); // No difference with this on/off + unsigned long q, r; + q = (n >> 1) + (n >> 3) + (n >> 6) - (n >> 10) + + (n >> 12) + (n >> 13) - (n >> 16); + q = q + (q >> 20); + q = q >> 6; + r = n - q*100; + return q + ((r + 28) >> 7); +// return q + (r > 99); +} + +//Return x percent of y +//This is a relatively fast approximation of a percentage value. +unsigned long percentage(byte x, unsigned long y) +{ + return (y * x) / 100; //For some reason this is faster + //return divu100(y * x); +} + +/* + * Calculates integer power values. Same as pow() but with ints + */ +inline long powint(int factor, unsigned int exponent) +{ + long product = 1; + while (exponent--) + product *= factor; + return product; +} From 0d4994f884a70364236eb2a3f27af862c9db6b72 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Wed, 26 Oct 2016 16:54:06 +1100 Subject: [PATCH 15/15] Create contributing.md --- contributing.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 contributing.md diff --git a/contributing.md b/contributing.md new file mode 100644 index 0000000..28b33e5 --- /dev/null +++ b/contributing.md @@ -0,0 +1,36 @@ +# How to contribute + +The Speeduino project is always looking for new contributors so thanks for your interest in this! + +If you haven't already, jump onto our Slack team as that is where most of the development discussion takes place: https://speeduino.com/forum/app.php/page/slack + +Here are some important resources: + + * [Coding style guide](http://speeduino.com/wiki/index.php/Style_code) + * [Project forum](https://speeduino.com/forum) + * [Slack team](https://speeduino.com/forum/app.php/page/slack) + +## Testing + +All contributions should be in a working, compilable state. If your change does not compile cleanly it will be rejected immediately. + +## Submitting changes + +Please send a [GitHub Pull Request to Speeduino](https://github.com/noisymime/speeduino/pull/new/master) with a clear list of what you've done (read more about [pull requests](http://help.github.com/pull-requests/)). + +Please try to make each pull request atomic, that is, there should be a single defined intent or feature for the pull request. If you are adding multiple features or fixing different bugs, please split these up and submit multiple pull requests. + +Always write a clear log message for your commits. One-line messages are fine for small changes, but bigger changes should look like this: + + $ git commit -m "A brief summary of the commit + > + > A paragraph describing what changed and its impact." + +## Contributor Licensing + +Note that all contributions to the project are made under the Github Contributor Lincensing Agreement: https://cla.github.com/agreement +This ensures that all contributions made to the project are licensed in the same way as the existing work. Such an agreement is not intended to deprive contributors of their copyright, but to protect the project from claims by malicious contributors. + +## Coding conventions + +The coding style guide can be found on the project wiki: http://speeduino.com/wiki/index.php/Style_code