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.

M911-M914.cpp 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 ENABLED(HAVE_TMC2130)
  24. #include "../../gcode.h"
  25. #include "../../../feature/tmc2130.h"
  26. #include "../../../module/stepper_indirection.h"
  27. inline void tmc2130_report_otpw(TMC2130Stepper &st, const char name) {
  28. SERIAL_CHAR(name);
  29. SERIAL_ECHOPGM(" axis temperature prewarn triggered: ");
  30. serialprintPGM(st.getOTPW() ? PSTR("true") : PSTR("false"));
  31. SERIAL_EOL();
  32. }
  33. /**
  34. * M911: Report TMC2130 stepper driver overtemperature pre-warn flag
  35. * The flag is held by the library and persist until manually cleared by M912
  36. */
  37. void GcodeSuite::M911() {
  38. const bool reportX = parser.seen('X'), reportY = parser.seen('Y'), reportZ = parser.seen('Z'), reportE = parser.seen('E'),
  39. reportAll = (!reportX && !reportY && !reportZ && !reportE) || (reportX && reportY && reportZ && reportE);
  40. #if ENABLED(X_IS_TMC2130)
  41. if (reportX || reportAll) tmc2130_report_otpw(stepperX, 'X');
  42. #endif
  43. #if ENABLED(Y_IS_TMC2130)
  44. if (reportY || reportAll) tmc2130_report_otpw(stepperY, 'Y');
  45. #endif
  46. #if ENABLED(Z_IS_TMC2130)
  47. if (reportZ || reportAll) tmc2130_report_otpw(stepperZ, 'Z');
  48. #endif
  49. #if ENABLED(E0_IS_TMC2130)
  50. if (reportE || reportAll) tmc2130_report_otpw(stepperE0, 'E');
  51. #endif
  52. }
  53. inline void tmc2130_clear_otpw(TMC2130Stepper &st, const char name) {
  54. st.clear_otpw();
  55. SERIAL_CHAR(name);
  56. SERIAL_ECHOLNPGM(" prewarn flag cleared");
  57. }
  58. /**
  59. * M912: Clear TMC2130 stepper driver overtemperature pre-warn flag held by the library
  60. */
  61. void GcodeSuite::M912() {
  62. const bool clearX = parser.seen('X'), clearY = parser.seen('Y'), clearZ = parser.seen('Z'), clearE = parser.seen('E'),
  63. clearAll = (!clearX && !clearY && !clearZ && !clearE) || (clearX && clearY && clearZ && clearE);
  64. #if ENABLED(X_IS_TMC2130)
  65. if (clearX || clearAll) tmc2130_clear_otpw(stepperX, 'X');
  66. #endif
  67. #if ENABLED(Y_IS_TMC2130)
  68. if (clearY || clearAll) tmc2130_clear_otpw(stepperY, 'Y');
  69. #endif
  70. #if ENABLED(Z_IS_TMC2130)
  71. if (clearZ || clearAll) tmc2130_clear_otpw(stepperZ, 'Z');
  72. #endif
  73. #if ENABLED(E0_IS_TMC2130)
  74. if (clearE || clearAll) tmc2130_clear_otpw(stepperE0, 'E');
  75. #endif
  76. }
  77. #if ENABLED(HYBRID_THRESHOLD)
  78. #include "../../../module/planner.h"
  79. inline void tmc2130_get_pwmthrs(TMC2130Stepper &st, const char name, const uint16_t spmm) {
  80. SERIAL_CHAR(name);
  81. SERIAL_ECHOPGM(" stealthChop max speed set to ");
  82. SERIAL_ECHOLN(12650000UL * st.microsteps() / (256 * st.stealth_max_speed() * spmm));
  83. }
  84. inline void tmc2130_set_pwmthrs(TMC2130Stepper &st, const char name, const int32_t thrs, const uint32_t spmm) {
  85. st.stealth_max_speed(12650000UL * st.microsteps() / (256 * thrs * spmm));
  86. tmc2130_get_pwmthrs(st, name, spmm);
  87. }
  88. /**
  89. * M913: Set HYBRID_THRESHOLD speed.
  90. */
  91. void GcodeSuite::M913() {
  92. uint16_t values[XYZE];
  93. LOOP_XYZE(i)
  94. values[i] = parser.intval(axis_codes[i]);
  95. #if ENABLED(X_IS_TMC2130)
  96. if (values[X_AXIS]) tmc2130_set_pwmthrs(stepperX, 'X', values[X_AXIS], planner.axis_steps_per_mm[X_AXIS]);
  97. else tmc2130_get_pwmthrs(stepperX, 'X', planner.axis_steps_per_mm[X_AXIS]);
  98. #endif
  99. #if ENABLED(Y_IS_TMC2130)
  100. if (values[Y_AXIS]) tmc2130_set_pwmthrs(stepperY, 'Y', values[Y_AXIS], planner.axis_steps_per_mm[Y_AXIS]);
  101. else tmc2130_get_pwmthrs(stepperY, 'Y', planner.axis_steps_per_mm[Y_AXIS]);
  102. #endif
  103. #if ENABLED(Z_IS_TMC2130)
  104. if (values[Z_AXIS]) tmc2130_set_pwmthrs(stepperZ, 'Z', values[Z_AXIS], planner.axis_steps_per_mm[Z_AXIS]);
  105. else tmc2130_get_pwmthrs(stepperZ, 'Z', planner.axis_steps_per_mm[Z_AXIS]);
  106. #endif
  107. #if ENABLED(E0_IS_TMC2130)
  108. if (values[E_AXIS]) tmc2130_set_pwmthrs(stepperE0, 'E', values[E_AXIS], planner.axis_steps_per_mm[E_AXIS]);
  109. else tmc2130_get_pwmthrs(stepperE0, 'E', planner.axis_steps_per_mm[E_AXIS]);
  110. #endif
  111. }
  112. #endif // HYBRID_THRESHOLD
  113. #if ENABLED(SENSORLESS_HOMING)
  114. inline void tmc2130_get_sgt(TMC2130Stepper &st, const char name) {
  115. SERIAL_CHAR(name);
  116. SERIAL_ECHOPGM(" driver homing sensitivity set to ");
  117. SERIAL_ECHOLN(st.sgt());
  118. }
  119. inline void tmc2130_set_sgt(TMC2130Stepper &st, const char name, const int8_t sgt_val) {
  120. st.sgt(sgt_val);
  121. tmc2130_get_sgt(st, name);
  122. }
  123. /**
  124. * M914: Set SENSORLESS_HOMING sensitivity.
  125. */
  126. void GcodeSuite::M914() {
  127. #if ENABLED(X_IS_TMC2130)
  128. if (parser.seen(axis_codes[X_AXIS])) tmc2130_set_sgt(stepperX, 'X', parser.value_int());
  129. else tmc2130_get_sgt(stepperX, 'X');
  130. #endif
  131. #if ENABLED(Y_IS_TMC2130)
  132. if (parser.seen(axis_codes[Y_AXIS])) tmc2130_set_sgt(stepperY, 'Y', parser.value_int());
  133. else tmc2130_get_sgt(stepperY, 'Y');
  134. #endif
  135. }
  136. #endif // SENSORLESS_HOMING
  137. #endif // HAVE_TMC2130