소스 검색

Added stage and routine for reflow

Toby Chui 1 년 전
부모
커밋
d7f2e3cce4
2개의 변경된 파일125개의 추가작업 그리고 37개의 파일을 삭제
  1. 108 35
      firmware/reflow/reflow.ino
  2. 17 2
      firmware/reflow/utils.ino

+ 108 - 35
firmware/reflow/reflow.ino

@@ -17,32 +17,52 @@
 #define LED_PREHEAT 15 //P1.5
 #define LED_REFLOW 16 //P1.6
 
-#define HOLDSTART_TIME 100 //in cycles
+//Timing settings. Each cycle is approximately 100ms
+#define HOLDSTART_TIME 100 //START Button hold down time in cycles
+#define SOAKING_TIME 6000 //SOAKING temperature upkeep time in cycles
+
+//Temperature Settings
 #define COOLDOWN_TEMP_ADC 255 //Room temperature
-//Preheat power settings
+//Preheat temp & power
 #define PREHEAT_TEMP_ADC 155 //160 degree C
-#define PREHEAT_PWR_PWM 150 //160 degree C
-
-//Reflow power settings
+#define PREHEAT_PWR_PWM 130 //50% power output
+//Reflow temp & power
 #define REFLOW_TEMP_ADC 123 //220 degree C
-#define REFLOW_PWR_PWM 255
-
-#define CUTOFF_TEMP_ADC 100 //240 degree C, overheat cutoff
+#define REFLOW_PWR_PWM 255 //100% power output
+//Overheat cutoff temp 
+#define CUTOFF_TEMP_ADC 100 //240 degree C
 
 //Func def
-void updateHeaterPowerState();
+bool updateHeaterPowerState();
 void updateKeyStates();
 int readTemp();
 
 
 //Runtimes
-bool reflowing = false;
-int startCountdown = HOLDSTART_TIME; //Hold for 1000ms to start
-int currentHeatplateTemp = 0; //Converted temperature in degree C (rounded)
+bool reflowing = false; //Reflow has started
+bool reflowComplete = false; //Indicate if the stopping is done because of reflow complete
+/*
+  Reflow Stages define what is the next state the hotplate should reach
+  0: Standby
+  1: Preheating
+  2: Preheat Holding / Soaking
+  3: Reflowing 
+  4: Cooling down 
+*/
+int reflowStages = 0; 
+int startCountdown = HOLDSTART_TIME; //Hold for HOLDSTART_TIME to start to prevent accidental touches
 int cycleCounter = 0; //Record cycle time up to 10 seconds
+int soakingCountdown = SOAKING_TIME;
+
+//Blink state controls
 bool blinkState = false; //If blinking this will be switching between true and false
-bool reflowComplete = false; //Indicate if the stopping is done because of reflow complete
+bool blinkYellow = true; //Slow blink yellow if enabled (Standby). Do not enable both yellow and red at the same time
+bool blinkRed = false; //Slow blink red if enable (End of Reflow). Do not enable both yellow and red at the same time
+bool fastBlinkState = false; 
+bool fastblinkRed = false;
 
+
+//Real-time temperature control targets
 int targetTempADC = 255; //Target ADC reading to reach, 255 = room temperature
 int targetPwrPWM = 0; //Target PWM cycle for heater, 255 = full power, 0 = off
 int offset = 1; //Allow +-offset for the ADC reading before reheating / cooling
@@ -71,39 +91,92 @@ void loop() {
   //Check key status
   updateKeyStates();
 
-  //Update current temperature value
+  //Main reflowing logics
+  //Add delay to the end of each conditions so each loop cycle is approximate 100ms
   if (reflowing){
-    //Reflowing. cycle time = 100ms
-    updateHeaterPowerState();
-  }else{
-    //Standby, cycle time = 10ms
-    digitalWrite(HEATER_PIN, LOW);
-    if (cycleCounter%200 == 0){
-      if (reflowComplete){
-        //Reflow done blink
-        if (blinkState){
+    bool tempReached = updateHeaterPowerState();
+    if (tempReached){
+      //This stage temperature reached. Move to next stage
+      if (reflowStages == 1){
+        //Preheat stage completed. Enter soaking stage
+        USBSerial_println("Preheat temperature reached. Soaking started");
+        reflowStages = 2; //Set reflow stage to soaking
+        soakingCountdown = SOAKING_TIME;
+        fastblinkRed = true;
+      }else if (reflowStages == 2){
+        //Wait for the soaking to complete and enter reflow stage
+        soakingCountdown--;
+        if (soakingCountdown <= 0){
+          //Soaking completed. Enter reflow stage
+          USBSerial_println("Soaking time ended. Reflow started");
+
+          //Set Reflow LED to high
+          fastblinkRed = false;
           digitalWrite(LED_REFLOW, HIGH);
-        }else{
-          digitalWrite(LED_REFLOW, LOW);
+
+          //Set to reflow temperature
+          targetTempADC = REFLOW_TEMP_ADC; //Set the target temp to reflow
+          targetPwrPWM = REFLOW_PWR_PWM; //Set power rating to reflow
+          
+          //Update the reflow stage to 3
+          reflowStages = 3;
         }
+      }else if (reflowStages == 3){
+        //Reflowing target temperature reached. Start cooldown and shut down heater
+        reflowStages = 4;
+        blinkYellow = false;
+        blinkRed = true;
+        targetTempADC = COOLDOWN_TEMP_ADC;
+        targetPwrPWM = 0;
+
+        //Reflow ended. Wait until stop being press to exit this state
+      }
+    }
+
+
+  delay(1);
+  }else{
+    //Standby mode
+    digitalWrite(HEATER_PIN, LOW);
+    blinkYellow = true;
+    delay(100);
+  }
+
+  //FastBlink handler, execute every 500ms
+  if (cycleCounter%5 == 0){
+    if (fastblinkRed){
+      digitalWrite(LED_REFLOW, HIGH);
+    }else{
+      digitalWrite(LED_REFLOW, LOW);
+    }
+    fastBlinkState = !fastBlinkState;
+  }
+
+  //Blink handler, execute every 2 seconds
+  if (cycleCounter%20 == 0){
+    if (blinkYellow){
+      if (blinkState){
+        digitalWrite(LED_PREHEAT, HIGH);
       }else{
-        //Standby blink
-        if (blinkState){
-          digitalWrite(LED_PREHEAT, HIGH);
-        }else{
-          digitalWrite(LED_PREHEAT, LOW);
-        }
+        digitalWrite(LED_PREHEAT, LOW);
+      }
+    }else if (blinkRed){
+      if (blinkState){
+        digitalWrite(LED_REFLOW, HIGH);
+      }else{
+        digitalWrite(LED_REFLOW, LOW);
       }
-      
-      blinkState = !blinkState;
+    }else{
+      digitalWrite(LED_REFLOW, LOW);
+      digitalWrite(LED_PREHEAT, LOW);
     }
-    delay(10);
+    blinkState = !blinkState;
   }
 
   //Cycle printout
   //USBSerial_println("cycle");
   cycleCounter++;
-  if (cycleCounter > 10000){
+  if (cycleCounter > 600){
     cycleCounter = 0;
   }
 }

+ 17 - 2
firmware/reflow/utils.ino

@@ -30,25 +30,29 @@ int readTemp() {
 
 //Update heater power state base on temp reading
 //The hotter the plate, the smaller the ADC reading
-void updateHeaterPowerState(){
+//Return true when the temperature is within target range
+bool updateHeaterPowerState(){
   int currentADC = readTemp();
   if (currentADC <= CUTOFF_TEMP_ADC){
     digitalWrite(HEATER_PIN, LOW);
     USBSerial_println("!!! OVERHEAT !!!");
-    return;
+    return false;
   }
   if (currentADC > targetTempADC + offset){
     //Temperature too low. Turn on the heater
     analogWrite(HEATER_PIN, targetPwrPWM);
     USBSerial_print("+ ");
     USBSerial_println(currentADC);
+    return false;
   }else if (currentADC < targetTempADC - offset){
     //Temperature too high. Turn off the heater
     analogWrite(HEATER_PIN, 0);
     USBSerial_print("- ");
     USBSerial_println(currentADC);
+    return false;
   }else{
     //Within range. Keep the current state
+    return true;
   }
 }
 
@@ -69,6 +73,7 @@ void updateKeyStates(){
       targetTempADC = PREHEAT_TEMP_ADC; //Set the target temp to preheat
       targetPwrPWM = PREHEAT_PWR_PWM; //Set power rating to preheat
       digitalWrite(LED_PREHEAT, HIGH); //Light up the preheat LED
+      reflowStages = 1; //Set the reflow stage to preheating
     }
   } else {
     //Touch released
@@ -79,6 +84,16 @@ void updateKeyStates(){
   if (touchResult & (1 << 5)) {
     reflowing= false;
     USBSerial_println("Reflow Stopped");
+    //Set target temperature to room temp and shut down heater
     targetTempADC = COOLDOWN_TEMP_ADC;
+     targetPwrPWM = 0;
+
+    //Set yellow LED to slow blink
+    blinkYellow = true;
+    blinkRed = false;
+    fastblinkRed = false;
+
+    //Set reflow stage to standby
+    reflowStages = 0;
   }
 }