My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

M3-M5.cpp 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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_CUTTER
  24. #include "../gcode.h"
  25. #include "../../feature/spindle_laser.h"
  26. #include "../../module/stepper.h"
  27. /**
  28. * Laser:
  29. *
  30. * M3 - Laser ON/Power (Ramped power)
  31. * M4 - Laser ON/Power (Continuous power)
  32. *
  33. * S<power> - Set power. S0 will turn the laser off.
  34. * O<ocr> - Set power and OCR
  35. *
  36. * Spindle:
  37. *
  38. * M3 - Spindle ON (Clockwise)
  39. * M4 - Spindle ON (Counter-clockwise)
  40. *
  41. * S<power> - Set power. S0 will turn the spindle off.
  42. * O<ocr> - Set power and OCR
  43. *
  44. * If no PWM pin is defined then M3/M4 just turns it on.
  45. *
  46. * At least 12.8KHz (50Hz * 256) is needed for Spindle PWM.
  47. * Hardware PWM is required on AVR. ISRs are too slow.
  48. *
  49. * NOTE: WGM for timers 3, 4, and 5 must be either Mode 1 or Mode 5.
  50. * No other settings give a PWM signal that goes from 0 to 5 volts.
  51. *
  52. * The system automatically sets WGM to Mode 1, so no special
  53. * initialization is needed.
  54. *
  55. * WGM bits for timer 2 are automatically set by the system to
  56. * Mode 1. This produces an acceptable 0 to 5 volt signal.
  57. * No special initialization is needed.
  58. *
  59. * NOTE: A minimum PWM frequency of 50 Hz is needed. All prescaler
  60. * factors for timers 2, 3, 4, and 5 are acceptable.
  61. *
  62. * SPINDLE_LASER_ENA_PIN needs an external pullup or it may power on
  63. * the spindle/laser during power-up or when connecting to the host
  64. * (usually goes through a reset which sets all I/O pins to tri-state)
  65. *
  66. * PWM duty cycle goes from 0 (off) to 255 (always on).
  67. */
  68. void GcodeSuite::M3_M4(const bool is_M4) {
  69. #if ENABLED(SPINDLE_FEATURE)
  70. planner.synchronize(); // Wait for movement to complete before changing power
  71. #endif
  72. cutter.set_direction(is_M4);
  73. #if ENABLED(SPINDLE_LASER_PWM)
  74. if (parser.seenval('O'))
  75. cutter.set_ocr_power(parser.value_byte()); // The OCR is a value from 0 to 255 (uint8_t)
  76. else
  77. cutter.set_power(parser.intval('S', 255));
  78. #else
  79. cutter.set_enabled(true);
  80. #endif
  81. }
  82. /**
  83. * M5 - Cutter OFF
  84. */
  85. void GcodeSuite::M5() {
  86. #if ENABLED(SPINDLE_FEATURE)
  87. planner.synchronize();
  88. #endif
  89. cutter.set_enabled(false);
  90. }
  91. #endif // HAS_CUTTER