My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2021 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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #include "../inc/MarlinConfigPre.h"
  24. #ifndef FLOWMETER_PPL
  25. #define FLOWMETER_PPL 5880 // Pulses per liter
  26. #endif
  27. #ifndef FLOWMETER_INTERVAL
  28. #define FLOWMETER_INTERVAL 1000 // milliseconds
  29. #endif
  30. // Cooling device
  31. class Cooler {
  32. public:
  33. static uint16_t capacity; // Cooling capacity in watts
  34. static uint16_t load; // Cooling load in watts
  35. static bool enabled;
  36. static void enable() { enabled = true; }
  37. static void disable() { enabled = false; }
  38. static void toggle() { enabled = !enabled; }
  39. static uint8_t mode; // 0 = CO2 Liquid cooling, 1 = Laser Diode TEC Heatsink Cooling
  40. static void set_mode(const uint8_t m) { mode = m; }
  41. #if ENABLED(LASER_COOLANT_FLOW_METER)
  42. static float flowrate; // Flow meter reading in liters-per-minute.
  43. static bool flowmeter; // Flag to monitor the flow
  44. static volatile uint16_t flowpulses; // Flowmeter IRQ pulse count
  45. static millis_t flowmeter_next_ms; // Next time at which to calculate flow
  46. static void set_flowmeter(const bool sflag) {
  47. if (flowmeter != sflag) {
  48. flowmeter = sflag;
  49. if (sflag) {
  50. flowpulses = 0;
  51. flowmeter_next_ms = millis() + FLOWMETER_INTERVAL;
  52. }
  53. }
  54. }
  55. // To calculate flow we only need to count pulses
  56. static void flowmeter_ISR() { flowpulses++; }
  57. // Enable / Disable the flow meter interrupt
  58. static void flowmeter_interrupt_enable() {
  59. attachInterrupt(digitalPinToInterrupt(FLOWMETER_PIN), flowmeter_ISR, RISING);
  60. }
  61. static void flowmeter_interrupt_disable() {
  62. detachInterrupt(digitalPinToInterrupt(FLOWMETER_PIN));
  63. }
  64. // Enable / Disable the flow meter interrupt
  65. static void flowmeter_enable() { set_flowmeter(true); flowpulses = 0; flowmeter_interrupt_enable(); }
  66. static void flowmeter_disable() { set_flowmeter(false); flowmeter_interrupt_disable(); flowpulses = 0; }
  67. // Get the total flow (in liters per minute) since the last reading
  68. static void calc_flowrate() {
  69. //flowmeter_interrupt_disable();
  70. // const uint16_t pulses = flowpulses;
  71. //flowmeter_interrupt_enable();
  72. flowrate = flowpulses * 60.0f * (1000.0f / (FLOWMETER_INTERVAL)) * (1000.0f / (FLOWMETER_PPL));
  73. flowpulses = 0;
  74. }
  75. // Userland task to update the flow meter
  76. static void flowmeter_task(const millis_t ms=millis()) {
  77. if (!flowmeter) // !! The flow meter must always be on !!
  78. flowmeter_enable(); // Init and prime
  79. if (ELAPSED(ms, flowmeter_next_ms)) {
  80. calc_flowrate();
  81. flowmeter_next_ms = ms + FLOWMETER_INTERVAL;
  82. }
  83. }
  84. #if ENABLED(FLOWMETER_SAFETY)
  85. static bool fault; // Flag that the cooler is in a fault state
  86. static bool flowsafety_enabled; // Flag to disable the cutter if flow rate is too low
  87. static void flowsafety_toggle() { flowsafety_enabled = !flowsafety_enabled; }
  88. static bool check_flow_too_low() {
  89. const bool too_low = flowsafety_enabled && flowrate < (FLOWMETER_MIN_LITERS_PER_MINUTE);
  90. if (too_low) fault = true;
  91. return too_low;
  92. }
  93. #endif
  94. #endif
  95. };
  96. extern Cooler cooler;