From 940c3a5be778d621194a5f4fa2bf5b4fee4113c1 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Thu, 27 Oct 2016 08:48:44 +1100 Subject: [PATCH] Further memory work on the sequential tables --- comms.ino | 42 +++++++++++++++++++++++++++++------------ globals.h | 8 ++++++-- reference/speeduino.ini | 12 ++++++++---- speeduino.ino | 6 ++++++ table.h | 3 +++ 5 files changed, 53 insertions(+), 18 deletions(-) diff --git a/comms.ino b/comms.ino index 42f59fc2..8cb77e1f 100644 --- a/comms.ino +++ b/comms.ino @@ -286,13 +286,13 @@ void receiveValue(int valueOffset, byte newValue) if (valueOffset < 272) { //X Axis - fuelTable.axisX[(valueOffset - 256)] = ((int)(newValue) * 100); //The RPM values sent by megasquirt are divided by 100, need to multiple it back by 100 to make it correct + fuelTable.axisX[(valueOffset - 256)] = ((int)(newValue) * TABLE_RPM_MULTIPLIER); //The RPM values sent by megasquirt are divided by 100, need to multiple it back by 100 to make it correct (TABLE_RPM_MULTIPLIER) } else { //Y Axis valueOffset = 15 - (valueOffset - 272); //Need to do a translation to flip the order (Due to us using (0,0) in the top left rather than bottom right - fuelTable.axisY[valueOffset] = (int)(newValue); + fuelTable.axisY[valueOffset] = (int)(newValue) * TABLE_LOAD_MULTIPLIER; } return; } @@ -319,13 +319,13 @@ void receiveValue(int valueOffset, byte newValue) if (valueOffset < 272) { //X Axis - ignitionTable.axisX[(valueOffset - 256)] = (int)(newValue) * int(100); //The RPM values sent by megasquirt are divided by 100, need to multiple it back by 100 to make it correct + ignitionTable.axisX[(valueOffset - 256)] = (int)(newValue) * TABLE_RPM_MULTIPLIER; //The RPM values sent by megasquirt are divided by 100, need to multiple it back by 100 to make it correct } else { //Y Axis valueOffset = 15 - (valueOffset - 272); //Need to do a translation to flip the order - ignitionTable.axisY[valueOffset] = (int)(newValue); + ignitionTable.axisY[valueOffset] = (int)(newValue) * TABLE_LOAD_MULTIPLIER; } return; } @@ -335,7 +335,7 @@ void receiveValue(int valueOffset, byte newValue) //For some reason, TunerStudio is sending offsets greater than the maximum page size. I'm not sure if it's their bug or mine, but the fix is to only update the config page if the offset is less than the maximum size if (valueOffset < page_size) { - *((byte *)pnt_configPage + (byte)valueOffset) = newValue; //Need to subtract 80 because the map and bins (Which make up 80 bytes) aren't part of the config pages + *((byte *)pnt_configPage + (byte)valueOffset) = newValue; } break; @@ -351,13 +351,13 @@ void receiveValue(int valueOffset, byte newValue) if (valueOffset < 272) { //X Axis - afrTable.axisX[(valueOffset - 256)] = int(newValue) * int(100); //The RPM values sent by megasquirt are divided by 100, need to multiply it back by 100 to make it correct + afrTable.axisX[(valueOffset - 256)] = int(newValue) * TABLE_RPM_MULTIPLIER; //The RPM values sent by megasquirt are divided by 100, need to multiply it back by 100 to make it correct (TABLE_RPM_MULTIPLIER) } else { //Y Axis valueOffset = 15 - (valueOffset - 272); //Need to do a translation to flip the order - afrTable.axisY[valueOffset] = int(newValue); + afrTable.axisY[valueOffset] = int(newValue) * TABLE_LOAD_MULTIPLIER; } return; @@ -368,7 +368,7 @@ void receiveValue(int valueOffset, byte newValue) //For some reason, TunerStudio is sending offsets greater than the maximum page size. I'm not sure if it's their bug or mine, but the fix is to only update the config page if the offset is less than the maximum size if (valueOffset < page_size) { - *((byte *)pnt_configPage + (byte)valueOffset) = newValue; //Need to subtract 80 because the map and bins (Which make up 80 bytes) aren't part of the config pages + *((byte *)pnt_configPage + (byte)valueOffset) = newValue; } break; @@ -388,12 +388,12 @@ void receiveValue(int valueOffset, byte newValue) } else if (valueOffset < 72) //New value is on the X (RPM) axis of the boost table { - boostTable.axisX[(valueOffset - 64)] = int(newValue) * int(100); //The RPM values sent by TunerStudio are divided by 100, need to multiply it back by 100 to make it correct + boostTable.axisX[(valueOffset - 64)] = int(newValue) * TABLE_RPM_MULTIPLIER; //The RPM values sent by TunerStudio are divided by 100, need to multiply it back by 100 to make it correct (TABLE_RPM_MULTIPLIER) return; } else if (valueOffset < 80) //New value is on the Y (TPS) axis of the boost table { - boostTable.axisY[(7 - (valueOffset - 72))] = int(newValue); + boostTable.axisY[(7 - (valueOffset - 72))] = int(newValue) * TABLE_LOAD_MULTIPLIER; return; } else if (valueOffset < 144) //New value is part of the vvt map @@ -405,15 +405,33 @@ void receiveValue(int valueOffset, byte newValue) else if (valueOffset < 152) //New value is on the X (RPM) axis of the vvt table { valueOffset = valueOffset - 144; - vvtTable.axisX[valueOffset] = int(newValue) * int(100); //The RPM values sent by TunerStudio are divided by 100, need to multiply it back by 100 to make it correct + vvtTable.axisX[valueOffset] = int(newValue) * TABLE_RPM_MULTIPLIER; //The RPM values sent by TunerStudio are divided by 100, need to multiply it back by 100 to make it correct (TABLE_RPM_MULTIPLIER) return; } else //New value is on the Y (Load) axis of the vvt table { valueOffset = valueOffset - 152; - vvtTable.axisY[(7 - valueOffset)] = int(newValue); + vvtTable.axisY[(7 - valueOffset)] = int(newValue) * TABLE_LOAD_MULTIPLIER; return; } + case seqFuelPage: + if (valueOffset < 36) { trim1Table.values[5 - valueOffset / 6][valueOffset % 6] = newValue; } //Trim1 values + else if (valueOffset < 42) { trim1Table.axisX[(valueOffset - 36)] = int(newValue) * TABLE_RPM_MULTIPLIER; } //New value is on the X (RPM) axis of the trim1 table. The RPM values sent by TunerStudio are divided by 100, need to multiply it back by 100 to make it correct (TABLE_RPM_MULTIPLIER) + else if (valueOffset < 48) { trim1Table.axisY[(5 - (valueOffset - 42))] = int(newValue) * TABLE_LOAD_MULTIPLIER; } //New value is on the Y (TPS) axis of the boost table + //Trim table 2 + else if (valueOffset < 84) { valueOffset = valueOffset - 48; trim2Table.values[5 - valueOffset / 6][valueOffset % 6] = newValue; } //New value is part of the trim2 map + else if (valueOffset < 90) { valueOffset = valueOffset - 84; trim2Table.axisX[valueOffset] = int(newValue) * TABLE_RPM_MULTIPLIER; } //New value is on the X (RPM) axis of the table. //The RPM values sent by TunerStudio are divided by 100, need to multiply it back by 100 to make it correct (TABLE_RPM_MULTIPLIER) + else if (valueOffset < 96) { valueOffset = valueOffset - 90; trim2Table.axisY[(5 - valueOffset)] = int(newValue) * TABLE_LOAD_MULTIPLIER; } //New value is on the Y (Load) axis of the table + //Trim table 3 + else if (valueOffset < 132) { valueOffset = valueOffset - 96; trim3Table.values[5 - valueOffset / 6][valueOffset % 6] = newValue; } //New value is part of the trim2 map + else if (valueOffset < 138) { valueOffset = valueOffset - 132; trim3Table.axisX[valueOffset] = int(newValue) * TABLE_RPM_MULTIPLIER; } //New value is on the X (RPM) axis of the table. //The RPM values sent by TunerStudio are divided by 100, need to multiply it back by 100 to make it correct (TABLE_RPM_MULTIPLIER) + else if (valueOffset < 144) { valueOffset = valueOffset - 138; trim3Table.axisY[(5 - valueOffset)] = int(newValue) * TABLE_LOAD_MULTIPLIER; } //New value is on the Y (Load) axis of the table + //Trim table 4 + else if (valueOffset < 180) { valueOffset = valueOffset - 144; trim4Table.values[5 - valueOffset / 6][valueOffset % 6] = newValue; } //New value is part of the trim2 map + else if (valueOffset < 186) { valueOffset = valueOffset - 180; trim4Table.axisX[valueOffset] = int(newValue) * TABLE_RPM_MULTIPLIER; } //New value is on the X (RPM) axis of the table. //The RPM values sent by TunerStudio are divided by 100, need to multiply it back by 100 to make it correct (TABLE_RPM_MULTIPLIER) + else if (valueOffset < 192) { valueOffset = valueOffset - 186; trim4Table.axisY[(5 - valueOffset)] = int(newValue) * TABLE_LOAD_MULTIPLIER; } //New value is on the Y (Load) axis of the table + + break; default: break; } diff --git a/globals.h b/globals.h index 1c753a83..c79b30cd 100644 --- a/globals.h +++ b/globals.h @@ -146,6 +146,9 @@ struct statuses { volatile byte spark; byte engine; unsigned int PW; //In uS + unsigned int PW2; //In uS + unsigned int PW3; //In uS + unsigned int PW4; //In uS volatile byte runSecs; //Counter of seconds since cranking commenced (overflows at 255 obviously) volatile byte secl; //Continous volatile unsigned int loopsPerSecond; @@ -356,8 +359,9 @@ struct config3 { byte boostKI; byte boostKD; - byte lnchPullRes :2; - byte unused60 : 6; + byte lnchPullRes : 2; + bool fuelTrimEnabled : 1; + byte unused60 : 5; byte unused61; byte unused62; byte unused63; diff --git a/reference/speeduino.ini b/reference/speeduino.ini index 100cc259..b3af7cc5 100644 --- a/reference/speeduino.ini +++ b/reference/speeduino.ini @@ -381,8 +381,9 @@ page = 6 boostKI = scalar, U08, 58, "%", 1.0, 0.0, 0.0, 200.0, 0 ; * ( 1 byte) boostKD = scalar, U08, 59, "%", 1.0, 0.0, 0.0, 200.0, 0 ; * ( 1 byte) - lnchPullRes = bits, U08, 60 [0:1], "Float" , "Pullup", "INVALID", "INVALID" - unused6-60 = bits, U08, 60, [2:7], "ONE", "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", "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", "INVALID", "INVALID", "INVALID" + lnchPullRes = bits, U08, 60 [0:1], "Float" , "Pullup", "INVALID", "INVALID" + fuelTrimEnabled= bits, U08, 60, [2:2], "No", "Yes" + unused6-60 = bits, U08, 60, [3:7], "ONE", "INVALID" unused6-61 = scalar, U08, 61, "RPM", 100.0, 0.0, 100, 25500, 0 unused6-62 = scalar, U08, 62, "RPM", 100.0, 0.0, 100, 25500, 0 unused6-63 = scalar, U08, 63, "RPM", 100.0, 0.0, 100, 25500, 0 @@ -423,7 +424,7 @@ page = 7 ; Begin fan control vairables fanInv = bits, U08, 56, [0:0], "No", "Yes" - fanEnable = bits, U08, 56, [1:2], "Off", "On/Off", "PWM", "INVALID" + fanEnable = bits, U08, 56, [1:2], "Off", "On/Off", "INVALID", "INVALID" unused7-55b = bits, U08, 56, [3:3], "No", "Yes" unused7-55c = bits, U08, 56, [4:4], "No", "Yes" unused7-55d = bits, U08, 56, [5:5], "No", "Yes" @@ -695,6 +696,9 @@ menuDialog = main sparkMode = "Wasted Spark: Ignition outputs are on the channels <= half the number of cylinders. Eg 4 cylinder outputs on IGN1 and IGN2.\nSingle Channel: All ignition pulses are output on IGN1.\nWasted COP: Ignition pulses are output on all ignition channels up to the number of cylinders. Eg 4 cylinder outputs on all ignition channels. No valid for >4 cylinders" IgInv = "Whether the spark fires when the ignition sign goes high or goes low. Most ignition systems 'Going Low' but please verify this as damage to coils can result from the incorrect selection" + fanInv = "" + fanHyster = "The number of degrees of hysteresis to be used in controlling the fan. Recommended values are between 2 and 5" + taeTime = "The duration of the acceleration enrichment" iacChannels = "The number of output channels used for PWM valves. Select 1 for 2-wire valves or 2 for 3-wire valves." @@ -846,7 +850,7 @@ menuDialog = main dialog = fanSettings,"Fan Settings",7 field = "Fan Mode", fanEnable - field = "Fan Output Inverted (see F1)", fanInv + field = "Fan Output Inverted", fanInv field = "Fan temperature SP", fanSP field = "Fan hysteresis", fanHyster diff --git a/speeduino.ino b/speeduino.ino index 9bccc6c9..2f67a94d 100644 --- a/speeduino.ino +++ b/speeduino.ino @@ -1076,6 +1076,12 @@ void loop() injector2StartAngle += 360; injector3StartAngle += 360; injector4StartAngle += 360; + + if(configPage3.fuelTrimEnabled) + { + + //currentStatus.PW = currentStatus.PW * (100 + get3DTableValue(&trim1Table, currentStatus.MAP, currentStatus.RPM) ); //Perform lookup into fuel map for RPM vs MAP value + } } break; //5 cylinders diff --git a/table.h b/table.h index 1c79c789..637c2047 100644 --- a/table.h +++ b/table.h @@ -5,6 +5,9 @@ This file is used for everything related to maps/tables including their definiti #define TABLE_H #include +#define TABLE_RPM_MULTIPLIER 100 +#define TABLE_LOAD_MULTIPLIER 1 + /* The 2D table can contain either 8-bit (byte) or 16-bit (int) values The valueSize variable should be set to either 8 or 16 to indicate this BEFORE the table is used