Browse Source

Cooler (for Laser) - M143, M193 (#21255)

Mike La Spina 4 years ago
parent
commit
b95e548ddb

+ 4 - 0
Marlin/Configuration.h

@@ -329,8 +329,10 @@
     #define AUTO_POWER_E_FANS
     #define AUTO_POWER_CONTROLLERFAN
     #define AUTO_POWER_CHAMBER_FAN
+    #define AUTO_POWER_COOLER_FAN
     //#define AUTO_POWER_E_TEMP        50 // (°C) Turn on PSU if any extruder is over this temperature
     //#define AUTO_POWER_CHAMBER_TEMP  30 // (°C) Turn on PSU if the chamber is over this temperature
+    //#define AUTO_POWER_COOLER_TEMP   26 // (°C) Turn on PSU if the cooler is over this temperature
     #define POWER_TIMEOUT              30 // (s) Turn off power if the machine is idle for this duration
     //#define POWER_OFF_DELAY          60 // (s) Delay of poweroff after M81 command. Useful to let fans run for extra time.
   #endif
@@ -418,6 +420,7 @@
 #define TEMP_SENSOR_BED 0
 #define TEMP_SENSOR_PROBE 0
 #define TEMP_SENSOR_CHAMBER 0
+#define TEMP_SENSOR_COOLER 0
 
 // Dummy thermistor constant temperature readings, for use with 998 and 999
 #define DUMMY_THERMISTOR_998_VALUE  25
@@ -636,6 +639,7 @@
 #define THERMAL_PROTECTION_HOTENDS // Enable thermal protection for all extruders
 #define THERMAL_PROTECTION_BED     // Enable thermal protection for the heated bed
 #define THERMAL_PROTECTION_CHAMBER // Enable thermal protection for the heated chamber
+#define THERMAL_PROTECTION_COOLER  // Enable thermal protection for the laser cooling
 
 //===========================================================================
 //============================= Mechanical Settings =========================

+ 44 - 0
Marlin/Configuration_adv.h

@@ -113,6 +113,12 @@
   #define CHAMBER_BETA                 3950    // Beta value
 #endif
 
+#if TEMP_SENSOR_COOLER == 1000
+  #define COOLER_PULLUP_RESISTOR_OHMS 4700    // Pullup resistor
+  #define COOLER_RESISTANCE_25C_OHMS  100000  // Resistance at 25C
+  #define COOLER_BETA                 3950    // Beta value
+#endif
+
 #if TEMP_SENSOR_PROBE == 1000
   #define PROBE_PULLUP_RESISTOR_OHMS   4700    // Pullup resistor
   #define PROBE_RESISTANCE_25C_OHMS    100000  // Resistance at 25C
@@ -179,6 +185,25 @@
   #endif
 #endif
 
+//
+// Laser Cooler options
+//
+#if TEMP_SENSOR_COOLER
+  #define COOLER_MINTEMP           8  // (°C)
+  #define COOLER_MAXTEMP          26  // (°C)
+  #define COOLER_DEFAULT_TEMP     16  // (°C)
+  #define TEMP_COOLER_HYSTERESIS   1  // (°C) Temperature proximity considered "close enough" to the target
+  #define COOLER_PIN               8  // Laser cooler on/off pin used to control power to the cooling element e.g. TEC, External chiller via relay
+  #define COOLER_INVERTING     false
+  #define TEMP_COOLER_PIN         15  // Laser/Cooler temperature sensor pin. ADC is required.
+  #define COOLER_FAN                  // Enable a fan on the cooler, Fan# 0,1,2,3 etc.
+  #define COOLER_FAN_INDEX         0  // FAN number 0, 1, 2 etc. e.g.
+  #if ENABLED(COOLER_FAN)
+    #define COOLER_FAN_BASE      100  // Base Cooler fan PWM (0-255); turns on when Cooler temperature is above the target
+    #define COOLER_FAN_FACTOR     25  // PWM increase per °C above target
+  #endif
+#endif
+
 /**
  * Thermal Protection provides additional protection to your printer from damage
  * and fire. Marlin always includes safe min and max temperature ranges which
@@ -248,6 +273,20 @@
   #define WATCH_CHAMBER_TEMP_INCREASE           2 // Degrees Celsius
 #endif
 
+/**
+ * Thermal Protection parameters for the laser cooler.
+ */
+#if ENABLED(THERMAL_PROTECTION_COOLER)
+  #define THERMAL_PROTECTION_COOLER_PERIOD    10 // Seconds
+  #define THERMAL_PROTECTION_COOLER_HYSTERESIS 3 // Degrees Celsius
+
+  /**
+   * Laser cooling watch settings (M143/M193).
+   */
+  #define WATCH_COOLER_TEMP_PERIOD            60 // Seconds
+  #define WATCH_COOLER_TEMP_INCREASE           3 // Degrees Celsius
+#endif
+
 #if ENABLED(PIDTEMP)
   // Add an experimental additional term to the heater power, proportional to the extrusion speed.
   // A well-chosen Kc value should add just enough power to melt the increased material volume.
@@ -493,11 +532,15 @@
 #define E6_AUTO_FAN_PIN -1
 #define E7_AUTO_FAN_PIN -1
 #define CHAMBER_AUTO_FAN_PIN -1
+#define COOLER_AUTO_FAN_PIN -1
+#define COOLER_FAN_PIN -1
 
 #define EXTRUDER_AUTO_FAN_TEMPERATURE 50
 #define EXTRUDER_AUTO_FAN_SPEED 255   // 255 == full speed
 #define CHAMBER_AUTO_FAN_TEMPERATURE 30
 #define CHAMBER_AUTO_FAN_SPEED 255
+#define COOLER_AUTO_FAN_TEMPERATURE 18
+#define COOLER_AUTO_FAN_SPEED 255
 
 /**
  * Part-Cooling Fan Multiplexer
@@ -1495,6 +1538,7 @@
   #define STATUS_BED_ANIM             // Use a second bitmap to indicate bed heating
   #define STATUS_CHAMBER_ANIM         // Use a second bitmap to indicate chamber heating
   //#define STATUS_CUTTER_ANIM        // Use a second bitmap to indicate spindle / laser active
+  //#define STATUS_COOLER_ANIM        // Use a second bitmap to indicate laser cooling
   //#define STATUS_ALT_BED_BITMAP     // Use the alternative bed bitmap
   //#define STATUS_ALT_FAN_BITMAP     // Use the alternative fan bitmap
   //#define STATUS_FAN_FRAMES 3       // :[0,1,2,3,4] Number of fan animation frames

+ 1 - 1
Marlin/src/HAL/AVR/fastio.h

@@ -285,7 +285,7 @@ enum ClockSource2 : char {
  */
 
 // Determine which harware PWMs are already in use
-#define _PWM_CHK_FAN_B(P) (P == E0_AUTO_FAN_PIN || P == E1_AUTO_FAN_PIN || P == E2_AUTO_FAN_PIN || P == E3_AUTO_FAN_PIN || P == E4_AUTO_FAN_PIN || P == E5_AUTO_FAN_PIN || P == E6_AUTO_FAN_PIN || P == E7_AUTO_FAN_PIN || P == CHAMBER_AUTO_FAN_PIN)
+#define _PWM_CHK_FAN_B(P) (P == E0_AUTO_FAN_PIN || P == E1_AUTO_FAN_PIN || P == E2_AUTO_FAN_PIN || P == E3_AUTO_FAN_PIN || P == E4_AUTO_FAN_PIN || P == E5_AUTO_FAN_PIN || P == E6_AUTO_FAN_PIN || P == E7_AUTO_FAN_PIN || P == CHAMBER_AUTO_FAN_PIN || P == COOLER_AUTO_FAN_PIN)
 #if PIN_EXISTS(CONTROLLER_FAN)
   #define PWM_CHK_FAN_B(P) (_PWM_CHK_FAN_B(P) || P == CONTROLLER_FAN_PIN)
 #else

+ 1 - 0
Marlin/src/HAL/ESP32/HAL.cpp

@@ -185,6 +185,7 @@ void HAL_adc_init() {
   TERN_(HAS_TEMP_ADC_7, adc3_set_attenuation(get_channel(TEMP_7_PIN), ADC_ATTEN_11db));
   TERN_(HAS_HEATED_BED, adc1_set_attenuation(get_channel(TEMP_BED_PIN), ADC_ATTEN_11db));
   TERN_(HAS_TEMP_CHAMBER, adc1_set_attenuation(get_channel(TEMP_CHAMBER_PIN), ADC_ATTEN_11db));
+  TERN_(HAS_TEMP_COOLER, adc1_set_attenuation(get_channel(TEMP_COOLER_PIN), ADC_ATTEN_11db));
   TERN_(FILAMENT_WIDTH_SENSOR, adc1_set_attenuation(get_channel(FILWIDTH_PIN), ADC_ATTEN_11db));
 
   // Note that adc2 is shared with the WiFi module, which has higher priority, so the conversion may fail.

+ 14 - 0
Marlin/src/HAL/SAMD51/HAL.cpp

@@ -57,6 +57,7 @@
 #define GET_PROBE_ADC()           TERN(HAS_TEMP_PROBE,        PIN_TO_ADC(TEMP_PROBE_PIN),   -1)
 #define GET_BED_ADC()             TERN(HAS_TEMP_ADC_BED,      PIN_TO_ADC(TEMP_BED_PIN),     -1)
 #define GET_CHAMBER_ADC()         TERN(HAS_TEMP_ADC_CHAMBER,  PIN_TO_ADC(TEMP_CHAMBER_PIN), -1)
+#define GET_COOLER_ADC()          TERN(HAS_TEMP_ADC_COOLER,   PIN_TO_ADC(TEMP_COOLER_PIN),  -1)
 #define GET_FILAMENT_WIDTH_ADC()  TERN(FILAMENT_WIDTH_SENSOR, PIN_TO_ADC(FILWIDTH_PIN),     -1)
 #define GET_BUTTONS_ADC()         TERN(HAS_ADC_BUTTONS,       PIN_TO_ADC(ADC_KEYPAD_PIN),   -1)
 
@@ -66,6 +67,7 @@
   || GET_PROBE_ADC() == n          \
   || GET_BED_ADC() == n            \
   || GET_CHAMBER_ADC() == n        \
+  || GET_COOLER_ADC() == n         \
   || GET_FILAMENT_WIDTH_ADC() == n \
   || GET_BUTTONS_ADC() == n        \
 )
@@ -144,6 +146,9 @@ uint16_t HAL_adc_result;
     #if GET_CHAMBER_ADC() == 0
       TEMP_CHAMBER_PIN,
     #endif
+    #if GET_COOLER_ADC() == 0
+      TEMP_COOLER_PIN,
+    #endif
     #if GET_FILAMENT_WIDTH_ADC() == 0
       FILWIDTH_PIN,
     #endif
@@ -184,6 +189,9 @@ uint16_t HAL_adc_result;
     #if GET_CHAMBER_ADC() == 1
       TEMP_CHAMBER_PIN,
     #endif
+    #if GET_COOLER_ADC() == 1
+      TEMP_COOLER_PIN,
+    #endif
     #if GET_FILAMENT_WIDTH_ADC() == 1
       FILWIDTH_PIN,
     #endif
@@ -232,6 +240,9 @@ uint16_t HAL_adc_result;
       #if GET_CHAMBER_ADC() == 0
         { PIN_TO_INPUTCTRL(TEMP_CHAMBER_PIN) },
       #endif
+      #if GET_COOLER_ADC() == 0
+        { PIN_TO_INPUTCTRL(TEMP_COOLER_PIN) },
+      #endif
       #if GET_FILAMENT_WIDTH_ADC() == 0
         { PIN_TO_INPUTCTRL(FILWIDTH_PIN) },
       #endif
@@ -281,6 +292,9 @@ uint16_t HAL_adc_result;
       #if GET_CHAMBER_ADC() == 1
         { PIN_TO_INPUTCTRL(TEMP_CHAMBER_PIN) },
       #endif
+      #if GET_COOLER_ADC() == 1
+        { PIN_TO_INPUTCTRL(TEMP_COOLER_PIN) },
+      #endif
       #if GET_FILAMENT_WIDTH_ADC() == 1
         { PIN_TO_INPUTCTRL(FILWIDTH_PIN) },
       #endif

+ 9 - 0
Marlin/src/HAL/STM32F1/HAL.cpp

@@ -132,6 +132,9 @@ const uint8_t adc_pins[] = {
   #if HAS_TEMP_CHAMBER
     TEMP_CHAMBER_PIN,
   #endif
+  #if HAS_TEMP_COOLER
+    TEMP_COOLER_PIN,
+  #endif
   #if HAS_TEMP_ADC_1
     TEMP_1_PIN,
   #endif
@@ -189,6 +192,9 @@ enum TempPinIndex : char {
   #if HAS_TEMP_CHAMBER
     TEMP_CHAMBER,
   #endif
+  #if HAS_TEMP_COOLER
+    TEMP_COOLER_PIN,
+  #endif
   #if HAS_TEMP_ADC_1
     TEMP_1,
   #endif
@@ -385,6 +391,9 @@ void HAL_adc_start_conversion(const uint8_t adc_pin) {
     #if HAS_TEMP_CHAMBER
       case TEMP_CHAMBER_PIN: pin_index = TEMP_CHAMBER; break;
     #endif
+    #if HAS_TEMP_COOLER
+      case TEMP_COOLER_PIN: pin_index = TEMP_COOLER; break;
+    #endif
     #if HAS_TEMP_ADC_1
       case TEMP_1_PIN: pin_index = TEMP_1; break;
     #endif

+ 18 - 17
Marlin/src/HAL/STM32F1/msc_sd.cpp

@@ -43,26 +43,27 @@ Serial0Type<USBCompositeSerial> MarlinCompositeSerial(true);
 
 #if ENABLED(EMERGENCY_PARSER)
 
-// The original callback is not called (no way to retrieve address).
-// That callback detects a special STM32 reset sequence: this functionality is not essential
-// as M997 achieves the same.
-void my_rx_callback(unsigned int, void*) {
-  // max length of 16 is enough to contain all emergency commands
-  uint8 buf[16];
+  // The original callback is not called (no way to retrieve address).
+  // That callback detects a special STM32 reset sequence: this functionality is not essential
+  // as M997 achieves the same.
+  void my_rx_callback(unsigned int, void*) {
+    // max length of 16 is enough to contain all emergency commands
+    uint8 buf[16];
 
-  //rx is usbSerialPart.endpoints[2]
-  uint16 len = usb_get_ep_rx_count(usbSerialPart.endpoints[2].address);
-  uint32 total = composite_cdcacm_data_available();
+    //rx is usbSerialPart.endpoints[2]
+    uint16 len = usb_get_ep_rx_count(usbSerialPart.endpoints[2].address);
+    uint32 total = composite_cdcacm_data_available();
 
-  if (len == 0 || total == 0 || !WITHIN(total, len, COUNT(buf)))
-    return;
+    if (len == 0 || total == 0 || !WITHIN(total, len, COUNT(buf)))
+      return;
 
-  // cannot get character by character due to bug in composite_cdcacm_peek_ex
-  len = composite_cdcacm_peek(buf, total);
+    // cannot get character by character due to bug in composite_cdcacm_peek_ex
+    len = composite_cdcacm_peek(buf, total);
+
+    for (uint32 i = 0; i < len; i++)
+      emergency_parser.update(MarlinCompositeSerial.emergency_state, buf[i+total-len]);
+  }
 
-  for (uint32 i = 0; i < len; i++)
-    emergency_parser.update(MarlinCompositeSerial.emergency_state, buf[i+total-len]);
-}
 #endif
 
 void MSC_SD_init() {
@@ -87,7 +88,7 @@ void MSC_SD_init() {
   MarlinCompositeSerial.registerComponent();
   USBComposite.begin();
   #if ENABLED(EMERGENCY_PARSER)
-  	composite_cdcacm_set_hooks(USBHID_CDCACM_HOOK_RX, my_rx_callback);
+    composite_cdcacm_set_hooks(USBHID_CDCACM_HOOK_RX, my_rx_callback);
   #endif
 }
 

+ 2 - 0
Marlin/src/core/language.h

@@ -247,6 +247,8 @@
 
 #define STR_HEATER_BED                      "bed"
 #define STR_HEATER_CHAMBER                  "chamber"
+#define STR_COOLER                          "cooler"
+#define STR_LASER_TEMP                      "laser temperature"
 
 #define STR_STOPPED_HEATER                  ", system stopped! Heater_ID: "
 #define STR_REDUNDANCY                      "Heater switched off. Temperature difference between temp sensors is too high !"

+ 37 - 0
Marlin/src/feature/cooler.cpp

@@ -0,0 +1,37 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "../inc/MarlinConfig.h"
+
+#if HAS_COOLER
+
+#include "cooler.h"
+Cooler cooler;
+
+uint16_t Cooler::flowrate;        // Flow meter reading in liters, 0 will result in shutdown if equiped
+uint8_t Cooler::mode = 0;         // 0 = CO2 Liquid cooling, 1 = Laser Diode TEC Heatsink Cooling
+uint16_t Cooler::capacity;        // Cooling capacity in watts
+uint16_t Cooler::load;            // Cooling load in watts
+bool Cooler::flowmeter = false;
+bool Cooler::state = false;       // on = true, off = false
+
+#endif

+ 50 - 0
Marlin/src/feature/cooler.h

@@ -0,0 +1,50 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+#pragma once
+
+#include <stdint.h>
+
+#define _MSG_COOLER(M) MSG_COOLER_##M
+#define MSG_COOLER(M) _MSG_COOLER(M)
+
+// Cooling device
+
+class Cooler {
+public:
+  static uint16_t flowrate;        // Flow meter reading in liters, 0 will result in shutdown if equiped
+  static uint8_t mode;             // 0 = CO2 Liquid cooling, 1 = Laser Diode TEC Heatsink Cooling
+  static uint16_t capacity;        // Cooling capacity in watts
+  static uint16_t load;            // Cooling load in watts
+  static bool flowmeter;
+  static bool state;               // on = true, off = false
+
+  static bool is_enabled()                    { return state; }
+  static void enable()                        { state = true; }
+  static void disable()                       { state = false; }
+  static void set_mode(const uint8_t m)       { mode = m; }
+  static void set_flowmeter(const bool sflag) { flowmeter = sflag; }
+  static uint16_t get_flowrate()              { return flowrate; }
+  static void update_flowrate(uint16_t flow)  { flowrate = flow; }
+  //static void init() { set_state(false); }
+};
+
+extern Cooler cooler;

Some files were not shown because too many files changed in this diff