From 61708a5716e42a4123d0245ff51b591bdd026b5a Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Mon, 20 Jun 2022 15:03:31 +1000 Subject: [PATCH] Prevent cranking and ASE corrections running at once. Alternative fix to #868 --- speeduino/corrections.ino | 50 +++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/speeduino/corrections.ino b/speeduino/corrections.ino index 2eaaf924..8302d80e 100644 --- a/speeduino/corrections.ino +++ b/speeduino/corrections.ino @@ -288,7 +288,7 @@ uint16_t correctionCranking() unsigned long taperStart = (unsigned long) crankingValue * 100 / currentStatus.ASEValue; crankingValue = (uint16_t) map(crankingEnrichTaper, 0, configPage10.crankingEnrichTaper, taperStart, 100); //Taper from start value to 100% if (crankingValue < 100) { crankingValue = 100; } //Sanity check - if( BIT_CHECK(TIMER_mask, BIT_TIMER_10HZ) ) { crankingEnrichTaper++; } + if( BIT_CHECK(LOOP_TIMER, BIT_TIMER_10HZ) ) { crankingEnrichTaper++; } } return crankingValue; } @@ -298,40 +298,48 @@ uint16_t correctionCranking() * where an additional amount of fuel is added (Over and above the WUE amount). * * @return uint8_t The After Start Enrichment modifier as a %. 100% = No modification. - */ + */ byte correctionASE() { - int16_t ASEValue; + int16_t ASEValue = 100; //Two checks are required: //1) Is the engine run time less than the configured ase time //2) Make sure we're not still cranking - if ( BIT_CHECK(LOOP_TIMER, BIT_TIMER_10HZ) || (currentStatus.ASEValue == 0) ) + if( BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK) != true ) { - if ( (currentStatus.runSecs < (table2D_getValue(&ASECountTable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET))) && !(BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK)) ) + if ( BIT_CHECK(LOOP_TIMER, BIT_TIMER_15HZ) || (currentStatus.ASEValue == 0) ) { - BIT_SET(currentStatus.engine, BIT_ENGINE_ASE); //Mark ASE as active. - ASEValue = 100 + table2D_getValue(&ASETable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET); - aseTaper = 0; - } - else - { - if ( (!BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK)) && (aseTaper < configPage2.aseTaperTime) ) //Cranking check needs to be here also, so cranking and afterstart enrichments won't run simultaneously + if ( (currentStatus.runSecs < (table2D_getValue(&ASECountTable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET))) && !(BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK)) ) { BIT_SET(currentStatus.engine, BIT_ENGINE_ASE); //Mark ASE as active. - ASEValue = 100 + map(aseTaper, 0, configPage2.aseTaperTime, table2D_getValue(&ASETable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET), 0); - aseTaper++; + ASEValue = 100 + table2D_getValue(&ASETable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET); + aseTaper = 0; } else { - BIT_CLEAR(currentStatus.engine, BIT_ENGINE_ASE); //Mark ASE as inactive. - ASEValue = 100; + if ( aseTaper < configPage2.aseTaperTime ) //Check if we've reached the end of the taper time + { + BIT_SET(currentStatus.engine, BIT_ENGINE_ASE); //Mark ASE as active. + ASEValue = 100 + map(aseTaper, 0, configPage2.aseTaperTime, table2D_getValue(&ASETable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET), 0); + aseTaper++; + } + else + { + BIT_CLEAR(currentStatus.engine, BIT_ENGINE_ASE); //Mark ASE as inactive. + ASEValue = 100; + } } + + //Safety checks + if(ASEValue > 255) { ASEValue = 255; } + if(ASEValue < 0) { ASEValue = 0; } + currentStatus.ASEValue = (byte)ASEValue; } - - //Safety checks - if(ASEValue > 255) { ASEValue = 255; } - if(ASEValue < 0) { ASEValue = 0; } - currentStatus.ASEValue = (byte)ASEValue; + } + else + { + BIT_CLEAR(currentStatus.engine, BIT_ENGINE_ASE); //Mark ASE as inactive. + ASEValue = 100; } return currentStatus.ASEValue; }