All the code infrastructure for the AFR target table

This commit is contained in:
Josh Stewart 2015-02-03 21:33:22 +11:00
parent af5ef6295d
commit e62231fb06
6 changed files with 184 additions and 20 deletions

View File

@ -1,5 +1,6 @@
#define vePage 1 #define vePage 1
#define ignPage 2 #define ignPage 2
#define afrPage 3
byte currentPage; byte currentPage;

View File

@ -237,6 +237,41 @@ void receiveValue(byte offset, byte newValue)
return; return;
} }
break; break;
case afrPage: //Air/Fuel ratio target settings page (Page 3)
pnt_configPage = (byte *)&configPage3;
if (offset < 64) //New value is part of the afr map
{
afrTable.values[7-offset/8][offset%8] = newValue;
return;
}
else if (offset < 80) //New value is one of the X or Y axis bins
{
//Check whether this is on the X (RPM) or Y (MAP/TPS) axis
if (offset < 72)
{
//X Axis
afrTable.axisX[(offset-64)] = 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
}
else
{
//Y Axis
offset = 7-(offset-72); //Need to do a translation to flip the order
afrTable.axisY[offset] = int(newValue);
}
return;
}
else //New value is one of the remaining config items
{
//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( offset < page_size)
{
*(pnt_configPage + byte(offset - 80)) = newValue; //Need to subtract 80 because the map and bins (Which make up 80 bytes) aren't part of the config pages
}
return;
}
break;
default: default:
break; break;
@ -292,6 +327,23 @@ void sendPage()
Serial.flush(); Serial.flush();
break; break;
case afrPage:
//Need to perform a translation of the values[MAP/TPS][RPM] into the MS expected format
for(byte x=0;x<64;x++) { response[x] = afrTable.values[7-x/8][x%8]; }
for(byte x=64;x<72;x++) { response[x] = byte(afrTable.axisX[(x-64)] / 100); }
for(byte y=72;y<80;y++) { response[y] = byte(afrTable.axisY[7-(y-72)]); }
//All other bytes can simply be copied from the config table
pnt_configPage = (byte *)&configPage3; //Create a pointer to Page 2 in memory
offset = 80; //Offset is based on the amount already copied above (table + bins)
for(byte x=offset; x<page_size; x++)
{
response[x] = *(pnt_configPage + byte(x - offset)); //Each byte is simply the location in memory of configPage2 + the offset + the variable number (x)
}
Serial.write((byte *)&response, sizeof(response));
Serial.flush();
break;
default: default:
break; break;
} }

View File

@ -80,13 +80,6 @@ struct statuses {
//Page 1 of the config - See the ini file for further reference //Page 1 of the config - See the ini file for further reference
//This mostly covers off variables that are required for fuel //This mostly covers off variables that are required for fuel
struct config1 { struct config1 {
/*
byte engineCylinders; 1 // May support more than 1 cyl later. Always will assume 1 injector per cylinder.
byte engineInjectorSize; 80 // In cc/min
byte engineStoich; 14.7 // Stoichiometric ratio of fuel used
byte engineStrokes; 4 //Can be 2 stroke or 4 stroke, any other value will cause problems
byte engineDwell; 3000 //The spark dwell time in uS
*/
byte crankCold; //Cold cranking pulsewidth modifier. This is added to the fuel pulsewidth when cranking under a certain temp threshold (ms) byte crankCold; //Cold cranking pulsewidth modifier. This is added to the fuel pulsewidth when cranking under a certain temp threshold (ms)
byte crankHot; //Warm cranking pulsewidth modifier. This is added to the fuel pulsewidth when cranking (ms) byte crankHot; //Warm cranking pulsewidth modifier. This is added to the fuel pulsewidth when cranking (ms)
@ -98,10 +91,10 @@ struct config1 {
byte tpsThresh; byte tpsThresh;
byte taeTime; byte taeTime;
byte tdePct; byte tdePct;
byte egoTemp; //The temperature at which the EGO / O2 sensor values start being used (Degrees) byte unused102;
byte egoCount; byte unused103;
byte egoDelta; byte unused104;
byte egoLimit; byte unused105;
byte reqFuel; byte reqFuel;
byte divider; byte divider;
byte alternate; byte alternate;
@ -193,6 +186,51 @@ struct config2 {
byte unused127; byte unused127;
};
//Page 3 of the config - See the ini file for further reference
//This mostly covers off variables that are required for AFR targets and closed loop
struct config3 {
byte egoAlgorithm : 2;
byte egoType : 2;
byte unused : 4;
byte egoKP;
byte egoKI;
byte egoKD;
byte egoTemp; //The temperature above which closed loop functions
byte egoCount; //The number of ignition cylces per step
byte egoDelta; //The step size (In %) when using simple algorithm
byte egoLimit; //Maximum amount the closed loop will vary the fueling
byte ego_min; //AFR must be above this for closed loop to function
byte ego_max; //AFR must be below this for closed loop to function
byte ego_sdelay; //Time in seconds after engine starts that closed loop becomes available
byte egoRPM; //RPM must be above this for closed loop to function
byte egoTPSMax; //TPS must be below this for closed loop to function
byte floodClear; //TPS value that triggers flood clear mode (No fuel whilst cranking)
byte egoLoadMax; //Load (TPS or MAP) must be below this for closed loop to function
byte egoLoadMin; //Load (TPS or MAP) must be above this for closed loop to function
byte unused95;
byte unused96;
byte unused97;
byte unused98;
byte unused99;
byte unused115;
byte unused116;
byte unused117;
byte unused118;
byte unused119;
byte unused120;
byte unused121;
byte unused122;
byte unused123;
byte unused124;
byte unused125;
byte unused126;
byte unused127;
}; };
//Pin mappings as per the v0.2 shield //Pin mappings as per the v0.2 shield

View File

@ -25,6 +25,7 @@
struct config1 configPage1; struct config1 configPage1;
struct config2 configPage2; struct config2 configPage2;
struct config3 configPage3;
int req_fuel_uS, triggerToothAngle, inj_opentime_uS; int req_fuel_uS, triggerToothAngle, inj_opentime_uS;
volatile int triggerActualTeeth; volatile int triggerActualTeeth;
@ -43,6 +44,7 @@ volatile bool ignitionOn = true; //The current state of the ignition system
struct table3D fuelTable; //8x8 fuel map struct table3D fuelTable; //8x8 fuel map
struct table3D ignitionTable; //8x8 ignition map struct table3D ignitionTable; //8x8 ignition map
struct table3D afrTable; //8x8 afr target map
struct table2D taeTable; //4 bin TPS Acceleration Enrichment map (2D) struct table2D taeTable; //4 bin TPS Acceleration Enrichment map (2D)
struct table2D WUETable; //10 bin Warm Up Enrichment map (2D) struct table2D WUETable; //10 bin Warm Up Enrichment map (2D)
byte cltCalibrationTable[CALIBRATION_TABLE_SIZE]; byte cltCalibrationTable[CALIBRATION_TABLE_SIZE];

View File

@ -20,11 +20,15 @@ Current layout of EEPROM data (Version 2) is as follows (All sizes are in bytes)
| 133 |64 | Ignition Map (8x8) | | 133 |64 | Ignition Map (8x8) |
| 197 |8 | Ign Table RPM bins | | 197 |8 | Ign Table RPM bins |
| 205 |8 | Ign Table MAP/TPS bins | | 205 |8 | Ign Table MAP/TPS bins |
| 213 |45 | Remaining Page 2 settings | | 213 |46 | Remaining Page 2 settings |
| 258 |12 | Calibration data (CLT) | | 259 |2 | X and Y sizes for AFR table |
| 270 |12 | Calibration data (IAT) | | 261 |64 | AFR Target Map (8x8) |
| 282 |12 | Calibration data (O2) | | 325 |8 | AFR Table RPM bins |
| 294 |28 | Calibration data (Reserved) | | 333 |8 | AFR Table MAP/TPS bins |
| 341 |46 | Remaining Page 3 settings |
| 2559 |512 | Calibration data (O2) |
| 3071 |512 | Calibration data (IAT) |
| 3583 |512 | Calibration data (CLT) |
----------------------------------------------------- -----------------------------------------------------
*/ */
@ -41,8 +45,14 @@ Current layout of EEPROM data (Version 2) is as follows (All sizes are in bytes)
#define EEPROM_CONFIG2_XBINS 197 #define EEPROM_CONFIG2_XBINS 197
#define EEPROM_CONFIG2_YBINS 205 #define EEPROM_CONFIG2_YBINS 205
#define EEPROM_CONFIG2_SETTINGS 213 #define EEPROM_CONFIG2_SETTINGS 213
#define EEPROM_CONFIG2_END 259
#define EEPROM_CONFIG_END 258 #define EEPROM_CONFIG3_XSIZE 259
#define EEPROM_CONFIG3_YSIZE 260
#define EEPROM_CONFIG3_MAP 261
#define EEPROM_CONFIG3_XBINS 325
#define EEPROM_CONFIG3_YBINS 333
#define EEPROM_CONFIG3_SETTINGS 341
#define EEPROM_CONFIG3_END 387
//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) //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 #define EEPROM_CALIBRATION_O2 2559

View File

@ -72,10 +72,41 @@ void writeConfig()
if(EEPROM.read(x) != ignitionTable.axisY[offset]) { EEPROM.write(x, ignitionTable.axisY[offset]); } if(EEPROM.read(x) != ignitionTable.axisY[offset]) { EEPROM.write(x, ignitionTable.axisY[offset]); }
} }
//The next 45 bytes can simply be pulled straight from the configTable //The next 45 bytes can simply be pulled straight from the configTable
for(int x=EEPROM_CONFIG2_SETTINGS; x<EEPROM_CONFIG_END; x++) for(int x=EEPROM_CONFIG2_SETTINGS; x<EEPROM_CONFIG2_END; x++)
{ {
if(EEPROM.read(x) != *(pnt_configPage + byte(x - EEPROM_CONFIG2_SETTINGS))) { EEPROM.write(x, *(pnt_configPage + byte(x - EEPROM_CONFIG2_SETTINGS))); } if(EEPROM.read(x) != *(pnt_configPage + byte(x - EEPROM_CONFIG2_SETTINGS))) { EEPROM.write(x, *(pnt_configPage + byte(x - EEPROM_CONFIG2_SETTINGS))); }
} }
//That concludes the writing of the IGN table
//*********************************************************************************************************************************************************************************
//AFR CONFIG PAGE (3)
pnt_configPage = (byte *)&configPage3; //Create a pointer to Page 3 in memory
//Begin writing the Ignition table, basically the same thing as above
if(EEPROM.read(EEPROM_CONFIG3_XSIZE) != afrTable.xSize) { EEPROM.write(EEPROM_CONFIG3_XSIZE,afrTable.xSize); } //Write the ignition Table RPM dimension size
if(EEPROM.read(EEPROM_CONFIG3_YSIZE) != afrTable.ySize) { EEPROM.write(EEPROM_CONFIG3_YSIZE,afrTable.ySize); } //Write the ignition Table MAP/TPS dimension size
for(int x=EEPROM_CONFIG3_MAP; x<EEPROM_CONFIG3_XBINS; x++)
{
offset = x - EEPROM_CONFIG3_MAP;
if(EEPROM.read(x) != afrTable.values[7-offset/8][offset%8]) { EEPROM.write(x, afrTable.values[7-offset/8][offset%8]); } //Write the 8x8 map
}
//RPM bins
for(int x=EEPROM_CONFIG3_XBINS; x<EEPROM_CONFIG3_YBINS; x++)
{
offset = x - EEPROM_CONFIG3_XBINS;
if(EEPROM.read(x) != byte(afrTable.axisX[offset]/100)) { EEPROM.write(x, byte(afrTable.axisX[offset]/100)); } //RPM bins are divided by 100 and converted to a byte
}
//TPS/MAP bins
for(int x=EEPROM_CONFIG3_YBINS; x<EEPROM_CONFIG3_SETTINGS; x++)
{
offset = x - EEPROM_CONFIG3_YBINS;
if(EEPROM.read(x) != afrTable.axisY[offset]) { EEPROM.write(x, afrTable.axisY[offset]); }
}
//The next 45 bytes can simply be pulled straight from the configTable
for(int x=EEPROM_CONFIG3_SETTINGS; x<EEPROM_CONFIG3_END; x++)
{
if(EEPROM.read(x) != *(pnt_configPage + byte(x - EEPROM_CONFIG3_SETTINGS))) { EEPROM.write(x, *(pnt_configPage + byte(x - EEPROM_CONFIG3_SETTINGS))); }
}
} }
@ -138,11 +169,41 @@ void loadConfig()
ignitionTable.axisY[offset] = EEPROM.read(x); ignitionTable.axisY[offset] = EEPROM.read(x);
} }
//The next 45 bytes can simply be pulled straight from the configTable //The next 45 bytes can simply be pulled straight from the configTable
for(int x=EEPROM_CONFIG2_SETTINGS; x<EEPROM_CONFIG_END; x++) for(int x=EEPROM_CONFIG2_SETTINGS; x<EEPROM_CONFIG2_END; x++)
{ {
*(pnt_configPage + byte(x - EEPROM_CONFIG2_SETTINGS)) = EEPROM.read(x); *(pnt_configPage + byte(x - EEPROM_CONFIG2_SETTINGS)) = EEPROM.read(x);
} }
//*********************************************************************************************************************************************************************************
//AFR TARGET CONFIG PAGE (3)
pnt_configPage = (byte *)&configPage3; //Create a pointer to Page 2 in memory
//Begin writing the Ignition table, basically the same thing as above
//ignitionTable.xSize = EEPROM.read(EEPROM_CONFIG2_XSIZE); //Read the ignition Table RPM dimension size (Currently not supproted)
//ignitionTable.ySize = EEPROM.read(EEPROM_CONFIG2_YSIZE); //Read the ignition Table MAP/TPS dimension size (Currently not supproted)
for(int x=EEPROM_CONFIG3_MAP; x<EEPROM_CONFIG3_XBINS; x++)
{
offset = x - EEPROM_CONFIG3_MAP;
afrTable.values[7-offset/8][offset%8] = EEPROM.read(x); //Read the 8x8 map
}
//RPM bins
for(int x=EEPROM_CONFIG3_XBINS; x<EEPROM_CONFIG3_YBINS; x++)
{
offset = x - EEPROM_CONFIG3_XBINS;
afrTable.axisX[offset] = (EEPROM.read(x) * 100); //RPM bins are divided by 100 when stored. Multiply them back now
}
//TPS/MAP bins
for(int x=EEPROM_CONFIG3_YBINS; x<EEPROM_CONFIG3_SETTINGS; x++)
{
offset = x - EEPROM_CONFIG3_YBINS;
afrTable.axisY[offset] = EEPROM.read(x);
}
//The next 45 bytes can simply be pulled straight from the configTable
for(int x=EEPROM_CONFIG3_SETTINGS; x<EEPROM_CONFIG3_END; x++)
{
*(pnt_configPage + byte(x - EEPROM_CONFIG3_SETTINGS)) = EEPROM.read(x);
}
} }
/* /*