From 974a1e8078ae557041b17d1f69d4e8307be1576f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lino?= Date: Fri, 21 Aug 2015 14:56:36 +0100 Subject: [PATCH] Fixed watt application calculation. --- brew.ino | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/brew.ino b/brew.ino index f76950e..6f430a0 100644 --- a/brew.ino +++ b/brew.ino @@ -395,7 +395,7 @@ void setup() { boilTime = 5400; coolingTime = 120; - startpointTemperature = 45; + startpointTemperature = 30; betaGlucanaseTemperature = 40; debranchingTemperature = 40; proteolyticTemperature = 50; @@ -1033,13 +1033,14 @@ bool isTimeLeft() { return false; } +//HEATING_ELEMENT_MAX_WATTAGE / HEATING_ELEMENT_AC_FREQUENCY_HZ double ulWattToWindowTime( double ulAppliedWatts ) { double ulPulsesRequired = ulAppliedWatts / dWattPerPulse; - return (double)iWindowSize / 1000.0 * ulPulsesRequired; + return (double)iWindowSize / 1000.0 * ulPulsesRequired * 1000.0 / HEATING_ELEMENT_AC_FREQUENCY_HZ; } bool xRegulateTemperature() { - double difference = basePT100.getCurrentTemperature() - cookTemperature; + double difference = cookTemperature - basePT100.getCurrentTemperature(); bool overTemperature = false; double wattage = 0.0; @@ -1084,11 +1085,22 @@ bool xRegulateTemperature() { } // Apply wattage to the element at the right time - if( ulWattToWindowTime( wattage ) > (millis() - windowStartTime)) { + if( ulWattToWindowTime( wattage ) > (millis() - windowStartTime) ) { digitalWrite(HEATING_ELEMENT_OUTPUT_PIN,HIGH); } else { digitalWrite(HEATING_ELEMENT_OUTPUT_PIN,LOW); } + +#ifdef DEBUG + debugPrintFunction("xRegulateTemperature"); + debugPrintVar("difference", difference); + debugPrintVar("overTemperature", overTemperature); + debugPrintVar("wattage", wattage); + debugPrintVar("ulWattToWindowTime( wattage )", ulWattToWindowTime( wattage ) ); + debugPrintVar("millis()", millis()); + debugPrintVar("windowStartTime", windowStartTime); + debugPrintVar("test", ulWattToWindowTime( wattage ) > (millis() - windowStartTime) ); +#endif } bool xRegulatePumpSpeed() { -- 2.24.1