diff --git a/auxiliaries.ino b/auxiliaries.ino index 3475686..21a1c57 100644 --- a/auxiliaries.ino +++ b/auxiliaries.ino @@ -10,13 +10,13 @@ These functions control the auxillary outputs 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 == 1) {fanHIGH = LOW, fanLOW = HIGH; } +else {fanHIGH = HIGH, fanLOW = LOW;} +digitalWrite(pinFan, fanLOW); //Initiallise program with the fan in the off state } -void FanControl() +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 (currentStatus.coolant >= (configPage4.fanSP - CALIBRATION_TEMPERATURE_OFFSET)) { digitalWrite(pinFan,fanHIGH); } + else if (currentStatus.coolant <= (configPage4.fanSP - configPage4.fanHyster)) { digitalWrite(pinFan, fanLOW); } } diff --git a/globals.h b/globals.h index 7e01eb3..e557d91 100644 --- a/globals.h +++ b/globals.h @@ -236,11 +236,6 @@ struct config3 { //Page 4 of the config mostly deals with idle control //See ini file for further info struct config4 { - byte FanInv : 1; // Fan output inversion bit - byte FanEnable : 1; // Fan enable bit - byte FanSP; // Cooling fan start temperature - byte FanHyster; // Fan hysteresis - byte iacCLValues[10]; //Closed loop target RPM value byte iacOLStepVal[10]; //Open loop step values for stepper motors byte iacOLPWMVal[10]; //Open loop duty values for PMWM valves @@ -258,6 +253,10 @@ struct config4 { byte iacStepHome; //When using a stepper motor, the number of steps to be taken on startup to home the motor byte iacStepHyster; //Hysteresis temperature (*10). Eg 2.2C = 22 + byte fanInv : 1; // Fan output inversion bit + byte fanEnable : 1; // Fan enable bit + byte fanSP; // Cooling fan start temperature + byte fanHyster; // Fan hysteresis }; byte pinInjector1; //Output pin injector 1 diff --git a/speeduino.ino b/speeduino.ino index 4bf8205..299baf0 100644 --- a/speeduino.ino +++ b/speeduino.ino @@ -81,8 +81,8 @@ unsigned long scheduleEnd; byte coilHIGH = HIGH; byte coilLOW = LOW; -byte FanHIGH = HIGH; // Used to invert the cooling fan output -byte FanLOW = LOW; // Used to invert the cooling fan output +byte fanHIGH = HIGH; // Used to invert the cooling fan output +byte fanLOW = LOW; // Used to invert the cooling fan output struct statuses currentStatus; volatile int mainLoopCount; @@ -361,15 +361,6 @@ void loop() currentStatus.O2 = o2CalibrationTable[currentStatus.O2ADC]; } - // Only check the fan controls every 1000 loops to save processing power // ################ - if ((mainLoopCount & 1001) == 1) - { - if (configPage4.FanEnable == 1) - { - FanControl(); // Fucntion to turn the cooling fan on/off - } - } - //Always check for sync //Main loop runs within this clause if (currentStatus.hasSync && (currentStatus.RPM > 0)) diff --git a/timers.ino b/timers.ino index 2ec9716..85636b5 100644 --- a/timers.ino +++ b/timers.ino @@ -77,6 +77,11 @@ ISR(TIMER2_OVF_vect) //increament secl (secl is simply a counter that increments every second and is used to track whether the system has unexpectedly reset currentStatus.secl++; + //Check the fan output status + if (configPage4.fanEnable == 1) + { + fanControl(); // Fucntion to turn the cooling fan on/off + } } //Reset Timer2 to trigger in another ~1ms