Possible fix for TunerStudio calibrations

This commit is contained in:
Josh Stewart 2015-01-10 09:56:14 +11:00
parent 291e7d3282
commit a2bc8732ac
2 changed files with 9 additions and 34 deletions

View File

@ -62,6 +62,7 @@ void command()
receiveCalibration(tableID); //Receive new values and store in memory
writeCalibration(); //Store received values in EEPROM
analogWrite(13, 0 );
break;
@ -333,35 +334,17 @@ void receiveCalibration(byte tableID)
int tempValue;
byte tempBuffer[2];
bool every2nd = true;
//byte tempVal = 3;
int x;
int counter = 0;
Serial.setTimeout(20);
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
for (x = 0; x < 1024; x++)
{
//tempVal = Serial.available();
//int failcount = 0;
while ( Serial.available() < 2 ) {}
tempBuffer[0] = Serial.read();
tempBuffer[1] = Serial.read();
/*
int hsb16 = -1;
while( hsb16 == -1 ) { hsb16 = Serial.read(); }
byte hsb = (byte)(hsb16);
int lsb16 = -1;
while( lsb16 == -1 ) { lsb16 = Serial.read(); }
byte lsb = (byte)(lsb16);
*/
//Serial.readBytes(tempBuffer, 2);
//int hsb16 = Serial.read();
//int lsb16 = Serial.read();
tempValue = div(int(word(tempBuffer[0], tempBuffer[1])), DIVISION_FACTOR).quot; //Read 2 bytes, convert to word (an unsigned int), convert to signed int. These values come through * 10 from Tuner Studio
//tempValue = div((tempBuffer[0] << 8 | tempBuffer[1]), 10).quot;
tempValue = tempValue + OFFSET;
@ -371,11 +354,10 @@ void receiveCalibration(byte tableID)
{
if (tempValue > 255) { tempValue = 255; } // Cap the maximum value to prevent overflow when converting to byte
if (tempValue < 0) { tempValue = 0; }
//pnt_TargetTable[(x / 2)] = (byte)tempValue;
pnt_TargetTable[counter] = (byte)(counter);
pnt_TargetTable[(x / 2)] = (byte)tempValue;
//pnt_TargetTable[counter] = (byte)(counter);
int y = EEPROM_CALIBRATION_O2 + counter;
EEPROM.write(y, (byte)counter);
//if(counter > 400) { pnt_TargetTable[counter] = 201;}
//EEPROM.write(y, (byte)counter);
every2nd = false;
analogWrite(13, (counter % 50) );
@ -383,13 +365,8 @@ void receiveCalibration(byte tableID)
}
else { every2nd = true; }//digitalWrite(13, HIGH); }
//pnt_TargetTable[x] = tempValue;
//x++;
}
Serial.setTimeout(1000);
while(Serial.available() > 0) { Serial.read(); }
//pnt_TargetTable[511] = 123;
//cltCalibrationTable[510] = 123;
}
/*

View File

@ -169,8 +169,6 @@ void loadCalibration()
/*
This takes the values in the 3 calibration tables (Coolant, Inlet temp and O2)
and saves them to the EEPROM.
TODO: Need to add checking prior to write in order to prolong EEPROM life
*/
void writeCalibration()
{
@ -178,13 +176,13 @@ void writeCalibration()
for(int x=0; x<CALIBRATION_TABLE_SIZE; x++) //Each calibration table is 512 bytes long
{
int y = EEPROM_CALIBRATION_CLT + x;
EEPROM.write(y, cltCalibrationTable[x]);
if(EEPROM.read(y) != cltCalibrationTable[x]) { EEPROM.write(y, cltCalibrationTable[x]); }
y = EEPROM_CALIBRATION_IAT + x;
EEPROM.write(y, iatCalibrationTable[x]);
if(EEPROM.read(y) != iatCalibrationTable[x]) { EEPROM.write(y, iatCalibrationTable[x]); }
y = EEPROM_CALIBRATION_O2 + x;
EEPROM.write(y, o2CalibrationTable[x]);
if(EEPROM.read(y) != o2CalibrationTable[x]) { EEPROM.write(y, o2CalibrationTable[x]); }
}
}