From 8b95fe891afcc89ebcf85ad085d881f99f7fa5bd Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Thu, 27 Oct 2016 07:03:42 +1100 Subject: [PATCH] Improved fan on/off logic --- auxiliaries.ino | 17 ++++++++++++----- globals.h | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/auxiliaries.ino b/auxiliaries.ino index 17e46735..2d3acbed 100644 --- a/auxiliaries.ino +++ b/auxiliaries.ino @@ -10,15 +10,22 @@ Fan control */ void initialiseFan() { -if(configPage4.fanInv == 1) {fanHIGH = LOW, fanLOW = HIGH; } -else {fanHIGH = HIGH, fanLOW = LOW;} -digitalWrite(pinFan, fanLOW); //Initiallise program with the fan in the off state + if(configPage4.fanInv) { fanHIGH = LOW, fanLOW = HIGH; } + else { fanHIGH = HIGH, fanLOW = LOW; } + digitalWrite(pinFan, fanLOW); //Initiallise program with the fan in the off state + currentStatus.fanOn = false; } void fanControl() { - if (currentStatus.coolant >= (configPage4.fanSP - CALIBRATION_TEMPERATURE_OFFSET)) { digitalWrite(pinFan,fanHIGH); } - else if (currentStatus.coolant <= (configPage4.fanSP - configPage4.fanHyster)) { digitalWrite(pinFan, fanLOW); } + if(configPage4.fanEnable) + { + int onTemp = (int)configPage4.fanSP - CALIBRATION_TEMPERATURE_OFFSET; + int offTemp = onTemp - configPage4.fanHyster; + + if (!currentStatus.fanOn && currentStatus.coolant >= onTemp) { digitalWrite(pinFan,fanHIGH); currentStatus.fanOn = true; } + if (currentStatus.fanOn && currentStatus.coolant <= offTemp) { digitalWrite(pinFan, fanLOW); currentStatus.fanOn = false; } + } } #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) diff --git a/globals.h b/globals.h index a7f2006e..1c753a83 100644 --- a/globals.h +++ b/globals.h @@ -139,6 +139,7 @@ struct statuses { byte launchCorrection; //The amount of correction being applied if launch control is active byte afrTarget; byte idleDuty; + bool fanOn; //Whether or not the fan is turned on byte flex; //Ethanol reading (if enabled). 0 = No ethanol, 100 = pure ethanol. Eg E85 = 85. unsigned long TAEEndTime; //The target end time used whenever TAE is turned on volatile byte squirt;