Added further variables to the comms page reads

This commit is contained in:
Josh Stewart 2013-07-17 13:09:18 +10:00
parent d3a5b44eb9
commit 2e5e6668ff
3 changed files with 44 additions and 33 deletions

View File

@ -1,3 +1,8 @@
/*
This is called when a command is received over serial from TunerStudio / Megatune
It parses the command and calls the relevant function
A detailed description of each call can be found at: http://www.msextra.com/doc/ms1extra/COM_RS232.htm
*/
void command()
{
switch (Serial.read())
@ -6,11 +11,11 @@ void command()
sendValues(22);
break;
case 'B': // store to eeprom
case 'B': // Burn current values to eeprom
saveConfig();
break;
case 'C': // test communications
case 'C': // test communications. This is used by Tunerstudio to see whether there is an ECU on a given serial port
testComm();
break;
@ -19,9 +24,10 @@ void command()
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
digitalWrite(13, LOW);
while (Serial.available() == 0)
{
}
//A 2nd byte of data is required after the 'P' specifying the new page number.
//This loop should never need to run as the byte should already be in the buffer, but is here just in case
while (Serial.available() == 0) { }
currentPage = Serial.read();
break;
@ -54,6 +60,7 @@ void command()
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(13, LOW);
Serial.read();
Serial.read(); //Not doing anything with this currently, but need to read the next 2 bytes from the buffer
break;
@ -63,6 +70,9 @@ void command()
}
}
/*
This function returns the current values of a fixed group of variables
*/
void sendValues(int length)
{
byte response[22];
@ -71,9 +81,9 @@ void sendValues(int length)
boolean a = 0; //inj_port1.status;
boolean b = 0; //inj_port2.status;
response[1] = ((a & 0x01) << 0) | ((a & 0x02) << 1) | ((a & 0x04) << 1) | ((b & 0x01) << 1) | ((b & 0x02) << 3) | ((b & 0x04) << 3); //squirt
response[1] = ((a & 0x01) << 0) | ((a & 0x02) << 1) | ((a & 0x04) << 1) | ((b & 0x01) << 1) | ((b & 0x02) << 3) | ((b & 0x04) << 3); //squirt NOT YET WORKING
response[2] = (byte)128; // Engine Status
response[2] = (byte)128; // Engine Status NOT YET WORKING
response[3] = 0x00; //baro
response[4] = currentStatus.MAP; //map
response[5] = 0x00; //mat
@ -111,18 +121,19 @@ void sendPage()
{
case vePage:
//Need to perform a translation of the values[MAP/TPS][RPM] into the MS expected format
//MS format has origin (0,0) in the bottom left corner, we use the top left for efficiency reasons
for(byte x=0;x<64;x++) { response[x] = fuelTable.values[7-x/8][x%8]; }
for(byte x=64;x<72;x++) { response[x] = fuelTable.axisX[(x-64)] / 100; } //RPM Bins for VE table
for(byte y=72;y<80;y++) { response[y] = fuelTable.axisY[7-(y-72)]; } //MAP or TPS bins for VE table
response[80] = 0;
response[81] = 0;
response[82] = 0;
response[83] = 0;
response[84] = 0;
response[94] = 0;
response[95] = 0;
response[96] = 0;
response[97] = 0;
response[80] = configPage1.crankCold; //Cold cranking pulsewidth. This is added to the fuel pulsewidth when cranking under a temp threshold (ms)
response[81] = configPage1.crankHot; //Warm cranking pulsewidth. This is added to the fuel pulsewidth when cranking (ms)
response[82] = configPage1.asePct; //Afterstart enrichment (%)
response[83] = configPage1.aseCount; //Afterstart enrichment cycles. This is the number of ignition cycles that the afterstart enrichment % lasts for
for(byte x=84;x<94;x++) { response[x] = configPage1.wueBins[x-84]; } //Warm up enrichment array (10 bytes, % values)
response[94] = configPage1.taeBins1; //TPS based acceleration enrichment bin 1 of 4 (ms)
response[95] = configPage1.taeBins2; //TPS based acceleration enrichment bin 2 of 4 (ms)
response[96] = configPage1.taeBins3; //TPS based acceleration enrichment bin 3 of 4 (ms)
response[97] = configPage1.taeBins4; //TPS based acceleration enrichment bin 4 of 4 (ms)
response[98] = 0;
response[99] = 0;
response[100] = 0;
@ -131,7 +142,7 @@ void sendPage()
response[103] = 0;
response[104] = 0;
response[105] = 0;
response[106] = config1.reqFuel;
response[106] = configPage1.reqFuel;
response[107] = 0;
response[108] = 0;
response[109] = 0;
@ -140,7 +151,7 @@ void sendPage()
response[112] = 0;
response[113] = 0;
response[114] = 0; //rpmk (16 bits)
response[116] = ((config1.nCylinders-1) * 16) + (1 * 8) + ((config1.strokes / 4) * 4) + 2; // (engineCylinders * 16) + (1 * 8) + ((engineStrokes / 4) * 4) + 4
response[116] = ((configPage1.nCylinders-1) * 16) + (1 * 8) + ((configPage1.strokes / 4) * 4) + 2; // (engineCylinders * 16) + (1 * 8) + ((engineStrokes / 4) * 4) + 4
response[117] = 0;
response[118] = 0;
response[119] = 0;
@ -158,7 +169,7 @@ void sendPage()
for(byte x=0;x<64;x++) { response[x] = ignitionTable.values[7-x/8][x%8]; }
for(byte x=64;x<72;x++) { response[x] = ignitionTable.axisX[(x-64)] / 100; }
for(byte y=72;y<80;y++) { response[y] = ignitionTable.axisY[7-(y-72)]; }
response[80] = config2.triggerAngle;
response[80] = configPage2.triggerAngle;
response[81] = 0;
response[82] = 0;
response[83] = 0;

View File

@ -30,12 +30,12 @@ struct config1 {
byte crankCold;
byte crankHot;
byte asePct;
byte aseCount;
byte wueBins[10];
byte taeBins1;
byte taeBins2;
byte taeBins3;
byte taeBins4;
byte aseCount; //Afterstart enrichment cycles. This is the number of ignition cycles that the afterstart enrichment % lasts for
byte wueBins[10]; //Warm up enrichment array (10 bytes)
byte taeBins1; //TPS based acceleration enrichment bin 1 of 4 (ms)
byte taeBins2; //TPS based acceleration enrichment bin 2 of 4 (ms)
byte taeBins3; //TPS based acceleration enrichment bin 3 of 4 (ms)
byte taeBins4; //TPS based acceleration enrichment bin 4 of 4 (ms)
byte taeColdA;
byte tpsThresh;
byte taeTime;

View File

@ -30,16 +30,16 @@ Need to calculate the req_fuel figure here, preferably in pre-processor macro
#include "digitalIOPerformance.h"
//NEED TO LOAD FROM EEPROM HERE
struct config1 config1;
struct config2 config2;
struct config1 configPage1;
struct config2 configPage2;
//float req_fuel = ((engineCapacity / engineInjectorSize) / engineCylinders / engineStoich) * 100; // This doesn't seem quite correct, but I can't find why. It will be close enough to start an engine
int req_fuel_uS = config1.reqFuel * 1000; //Convert to uS and an int. This is the only variable to be used in calculations
int req_fuel_uS = configPage1.reqFuel * 1000; //Convert to uS and an int. This is the only variable to be used in calculations
// Setup section
// These aren't really configuration options, more so a description of how the hardware is setup. These are things that will be defined in the recommended hardware setup
int triggerActualTeeth = config2.triggerTeeth - config2.triggerMissingTeeth; //The number of physical teeth on the wheel. Doing this here saves us a calculation each time in the interrupt
int triggerToothAngle = 360 / config2.triggerTeeth; //The number of degrees that passes from tooth to tooth
int triggerActualTeeth = configPage2.triggerTeeth - configPage2.triggerMissingTeeth; //The number of physical teeth on the wheel. Doing this here saves us a calculation each time in the interrupt
int triggerToothAngle = 360 / configPage2.triggerTeeth; //The number of degrees that passes from tooth to tooth
volatile int toothCurrentCount = 0; //The current number of teeth (Onec sync has been achieved, this can never actually be 0
volatile unsigned long toothLastToothTime = 0; //The time (micros()) that the last tooth was registered
@ -135,7 +135,7 @@ void loop()
//Calculate the RPM based on the time between the last 2 teeth. I have no idea whether this will be accurate AT ALL, but it's fairly efficient and means there doesn't need to be another variable placed into the trigger interrupt
if (toothCurrentCount != 1) //We can't perform the RPM calculation if we're at the first tooth as the timing would be double (Well, we can, but it would need a different calculation and I don't think it's worth it, just use the last RPM value)
{
long revolutionTime = (config2.triggerTeeth * (toothLastToothTime - toothLastMinusOneToothTime)); //The time in uS that one revolution would take at current speed
long revolutionTime = (configPage2.triggerTeeth * (toothLastToothTime - toothLastMinusOneToothTime)); //The time in uS that one revolution would take at current speed
currentStatus.RPM = US_IN_MINUTE / revolutionTime;
}
//Get the current MAP value
@ -152,7 +152,7 @@ void loop()
int ignitionAdvance = getTableValue(ignitionTable, currentStatus.MAP, currentStatus.RPM);
//Determine the current crank angle
int crankAngle = (toothCurrentCount - 1) * triggerToothAngle + config2.triggerAngle; //Number of teeth that have passed since tooth 1, multiplied by the angle each tooth represents, plus the angle that tooth 1 is from TDC
int crankAngle = (toothCurrentCount - 1) * triggerToothAngle + configPage2.triggerAngle; //Number of teeth that have passed since tooth 1, multiplied by the angle each tooth represents, plus the angle that tooth 1 is from TDC
if (crankAngle > 360) { crankAngle -= 360; } //Not sure if this is actually required
//Serial.print("Crank angle: "); Serial.println(crankAngle);
@ -183,7 +183,7 @@ void loop()
{
setSchedule2(beginCoilCharge,
(ignitionStartAngle - crankAngle) * timePerDegree,
config2.dwellRun,
configPage2.dwellRun,
endCoilCharge
);
}