Commit 3cc06f21 authored by João Lino's avatar João Lino

Fixed the time circuits.

parent 974a1e80
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#define PT100_BASE_DEFAULT_OPERATION_RESISTENCE 0.0 #define PT100_BASE_DEFAULT_OPERATION_RESISTENCE 0.0
#define PT100_UP_DEFAULT_ADC_VMAX 1.1 #define PT100_UP_DEFAULT_ADC_VMAX 1.1
#define PT100_UP_DEFAULT_VS 5.0 #define PT100_UP_DEFAULT_VS 5.0
#define PT100_UP_DEFAULT_R1_RESISTENCE 615.0 #define PT100_UP_DEFAULT_R1_RESISTENCE 618.1
#define PT100_UP_DEFAULT_LINE_RESISTENCE 0.5408314 #define PT100_UP_DEFAULT_LINE_RESISTENCE 0.5408314
#define PT100_UP_DEFAULT_OPERATION_RESISTENCE 0.0 #define PT100_UP_DEFAULT_OPERATION_RESISTENCE 0.0
#define PT100_DOWN_DEFAULT_ADC_VMAX 1.1 #define PT100_DOWN_DEFAULT_ADC_VMAX 1.1
...@@ -123,29 +123,29 @@ eCookingStages cookingStage; ...@@ -123,29 +123,29 @@ eCookingStages cookingStage;
boolean cooking; boolean cooking;
boolean bStageFirstRun; boolean bStageFirstRun;
int clockStartTime; unsigned long clockStartTime;
int clockCounter; unsigned long clockCounter;
int clockIgnore; unsigned long clockIgnore;
boolean clockStart; boolean clockStart;
boolean clockEnd; boolean clockEnd;
int cookTime; unsigned long cookTime;
int cookTemperature; int cookTemperature;
//cook_mode_list cookMode; //cook_mode_list cookMode;
//int cookMixerSpeed; //int cookMixerSpeed;
int cookHeatPWM; int cookHeatPWM;
int startpointTime; unsigned long startpointTime;
int betaGlucanaseTime; unsigned long betaGlucanaseTime;
int debranchingTime; unsigned long debranchingTime;
int proteolyticTime; unsigned long proteolyticTime;
int betaAmylaseTime; unsigned long betaAmylaseTime;
int alphaAmylaseTime; unsigned long alphaAmylaseTime;
int mashoutTime; unsigned long mashoutTime;
int recirculationTime; unsigned long recirculationTime;
int spargeTime; unsigned long spargeTime;
int boilTime; unsigned long boilTime;
int coolingTime; unsigned long coolingTime;
int startpointTemperature; int startpointTemperature;
int betaGlucanaseTemperature; int betaGlucanaseTemperature;
...@@ -383,7 +383,7 @@ void setup() { ...@@ -383,7 +383,7 @@ void setup() {
//cookMixerSpeed = 120; //cookMixerSpeed = 120;
cookHeatPWM = 5; cookHeatPWM = 5;
startpointTime = 120; startpointTime = 3600; //120;
betaGlucanaseTime = 0; betaGlucanaseTime = 0;
debranchingTime = 0; debranchingTime = 0;
proteolyticTime = 0; proteolyticTime = 0;
...@@ -395,7 +395,7 @@ void setup() { ...@@ -395,7 +395,7 @@ void setup() {
boilTime = 5400; boilTime = 5400;
coolingTime = 120; coolingTime = 120;
startpointTemperature = 30; startpointTemperature = 33; //30;
betaGlucanaseTemperature = 40; betaGlucanaseTemperature = 40;
debranchingTemperature = 40; debranchingTemperature = 40;
proteolyticTemperature = 50; proteolyticTemperature = 50;
...@@ -527,8 +527,8 @@ void displayStatus() { ...@@ -527,8 +527,8 @@ void displayStatus() {
lcd.print(cookTemperature); lcd.print(cookTemperature);
// Calculate the numbers on the timer clock // Calculate the numbers on the timer clock
int minutes = clockCounter / 60; unsigned long minutes = clockCounter / 1000 / 60;
int seconds = clockCounter - minutes * 60; unsigned long seconds = (clockCounter / 1000) % 60;
// Position the cursor at the begining of where the timer goes onto the screen // Position the cursor at the begining of where the timer goes onto the screen
lcd.setCursor (10, 1); lcd.setCursor (10, 1);
...@@ -1015,11 +1015,12 @@ void xCountTheTime( int temperatureRange ) { ...@@ -1015,11 +1015,12 @@ void xCountTheTime( int temperatureRange ) {
} }
// Calculate the remaining time on the clock // Calculate the remaining time on the clock
clockCounter = cookTime - (now - clockStartTime - clockIgnore); clockCounter = cookTime * 1000 - (now - clockStartTime - clockIgnore);
#ifdef DEBUG_OFF #ifdef DEBUG
debugPrintFunction("xCountTheTime"); debugPrintFunction("xCountTheTime");
debugPrintVar("millis()", now); debugPrintVar("millis()", now);
debugPrintVar("cookTime", cookTime);
debugPrintVar("clockStartTime", clockStartTime); debugPrintVar("clockStartTime", clockStartTime);
debugPrintVar("clockIgnore", clockIgnore); debugPrintVar("clockIgnore", clockIgnore);
debugPrintVar("clockCounter", clockCounter); debugPrintVar("clockCounter", clockCounter);
...@@ -1086,12 +1087,12 @@ bool xRegulateTemperature() { ...@@ -1086,12 +1087,12 @@ bool xRegulateTemperature() {
// Apply wattage to the element at the right time // 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); //digitalWrite(HEATING_ELEMENT_OUTPUT_PIN,HIGH);
} else { } else {
digitalWrite(HEATING_ELEMENT_OUTPUT_PIN,LOW); digitalWrite(HEATING_ELEMENT_OUTPUT_PIN,LOW);
} }
#ifdef DEBUG #ifdef DEBUG_OFF
debugPrintFunction("xRegulateTemperature"); debugPrintFunction("xRegulateTemperature");
debugPrintVar("difference", difference); debugPrintVar("difference", difference);
debugPrintVar("overTemperature", overTemperature); debugPrintVar("overTemperature", overTemperature);
...@@ -1124,7 +1125,11 @@ void xWarnClockEnded() { ...@@ -1124,7 +1125,11 @@ void xWarnClockEnded() {
sing(MELODY_SUPER_MARIO_START, PIEZO_PIN); sing(MELODY_SUPER_MARIO_START, PIEZO_PIN);
} }
void xStageFirstRun( int stageTime, int stageTemperature, int stagePumpSpeed ) { void xStageFirstRun( int stageTime, int stageTemperature, int stagePumpSpeed, eCookingStages stage ) {
// Set Stage
bStageFirstRun = true;
cookingStage = stage;
// Set the clock // Set the clock
cookTime = stageTime; cookTime = stageTime;
...@@ -1140,9 +1145,94 @@ void xStageFirstRun( int stageTime, int stageTemperature, int stagePumpSpeed ) { ...@@ -1140,9 +1145,94 @@ void xStageFirstRun( int stageTime, int stageTemperature, int stagePumpSpeed ) {
} }
void xTransitionIntoStage_GlobalVariables(eCookingStages nextStage) { void xTransitionIntoStage_GlobalVariables(eCookingStages nextStage) {
// Reset global stage variables
bStageFirstRun = true; // Operate the machine according to the current mode
cookingStage = nextStage; switch(nextStage) {
case eCookingStage_Startpoint: {
// A basic operation for a basic stage
xStageFirstRun( startpointTime, startpointTemperature, 255, eCookingStage_Startpoint );
break;
}
case eCookingStage_BetaGlucanase: {
// A basic operation for a basic stage
xStageFirstRun( betaGlucanaseTime, betaGlucanaseTemperature, 255, eCookingStage_BetaGlucanase );
break;
}
case eCookingStage_Debranching: {
// A basic operation for a basic stage
xStageFirstRun( debranchingTime, debranchingTemperature, 255, eCookingStage_Debranching );
break;
}
case eCookingStage_Proteolytic: {
// A basic operation for a basic stage
xStageFirstRun( proteolyticTime, proteolyticTemperature, 255, eCookingStage_Proteolytic );
break;
}
case eCookingStage_BetaAmylase: {
// A basic operation for a basic stage
xStageFirstRun( betaAmylaseTime, betaAmylaseTemperature, 255, eCookingStage_BetaAmylase );
break;
}
case eCookingStage_AlphaAmylase: {
// A basic operation for a basic stage
xStageFirstRun( alphaAmylaseTime, alphaAmylaseTemperature, 255, eCookingStage_AlphaAmylase );
break;
}
case eCookingStage_Mashout: {
// A basic operation for a basic stage
xStageFirstRun( mashoutTime, mashoutTemperature, 255, eCookingStage_Mashout );
break;
}
case eCookingStage_Recirculation: {
// A basic operation for a basic stage
xStageFirstRun( recirculationTime, recirculationTemperature, 255, eCookingStage_Recirculation );
break;
}
case eCookingStage_Sparge: {
// A basic operation for a basic stage
xStageFirstRun( spargeTime, spargeTemperature, 255, eCookingStage_Sparge );
break;
}
case eCookingStage_Boil: {
// A basic operation for a basic stage
xStageFirstRun( boilTime, boilTemperature, 255, eCookingStage_Boil );
break;
}
case eCookingStage_Cooling: {
// A basic operation for a basic stage
xStageFirstRun( coolingTime, coolingTemperature, 255, eCookingStage_Cooling );
break;
}
case eCookingStage_Purge: {
// A basic operation for a basic stage
xStageFirstRun( 0, 0, 255, eCookingStage_Purge );
xRegulatePumpSpeed();
break;
}
case eCookingStage_Done: {
// A basic operation for a basic stage
xStageFirstRun( 0, 0, 0, eCookingStage_Done );
break;
}
default : {
// A basic operation for a basic stage
xStageFirstRun( 0, 0, 0, eCookingStage_Done );
}
}
} }
void xTransitionIntoStage(eCookingStages nextStage) { void xTransitionIntoStage(eCookingStages nextStage) {
...@@ -1161,18 +1251,20 @@ void xBasicStageOperation( int iStageTime, int iStageTemperature, int iStageTemp ...@@ -1161,18 +1251,20 @@ void xBasicStageOperation( int iStageTime, int iStageTemperature, int iStageTemp
if(bStageFirstRun) { if(bStageFirstRun) {
// Don't run this again // Don't run this again
bStageFirstRun = false; bStageFirstRun = false;
//xStageFirstRun( iStageTime, iStageTemperature, 255 );
// When the stage should be skipped // When the stage should be skipped
if( iStageTime == 0) { if( iStageTime == 0) {
// Continue to the next stage // Continue to the next stage
xTransitionIntoStage_GlobalVariables( nextStage ); //xTransitionIntoStage_GlobalVariables( nextStage );
// There is nothing to do, in this stage // There is nothing to do, in this stage
return; return;
} else { } else {
// Set the clock, target temperature and Reset the clock // Set the clock, target temperature and Reset the clock
//xStageFirstRun( iStageTime, iStageTemperature, PUMP_SPEED_SLOW ); //xStageFirstRun( iStageTime, iStageTemperature, PUMP_SPEED_SLOW );
xStageFirstRun( iStageTime, iStageTemperature, 255 ); //xStageFirstRun( iStageTime, iStageTemperature, 255 );
} }
} else { } else {
// Account for time spent at the target temperature | Input 1: range in ºC within which the target temperature is considered to be reached // Account for time spent at the target temperature | Input 1: range in ºC within which the target temperature is considered to be reached
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment