reflow-v6.ino 5.2 KB

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