My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

M190.cpp 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../../inc/MarlinConfig.h"
  23. #if HAS_HEATER_BED && HAS_TEMP_BED
  24. #include "../gcode.h"
  25. #include "../../module/motion.h"
  26. #include "../../module/temperature.h"
  27. #include "../../lcd/ultralcd.h"
  28. #if ENABLED(PRINTJOB_TIMER_AUTOSTART)
  29. #include "../../module/printcounter.h"
  30. #endif
  31. #if ENABLED(PRINTER_EVENT_LEDS)
  32. #include "../../feature/leds/leds.h"
  33. #endif
  34. #include "../../Marlin.h" // for wait_for_heatup and idle()
  35. #ifndef MIN_COOLING_SLOPE_DEG_BED
  36. #define MIN_COOLING_SLOPE_DEG_BED 1.50
  37. #endif
  38. #ifndef MIN_COOLING_SLOPE_TIME_BED
  39. #define MIN_COOLING_SLOPE_TIME_BED 60
  40. #endif
  41. /**
  42. * M190: Sxxx Wait for bed current temp to reach target temp. Waits only when heating
  43. * Rxxx Wait for bed current temp to reach target temp. Waits when heating and cooling
  44. */
  45. void GcodeSuite::M190() {
  46. if (DEBUGGING(DRYRUN)) return;
  47. LCD_MESSAGEPGM(MSG_BED_HEATING);
  48. const bool no_wait_for_cooling = parser.seenval('S');
  49. if (no_wait_for_cooling || parser.seenval('R')) {
  50. thermalManager.setTargetBed(parser.value_celsius());
  51. #if ENABLED(PRINTJOB_TIMER_AUTOSTART)
  52. if (parser.value_celsius() > BED_MINTEMP)
  53. print_job_timer.start();
  54. #endif
  55. }
  56. else return;
  57. #if TEMP_BED_RESIDENCY_TIME > 0
  58. millis_t residency_start_ms = 0;
  59. // Loop until the temperature has stabilized
  60. #define TEMP_BED_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + (TEMP_BED_RESIDENCY_TIME) * 1000UL))
  61. #else
  62. // Loop until the temperature is very close target
  63. #define TEMP_BED_CONDITIONS (wants_to_cool ? thermalManager.isCoolingBed() : thermalManager.isHeatingBed())
  64. #endif
  65. float target_temp = -1.0, old_temp = 9999.0;
  66. bool wants_to_cool = false;
  67. wait_for_heatup = true;
  68. millis_t now, next_temp_ms = 0, next_cool_check_ms = 0;
  69. #if DISABLED(BUSY_WHILE_HEATING)
  70. KEEPALIVE_STATE(NOT_BUSY);
  71. #endif
  72. target_extruder = active_extruder; // for print_heaterstates
  73. #if ENABLED(PRINTER_EVENT_LEDS)
  74. const float start_temp = thermalManager.degBed();
  75. uint8_t old_red = 255;
  76. #endif
  77. do {
  78. // Target temperature might be changed during the loop
  79. if (target_temp != thermalManager.degTargetBed()) {
  80. wants_to_cool = thermalManager.isCoolingBed();
  81. target_temp = thermalManager.degTargetBed();
  82. // Exit if S<lower>, continue if S<higher>, R<lower>, or R<higher>
  83. if (no_wait_for_cooling && wants_to_cool) break;
  84. }
  85. now = millis();
  86. if (ELAPSED(now, next_temp_ms)) { //Print Temp Reading every 1 second while heating up.
  87. next_temp_ms = now + 1000UL;
  88. thermalManager.print_heaterstates();
  89. #if TEMP_BED_RESIDENCY_TIME > 0
  90. SERIAL_PROTOCOLPGM(" W:");
  91. if (residency_start_ms)
  92. SERIAL_PROTOCOL(long((((TEMP_BED_RESIDENCY_TIME) * 1000UL) - (now - residency_start_ms)) / 1000UL));
  93. else
  94. SERIAL_PROTOCOLCHAR('?');
  95. #endif
  96. SERIAL_EOL();
  97. }
  98. idle();
  99. refresh_cmd_timeout(); // to prevent stepper_inactive_time from running out
  100. const float temp = thermalManager.degBed();
  101. #if ENABLED(PRINTER_EVENT_LEDS)
  102. // Gradually change LED strip from blue to violet as bed heats up
  103. if (!wants_to_cool) {
  104. const uint8_t red = map(constrain(temp, start_temp, target_temp), start_temp, target_temp, 0, 255);
  105. if (red != old_red) {
  106. old_red = red;
  107. set_led_color(red, 0, 255
  108. #if ENABLED(NEOPIXEL_RGBW_LED)
  109. , 0, true
  110. #endif
  111. );
  112. }
  113. }
  114. #endif
  115. #if TEMP_BED_RESIDENCY_TIME > 0
  116. const float temp_diff = FABS(target_temp - temp);
  117. if (!residency_start_ms) {
  118. // Start the TEMP_BED_RESIDENCY_TIME timer when we reach target temp for the first time.
  119. if (temp_diff < TEMP_BED_WINDOW) residency_start_ms = now;
  120. }
  121. else if (temp_diff > TEMP_BED_HYSTERESIS) {
  122. // Restart the timer whenever the temperature falls outside the hysteresis.
  123. residency_start_ms = now;
  124. }
  125. #endif // TEMP_BED_RESIDENCY_TIME > 0
  126. // Prevent a wait-forever situation if R is misused i.e. M190 R0
  127. if (wants_to_cool) {
  128. // Break after MIN_COOLING_SLOPE_TIME_BED seconds
  129. // if the temperature did not drop at least MIN_COOLING_SLOPE_DEG_BED
  130. if (!next_cool_check_ms || ELAPSED(now, next_cool_check_ms)) {
  131. if (old_temp - temp < MIN_COOLING_SLOPE_DEG_BED) break;
  132. next_cool_check_ms = now + 1000UL * MIN_COOLING_SLOPE_TIME_BED;
  133. old_temp = temp;
  134. }
  135. }
  136. } while (wait_for_heatup && TEMP_BED_CONDITIONS);
  137. if (wait_for_heatup) LCD_MESSAGEPGM(MSG_BED_DONE);
  138. #if DISABLED(BUSY_WHILE_HEATING)
  139. KEEPALIVE_STATE(IN_HANDLER);
  140. #endif
  141. }
  142. #endif // HAS_HEATER_BED && HAS_TEMP_BED