reflow-v6.ino 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. 60W PD Powered Automatic Reflow Hoteplate
  3. Author: tobychui
  4. Firmware version for v6 or above PCB
  5. Notes:
  6. - Temperature sensing is done using 1k 1% resistor and a 100k Thermistor
  7. You might need to change the code if you are using other values
  8. - If you are using the type-C 6p version of the reflow PCB, and after
  9. pluggin in the type C cable no led lights up, try flip the type C
  10. cable upside down
  11. Button Mappings (Active Low, aka not pressing = HIGH)
  12. Start Btn: P1.4
  13. Stop Btn: P1.7
  14. Download Settings
  15. CH552
  16. 16Mhz (internal, 3.3V or 5V)
  17. */
  18. #include <Serial.h>
  19. /* Hardware Definations */
  20. #define TEMP_PIN 11 //P1.1
  21. #define HEATER_PIN 34 //P3.4
  22. #define LED_PREHEAT 15 //P1.5
  23. #define LED_REFLOW 16 //P1.6
  24. #define START_BTN 14 //P1.4
  25. #define STOP_BTN 17 //P1.7
  26. #define FAN_PIN 33 //P3.3
  27. /* Software Definations */
  28. //Timing settings. Each cycle is approximately 100ms
  29. #define HOLDSTART_TIME 30 //START Button hold down time in cycles
  30. #define HOLDSTOP_TIME 10 //STOP Button hold down time in cycles
  31. #define SOAKING_TIME 600 //SOAKING temperature upkeep time in cycles
  32. #define MAX_CONTINUE_OPR_TIME 3000 //MAX_CONTINUE_OPR automatic shutdown desolder heatbed if continue operate for ~5 minutes for safty reasons
  33. /*
  34. Temperature Settings
  35. The ADC value can be calculated using the following line equation
  36. t=-0.7x+250
  37. where X is ADC reading and t is target temp in degree C
  38. Note that different setup (e.g. ref resistor value / NTC resistor value) might have different equations
  39. You can experiment with yours and get a few data point to plot your own line
  40. */
  41. #define COOLDOWN_TEMP_ADC 255 //Room temperature
  42. //Preheat temp & power
  43. #define PREHEAT_START_ADC 143 //150 degree C
  44. #define PREHEAT_TEMP_ADC 122 //160 degree C
  45. #define PREHEAT_PWR_PWM 155 //60% power output
  46. //Reflow temp & power
  47. #define REFLOW_TEMP_ADC 58 //220 degree C
  48. #define REFLOW_PWR_PWM 255 //100% power output
  49. //Overheat cutoff temp
  50. #define CUTOFF_TEMP_ADC 53 //250 degree C
  51. /* Function Prototypes */
  52. bool updateHeaterPowerState();
  53. void updateKeyStates();
  54. void handleLEDBlinking();
  55. void handleReflowProcedures();
  56. void handleDesolderProcedures();
  57. void enterStandbyMode();
  58. int readTemp();
  59. /* Runtime Variables */
  60. bool reflowing = false; //Reflow has started
  61. bool reflowComplete = false; //Indicate if the stopping is done because of reflow complete
  62. bool startPressed = false; //Start button is pressed down
  63. bool stopPressed = false; //Stop button is pressed down
  64. /*
  65. Reflow Stages define what is the next state the hotplate should reach
  66. 0: Standby
  67. 1: Preheating
  68. 2: Preheat Holding / Soaking
  69. 3: Reflowing
  70. 4: Cooling down
  71. 10: Preheating to reflow temp for desoldering
  72. 11: Desolder Mode (Keep at REFLOW_TEMP_ADC)
  73. */
  74. int reflowStages = 0;
  75. int startCountdown = HOLDSTART_TIME; //Hold for HOLDSTART_TIME to start to prevent accidental touches
  76. int stopcountdown = HOLDSTOP_TIME; //Hold for HOLDSTOP_TIME to stop reflowing
  77. int cycleCounter = 0; //Record cycle time up to 10 seconds
  78. int soakingCountdown = SOAKING_TIME;
  79. int desolderCountdown = MAX_CONTINUE_OPR_TIME; //Prevent overheat
  80. //Blink state controls
  81. bool blinkState = false; //If blinking this will be switching between true and false
  82. bool blinkYellow = true; //Slow blink yellow if enabled (Standby). Do not enable both yellow and red at the same time
  83. bool blinkRed = false; //Slow blink red if enable (End of Reflow). Do not enable both yellow and red at the same time
  84. bool fastBlinkState = false;
  85. bool fastblinkRed = false;
  86. //Real-time temperature control targets
  87. int targetTempADC = 255; //Target ADC reading to reach, 255 = room temperature
  88. int targetPwrPWM = 0; //Target PWM cycle for heater, 255 = full power, 0 = off
  89. int offset = 0; //Allow +-offset for the ADC reading before reheating / cooling
  90. void setup() {
  91. //Set button pins to input
  92. pinMode(START_BTN, INPUT);
  93. pinMode(STOP_BTN, INPUT);
  94. //Set LED pins to output
  95. pinMode(LED_PREHEAT, OUTPUT);
  96. pinMode(LED_REFLOW, OUTPUT);
  97. digitalWrite(LED_PREHEAT, LOW);
  98. digitalWrite(LED_REFLOW, LOW);
  99. //Set temp sense pin to input
  100. pinMode(TEMP_PIN, INPUT);
  101. //Set mosfet control pins to output and disable it
  102. pinMode(HEATER_PIN, OUTPUT);
  103. digitalWrite(HEATER_PIN, LOW);
  104. pinMode(FAN_PIN, OUTPUT);
  105. digitalWrite(FAN_PIN, LOW);
  106. USBSerial_println("Reflow Hotplate Ready!");
  107. }
  108. void loop() {
  109. /* State Check */
  110. updateKeyStates();
  111. /* Main reflowing logics */
  112. //Add delay to the end of each conditions so each loop cycle is approximate 100ms
  113. if (reflowing && reflowStages < 10) {
  114. //Automatic Reflow
  115. handleReflowProcedures();
  116. } else if (reflowing && reflowStages >= 10) {
  117. //Desolder hotplate
  118. handleDesolderProcedures();
  119. } else {
  120. /* Standby Mode */
  121. digitalWrite(HEATER_PIN, LOW);
  122. blinkYellow = true;
  123. delay(100); //adjust this if needed to make sure reflow cycles use the same time as standby cycles
  124. }
  125. /* Blink Signal Handlers */
  126. handleLEDBlinking();
  127. /*
  128. Cycle Counter
  129. Counter are limited to 600 to prevent overflow.
  130. */
  131. cycleCounter++;
  132. if (cycleCounter > 600) {
  133. cycleCounter = 0;
  134. }
  135. }