From b12fec4a72cbec35974f4df9d5df374806a96704 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Thu, 2 May 2019 11:52:05 +1000 Subject: [PATCH] Initial work on processing the 2nd fuel table --- speeduino/decoders.ino | 2 +- speeduino/speeduino.h | 1 + speeduino/speeduino.ino | 59 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/speeduino/decoders.ino b/speeduino/decoders.ino index 636fcaa8..8ccbb498 100644 --- a/speeduino/decoders.ino +++ b/speeduino/decoders.ino @@ -2025,7 +2025,7 @@ void triggerSetEndTeeth_Miata9905() if(configPage4.sparkMode == IGN_MODE_SEQUENTIAL) { - if(currentStatus.advance > 10) + if(currentStatus.advance >= 10) { ignition1EndTooth = 8; ignition2EndTooth = 2; diff --git a/speeduino/speeduino.h b/speeduino/speeduino.h index 504f4050..3eee4947 100644 --- a/speeduino/speeduino.h +++ b/speeduino/speeduino.h @@ -14,6 +14,7 @@ uint16_t PW(int REQ_FUEL, byte VE, long MAP, int corrections, int injOpen); byte getVE(); +byte getVE2(); byte getAdvance(); uint16_t calculateInjector2StartAngle(unsigned int); diff --git a/speeduino/speeduino.ino b/speeduino/speeduino.ino index 349e919b..a857f48f 100644 --- a/speeduino/speeduino.ino +++ b/speeduino/speeduino.ino @@ -103,6 +103,7 @@ void loop() currentStatus.RPM = 0; currentStatus.PW1 = 0; currentStatus.VE = 0; + currentStatus.VE2 = 0; toothLastToothTime = 0; toothLastSecToothTime = 0; //toothLastMinusOneToothTime = 0; @@ -280,9 +281,34 @@ void loop() if( (configPage6.iacAlgorithm == IAC_ALGORITHM_STEP_OL) || (configPage6.iacAlgorithm == IAC_ALGORITHM_STEP_CL) ) { idleControl(); } //Run idlecontrol every loop for stepper idle. + byte totalVE = 0; //VE calculation was moved outside the sync/RPM check so that the fuel load value will be accurately shown when RPM=0 currentStatus.VE = getVE(); + //If the secondary fuel table is in use, also get the VE value from there + if(configPage10.fuel2Mode > 0) + { + currentStatus.VE2 = getVE2(); + + if(configPage10.fuel2Mode == FUEL2_MODE_MULTIPLY) + { + //Fuel 2 table is treated as a % value. Table 1 and 2 are multiplied together and divded by 100 + totalVE = ((uint16_t)currentStatus.VE * (uint16_t)currentStatus.VE2) / 100; + } + else if(configPage10.fuel2Mode == FUEL2_MODE_ADD) + { + //Fuel tables are added together, but a check is made to make sure this won't overflow the 8-bit totalVE value + uint16_t combinedVE = (uint16_t)currentStatus.VE + (uint16_t)currentStatus.VE2; + if(combinedVE <= 255) { totalVE = combinedVE; } + else { totalVE = 255; } + } + else if(configPage10.fuel2Mode == FUEL2_MODE_SWITCH) + { + + } + } + else { totalVE = currentStatus.VE; } + //Always check for sync //Main loop runs within this clause if (currentStatus.hasSync && (currentStatus.RPM > 0)) @@ -315,7 +341,8 @@ void loop() currentStatus.corrections = correctionsFuel(); currentStatus.advance = getAdvance(); - currentStatus.PW1 = PW(req_fuel_uS, currentStatus.VE, currentStatus.MAP, currentStatus.corrections, inj_opentime_uS); + //currentStatus.PW1 = PW(req_fuel_uS, currentStatus.VE, currentStatus.MAP, currentStatus.corrections, inj_opentime_uS); + currentStatus.PW1 = PW(req_fuel_uS, totalVE, currentStatus.MAP, currentStatus.corrections, inj_opentime_uS); //Manual adder for nitrous. These are not in correctionsFuel() because they are direct adders to the ms value, not % based if(currentStatus.nitrous_status == NITROUS_STAGE1) @@ -1170,6 +1197,36 @@ byte getVE() return tempVE; } +/** + * @brief Looks up and returns the VE value from the secondary fuel table + * + * This performs largely the same operations as getVE() however the lookup is of the secondary fuel table and uses the secondary load source + * @return byte + */ +byte getVE2() +{ + byte tempVE = 100; + if( configPage10.fuel2Algorithm == LOAD_SOURCE_MAP) + { + //Speed Density + currentStatus.fuelLoad2 = currentStatus.MAP; + } + else if (configPage10.fuel2Algorithm == LOAD_SOURCE_TPS) + { + //Alpha-N + currentStatus.fuelLoad2 = currentStatus.TPS; + } + else if (configPage10.fuel2Algorithm == LOAD_SOURCE_IMAPEMAP) + { + //IMAP / EMAP + currentStatus.fuelLoad2 = (currentStatus.MAP * 100) / currentStatus.EMAP; + } + else { currentStatus.fuelLoad2 = currentStatus.MAP; } //Fallback position + tempVE = get3DTableValue(&fuelTable2, currentStatus.fuelLoad2, currentStatus.RPM); //Perform lookup into fuel map for RPM vs MAP value + + return tempVE; +} + /** * @brief Performs a lookup of the ignition advance table. The values used to look this up will be RPM and whatever load source the user has configured *