|
@@ -10,16 +10,17 @@
|
|
|
Start Btn: P1.4
|
|
|
Stop Btn: P1.7
|
|
|
*/
|
|
|
+#include <Serial.h>
|
|
|
#include <TouchKey.h>
|
|
|
|
|
|
-#define TEMP_PIN 11 //P1.1
|
|
|
-#define HEATER_PIN 34 //P3.4
|
|
|
-#define LED_PREHEAT 15 //P1.5
|
|
|
-#define LED_REFLOW 16 //P1.6
|
|
|
+#define TEMP_PIN 11 //P1.1
|
|
|
+#define HEATER_PIN 34 //P3.4
|
|
|
+#define LED_PREHEAT 15 //P1.5
|
|
|
+#define LED_REFLOW 16 //P1.6
|
|
|
|
|
|
//Timing settings. Each cycle is approximately 100ms
|
|
|
-#define HOLDSTART_TIME 30 //START Button hold down time in cycles
|
|
|
-#define SOAKING_TIME 600 //SOAKING temperature upkeep time in cycles
|
|
|
+#define HOLDSTART_TIME 30 //START Button hold down time in cycles
|
|
|
+#define SOAKING_TIME 600 //SOAKING temperature upkeep time in cycles
|
|
|
|
|
|
/*
|
|
|
* Temperature Settings
|
|
@@ -32,16 +33,16 @@
|
|
|
* Note that different setup (e.g. ref resistor value / NTC resistor value) might have different equations
|
|
|
* You can experiment with yours and get a few data point to plot your own line
|
|
|
*/
|
|
|
-#define COOLDOWN_TEMP_ADC 255 //Room temperature
|
|
|
+#define COOLDOWN_TEMP_ADC 255 //Room temperature
|
|
|
//Preheat temp & power
|
|
|
-#define PREHEAT_START_ADC 143 //150 degree C
|
|
|
-#define PREHEAT_TEMP_ADC 122 //160 degree C
|
|
|
-#define PREHEAT_PWR_PWM 155 //60% power output
|
|
|
+#define PREHEAT_START_ADC 143 //150 degree C
|
|
|
+#define PREHEAT_TEMP_ADC 122 //160 degree C
|
|
|
+#define PREHEAT_PWR_PWM 155 //60% power output
|
|
|
//Reflow temp & power
|
|
|
-#define REFLOW_TEMP_ADC 58 //220 degree C
|
|
|
-#define REFLOW_PWR_PWM 255 //100% power output
|
|
|
+#define REFLOW_TEMP_ADC 58 //220 degree C
|
|
|
+#define REFLOW_PWR_PWM 255 //100% power output
|
|
|
//Overheat cutoff temp
|
|
|
-#define CUTOFF_TEMP_ADC 53 //230 degree C
|
|
|
+#define CUTOFF_TEMP_ADC 53 //230 degree C
|
|
|
|
|
|
//Func def
|
|
|
bool updateHeaterPowerState();
|
|
@@ -50,8 +51,8 @@ int readTemp();
|
|
|
|
|
|
|
|
|
//Runtimes
|
|
|
-bool reflowing = false; //Reflow has started
|
|
|
-bool reflowComplete = false; //Indicate if the stopping is done because of reflow complete
|
|
|
+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
|
|
@@ -61,28 +62,36 @@ bool reflowComplete = false; //Indicate if the stopping is done because of reflo
|
|
|
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 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 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 blinkState = false; //If blinking this will be switching between true and false
|
|
|
+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 = 0; //Allow +-offset for the ADC reading before reheating / cooling
|
|
|
+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 = 0; //Allow +-offset for the ADC reading before reheating / cooling
|
|
|
|
|
|
void setup() {
|
|
|
//Enable the touch buttons
|
|
|
//Enable all 6 channels:TIN2(P1.4),TIN5(P1.7)
|
|
|
TouchKey_begin((1 << 2) | (1 << 5));
|
|
|
|
|
|
+ //refer to AN3891 MPR121 Baseline System for more details
|
|
|
+ TouchKey_SetMaxHalfDelta(192); // increase if sensor value are more noisy
|
|
|
+ TouchKey_SetNoiseHalfDelta(4); // If baseline need to adjust at higher rate, increase this value
|
|
|
+ TouchKey_SetNoiseCountLimit(10); // If baseline need to adjust faster, increase this value
|
|
|
+ TouchKey_SetFilterDelayLimit(5); // make overall adjustment slower
|
|
|
+ TouchKey_SetTouchThreshold(220); // Bigger touch pad can use a bigger value
|
|
|
+ TouchKey_SetReleaseThreshold(150); // Smaller than touch threshold
|
|
|
+
|
|
|
//Set LED pins to output
|
|
|
pinMode(LED_PREHEAT, OUTPUT);
|
|
|
pinMode(LED_REFLOW, OUTPUT);
|
|
@@ -105,27 +114,27 @@ void loop() {
|
|
|
//Main reflowing logics
|
|
|
//Add delay to the end of each conditions so each loop cycle is approximate 100ms
|
|
|
if (reflowing) {
|
|
|
- bool tempReached = updateHeaterPowerState(); //This action takes 100ms
|
|
|
+ bool tempReached = updateHeaterPowerState(); //This action takes 100ms
|
|
|
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");
|
|
|
- targetTempADC = PREHEAT_TEMP_ADC; //Set temperature to soaking end temp
|
|
|
- reflowStages = 2; //Set reflow stage to soaking
|
|
|
+ targetTempADC = PREHEAT_TEMP_ADC; //Set temperature to soaking end temp
|
|
|
+ reflowStages = 2; //Set reflow stage to soaking
|
|
|
soakingCountdown = SOAKING_TIME;
|
|
|
fastblinkRed = true;
|
|
|
- }else if (reflowStages == 3) {
|
|
|
- //Reflowing target temperature reached. Start cooldown and shut down heater
|
|
|
- USBSerial_println("Reflow completed. Cooling down");
|
|
|
- reflowStages = 4;
|
|
|
- blinkYellow = false;
|
|
|
- blinkRed = true;
|
|
|
- targetTempADC = COOLDOWN_TEMP_ADC;
|
|
|
- targetPwrPWM = 0;
|
|
|
-
|
|
|
- //Reflow ended. Wait until stop being press to exit this state
|
|
|
- }
|
|
|
+ } else if (reflowStages == 3) {
|
|
|
+ //Reflowing target temperature reached. Start cooldown and shut down heater
|
|
|
+ USBSerial_println("Reflow completed. Cooling down");
|
|
|
+ reflowStages = 4;
|
|
|
+ blinkYellow = false;
|
|
|
+ blinkRed = true;
|
|
|
+ targetTempADC = COOLDOWN_TEMP_ADC;
|
|
|
+ targetPwrPWM = 0;
|
|
|
+
|
|
|
+ //Reflow ended. Wait until stop being press to exit this state
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (reflowStages == 2) {
|
|
@@ -140,8 +149,8 @@ void loop() {
|
|
|
digitalWrite(LED_REFLOW, HIGH);
|
|
|
|
|
|
//Set to reflow temperature
|
|
|
- targetTempADC = REFLOW_TEMP_ADC; //Set the target temp to reflow
|
|
|
- targetPwrPWM = REFLOW_PWR_PWM; //Set power rating to reflow
|
|
|
+ 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;
|