From 88429b977b1ad8866673686c63c00d85950aa902 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Mon, 4 Jun 2018 17:01:53 +1000 Subject: [PATCH] Minor changes to Simple closed loop AFR algorithm See Issue #142 --- speeduino/corrections.ino | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/speeduino/corrections.ino b/speeduino/corrections.ino index 47601fb3..98125365 100644 --- a/speeduino/corrections.ino +++ b/speeduino/corrections.ino @@ -331,19 +331,21 @@ static inline byte correctionAFRClosedLoop() //Running lean if(currentStatus.egoCorrection < (100 + configPage6.egoLimit) ) //Fueling adjustment must be at most the egoLimit amount (up or down) { - if(currentStatus.egoCorrection >= 100) { AFRValue = (currentStatus.egoCorrection + 1); } //Increase the fueling by 1% - else { AFRValue += 1; } //This means that the last reading had been rich, so start counting back towards 100% + AFRValue = (currentStatus.egoCorrection + 1); //Increase the fueling by 1% } - else { AFRValue = currentStatus.egoCorrection; } //Means we're at the maximum adjustment amount, so simply return then again + else { AFRValue = currentStatus.egoCorrection; } //Means we're at the maximum adjustment amount, so simply return that again } - else + else if(currentStatus.O2 < currentStatus.afrTarget) + { //Running Rich if(currentStatus.egoCorrection > (100 - configPage6.egoLimit) ) //Fueling adjustment must be at most the egoLimit amount (up or down) { - if(currentStatus.egoCorrection <= 100) { AFRValue = (currentStatus.egoCorrection - 1); } //Increase the fueling by 1% - else { AFRValue -= 1; } //This means that the last reading had been lean, so start count back towards 100% + AFRValue = (currentStatus.egoCorrection - 1); //Decrease the fueling by 1% } - else { AFRValue = currentStatus.egoCorrection; } //Means we're at the maximum adjustment amount, so simply return then again + else { AFRValue = currentStatus.egoCorrection; } //Means we're at the maximum adjustment amount, so simply return that again + } + else { AFRValue = currentStatus.egoCorrection; } //Means we're already right on target + } else if(configPage6.egoAlgorithm == EGO_ALGORITHM_PID) {