stepper.cpp 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521
  1. /*
  2. stepper.c - stepper motor driver: executes motion plans using stepper motors
  3. Part of Grbl
  4. Copyright (c) 2009-2011 Simen Svale Skogsrud
  5. Grbl is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. Grbl is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Grbl. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. /* The timer calculations of this module informed by the 'RepRap cartesian firmware' by Zack Smith
  17. and Philipp Tiefenbacher. */
  18. #include "Marlin.h"
  19. #include "stepper.h"
  20. #include "planner.h"
  21. #include "temperature.h"
  22. #include "ultralcd.h"
  23. #include "language.h"
  24. #include "cardreader.h"
  25. #include "speed_lookuptable.h"
  26. #if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1
  27. #include <SPI.h>
  28. #endif
  29. #ifdef TMC2130
  30. #include "tmc2130.h"
  31. #endif //TMC2130
  32. #ifdef FILAMENT_SENSOR
  33. #include "fsensor.h"
  34. int fsensor_counter = 0; //counter for e-steps
  35. #endif //FILAMENT_SENSOR
  36. #include "mmu.h"
  37. #include "ConfigurationStore.h"
  38. #ifdef DEBUG_STACK_MONITOR
  39. uint16_t SP_min = 0x21FF;
  40. #endif //DEBUG_STACK_MONITOR
  41. //===========================================================================
  42. //=============================public variables ============================
  43. //===========================================================================
  44. block_t *current_block; // A pointer to the block currently being traced
  45. bool x_min_endstop = false;
  46. bool x_max_endstop = false;
  47. bool y_min_endstop = false;
  48. bool y_max_endstop = false;
  49. bool z_min_endstop = false;
  50. bool z_max_endstop = false;
  51. //===========================================================================
  52. //=============================private variables ============================
  53. //===========================================================================
  54. //static makes it inpossible to be called from outside of this file by extern.!
  55. // Variables used by The Stepper Driver Interrupt
  56. static unsigned char out_bits; // The next stepping-bits to be output
  57. static dda_isteps_t
  58. counter_x, // Counter variables for the bresenham line tracer
  59. counter_y,
  60. counter_z,
  61. counter_e;
  62. volatile dda_usteps_t step_events_completed; // The number of step events executed in the current block
  63. static int32_t acceleration_time, deceleration_time;
  64. //static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
  65. static uint16_t acc_step_rate; // needed for deccelaration start point
  66. static uint8_t step_loops;
  67. static uint16_t OCR1A_nominal;
  68. static uint8_t step_loops_nominal;
  69. volatile long endstops_trigsteps[3]={0,0,0};
  70. volatile long endstops_stepsTotal,endstops_stepsDone;
  71. static volatile bool endstop_x_hit=false;
  72. static volatile bool endstop_y_hit=false;
  73. static volatile bool endstop_z_hit=false;
  74. #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
  75. bool abort_on_endstop_hit = false;
  76. #endif
  77. #ifdef MOTOR_CURRENT_PWM_XY_PIN
  78. int motor_current_setting[3] = DEFAULT_PWM_MOTOR_CURRENT;
  79. int motor_current_setting_silent[3] = DEFAULT_PWM_MOTOR_CURRENT;
  80. int motor_current_setting_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  81. #endif
  82. #if ( (defined(X_MAX_PIN) && (X_MAX_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_XMAXLIMIT)
  83. static bool old_x_max_endstop=false;
  84. #endif
  85. #if ( (defined(Y_MAX_PIN) && (Y_MAX_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_YMAXLIMIT)
  86. static bool old_y_max_endstop=false;
  87. #endif
  88. static bool old_x_min_endstop=false;
  89. static bool old_y_min_endstop=false;
  90. static bool old_z_min_endstop=false;
  91. static bool old_z_max_endstop=false;
  92. static bool check_endstops = true;
  93. static bool check_z_endstop = false;
  94. static bool z_endstop_invert = false;
  95. volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0};
  96. volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1};
  97. #ifdef LIN_ADVANCE
  98. void advance_isr_scheduler();
  99. void advance_isr();
  100. static const uint16_t ADV_NEVER = 0xFFFF;
  101. static bool use_advance_lead;
  102. static uint16_t nextMainISR;
  103. static uint16_t nextAdvanceISR;
  104. static uint16_t main_Rate;
  105. static uint16_t eISR_Rate;
  106. static volatile uint16_t current_adv_steps;
  107. static uint16_t final_adv_steps;
  108. static uint16_t max_adv_steps;
  109. static uint32_t LA_decelerate_after;
  110. static int8_t e_steps;
  111. static uint8_t e_step_loops;
  112. static int8_t LA_phase;
  113. #define _NEXT_ISR(T) main_Rate = nextMainISR = T
  114. #else
  115. #define _NEXT_ISR(T) OCR1A = T
  116. #endif
  117. #ifdef DEBUG_STEPPER_TIMER_MISSED
  118. extern bool stepper_timer_overflow_state;
  119. extern uint16_t stepper_timer_overflow_last;
  120. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  121. //===========================================================================
  122. //=============================functions ============================
  123. //===========================================================================
  124. void checkHitEndstops()
  125. {
  126. if( endstop_x_hit || endstop_y_hit || endstop_z_hit) {
  127. SERIAL_ECHO_START;
  128. SERIAL_ECHORPGM(MSG_ENDSTOPS_HIT);
  129. if(endstop_x_hit) {
  130. SERIAL_ECHOPAIR(" X:",(float)endstops_trigsteps[X_AXIS]/cs.axis_steps_per_unit[X_AXIS]);
  131. // LCD_MESSAGERPGM(CAT2((MSG_ENDSTOPS_HIT), PSTR("X")));
  132. }
  133. if(endstop_y_hit) {
  134. SERIAL_ECHOPAIR(" Y:",(float)endstops_trigsteps[Y_AXIS]/cs.axis_steps_per_unit[Y_AXIS]);
  135. // LCD_MESSAGERPGM(CAT2((MSG_ENDSTOPS_HIT), PSTR("Y")));
  136. }
  137. if(endstop_z_hit) {
  138. SERIAL_ECHOPAIR(" Z:",(float)endstops_trigsteps[Z_AXIS]/cs.axis_steps_per_unit[Z_AXIS]);
  139. // LCD_MESSAGERPGM(CAT2((MSG_ENDSTOPS_HIT),PSTR("Z")));
  140. }
  141. SERIAL_ECHOLN("");
  142. endstop_x_hit=false;
  143. endstop_y_hit=false;
  144. endstop_z_hit=false;
  145. #if defined(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) && defined(SDSUPPORT)
  146. if (abort_on_endstop_hit)
  147. {
  148. card.sdprinting = false;
  149. card.closefile();
  150. quickStop();
  151. setTargetHotend0(0);
  152. setTargetHotend1(0);
  153. setTargetHotend2(0);
  154. }
  155. #endif
  156. }
  157. }
  158. bool endstops_hit_on_purpose()
  159. {
  160. bool hit = endstop_x_hit || endstop_y_hit || endstop_z_hit;
  161. endstop_x_hit=false;
  162. endstop_y_hit=false;
  163. endstop_z_hit=false;
  164. return hit;
  165. }
  166. bool endstop_z_hit_on_purpose()
  167. {
  168. bool hit = endstop_z_hit;
  169. endstop_z_hit=false;
  170. return hit;
  171. }
  172. bool enable_endstops(bool check)
  173. {
  174. bool old = check_endstops;
  175. check_endstops = check;
  176. return old;
  177. }
  178. bool enable_z_endstop(bool check)
  179. {
  180. bool old = check_z_endstop;
  181. check_z_endstop = check;
  182. endstop_z_hit = false;
  183. return old;
  184. }
  185. void invert_z_endstop(bool endstop_invert)
  186. {
  187. z_endstop_invert = endstop_invert;
  188. }
  189. // __________________________
  190. // /| |\ _________________ ^
  191. // / | | \ /| |\ |
  192. // / | | \ / | | \ s
  193. // / | | | | | \ p
  194. // / | | | | | \ e
  195. // +-----+------------------------+---+--+---------------+----+ e
  196. // | BLOCK 1 | BLOCK 2 | d
  197. //
  198. // time ----->
  199. //
  200. // The trapezoid is the shape the speed curve over time. It starts at block->initial_rate, accelerates
  201. // first block->accelerate_until step_events_completed, then keeps going at constant speed until
  202. // step_events_completed reaches block->decelerate_after after which it decelerates until the trapezoid generator is reset.
  203. // The slope of acceleration is calculated with the leib ramp alghorithm.
  204. // "The Stepper Driver Interrupt" - This timer interrupt is the workhorse.
  205. // It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately.
  206. ISR(TIMER1_COMPA_vect) {
  207. #ifdef DEBUG_STACK_MONITOR
  208. uint16_t sp = SPL + 256 * SPH;
  209. if (sp < SP_min) SP_min = sp;
  210. #endif //DEBUG_STACK_MONITOR
  211. #ifdef LIN_ADVANCE
  212. advance_isr_scheduler();
  213. #else
  214. isr();
  215. #endif
  216. // Don't run the ISR faster than possible
  217. // Is there a 8us time left before the next interrupt triggers?
  218. if (OCR1A < TCNT1 + 16) {
  219. #ifdef DEBUG_STEPPER_TIMER_MISSED
  220. // Verify whether the next planned timer interrupt has not been missed already.
  221. // This debugging test takes < 1.125us
  222. // This skews the profiling slightly as the fastest stepper timer
  223. // interrupt repeats at a 100us rate (10kHz).
  224. if (OCR1A + 40 < TCNT1) {
  225. // The interrupt was delayed by more than 20us (which is 1/5th of the 10kHz ISR repeat rate).
  226. // Give a warning.
  227. stepper_timer_overflow_state = true;
  228. stepper_timer_overflow_last = TCNT1 - OCR1A;
  229. // Beep, the beeper will be cleared at the stepper_timer_overflow() called from the main thread.
  230. WRITE(BEEPER, HIGH);
  231. }
  232. #endif
  233. // Fix the next interrupt to be executed after 8us from now.
  234. OCR1A = TCNT1 + 16;
  235. }
  236. }
  237. uint8_t last_dir_bits = 0;
  238. #ifdef BACKLASH_X
  239. uint8_t st_backlash_x = 0;
  240. #endif //BACKLASH_X
  241. #ifdef BACKLASH_Y
  242. uint8_t st_backlash_y = 0;
  243. #endif //BACKLASH_Y
  244. FORCE_INLINE void stepper_next_block()
  245. {
  246. // Anything in the buffer?
  247. //WRITE_NC(LOGIC_ANALYZER_CH2, true);
  248. current_block = plan_get_current_block();
  249. if (current_block != NULL) {
  250. #ifdef BACKLASH_X
  251. if (current_block->steps_x.wide)
  252. { //X-axis movement
  253. if ((current_block->direction_bits ^ last_dir_bits) & 1)
  254. {
  255. printf_P(PSTR("BL %d\n"), (current_block->direction_bits & 1)?st_backlash_x:-st_backlash_x);
  256. if (current_block->direction_bits & 1)
  257. WRITE_NC(X_DIR_PIN, INVERT_X_DIR);
  258. else
  259. WRITE_NC(X_DIR_PIN, !INVERT_X_DIR);
  260. _delay_us(100);
  261. for (uint8_t i = 0; i < st_backlash_x; i++)
  262. {
  263. WRITE_NC(X_STEP_PIN, !INVERT_X_STEP_PIN);
  264. _delay_us(100);
  265. WRITE_NC(X_STEP_PIN, INVERT_X_STEP_PIN);
  266. _delay_us(900);
  267. }
  268. }
  269. last_dir_bits &= ~1;
  270. last_dir_bits |= current_block->direction_bits & 1;
  271. }
  272. #endif
  273. #ifdef BACKLASH_Y
  274. if (current_block->steps_y.wide)
  275. { //Y-axis movement
  276. if ((current_block->direction_bits ^ last_dir_bits) & 2)
  277. {
  278. printf_P(PSTR("BL %d\n"), (current_block->direction_bits & 2)?st_backlash_y:-st_backlash_y);
  279. if (current_block->direction_bits & 2)
  280. WRITE_NC(Y_DIR_PIN, INVERT_Y_DIR);
  281. else
  282. WRITE_NC(Y_DIR_PIN, !INVERT_Y_DIR);
  283. _delay_us(100);
  284. for (uint8_t i = 0; i < st_backlash_y; i++)
  285. {
  286. WRITE_NC(Y_STEP_PIN, !INVERT_Y_STEP_PIN);
  287. _delay_us(100);
  288. WRITE_NC(Y_STEP_PIN, INVERT_Y_STEP_PIN);
  289. _delay_us(900);
  290. }
  291. }
  292. last_dir_bits &= ~2;
  293. last_dir_bits |= current_block->direction_bits & 2;
  294. }
  295. #endif
  296. #ifdef FILAMENT_SENSOR
  297. fsensor_counter = 0;
  298. fsensor_st_block_begin(current_block);
  299. #endif //FILAMENT_SENSOR
  300. // The busy flag is set by the plan_get_current_block() call.
  301. // current_block->busy = true;
  302. // Initializes the trapezoid generator from the current block. Called whenever a new
  303. // block begins.
  304. deceleration_time = 0;
  305. // Set the nominal step loops to zero to indicate, that the timer value is not known yet.
  306. // That means, delay the initialization of nominal step rate and step loops until the steady
  307. // state is reached.
  308. step_loops_nominal = 0;
  309. acc_step_rate = uint16_t(current_block->initial_rate);
  310. acceleration_time = calc_timer(acc_step_rate, step_loops);
  311. #ifdef LIN_ADVANCE
  312. if ((use_advance_lead = current_block->use_advance_lead)) {
  313. LA_decelerate_after = current_block->decelerate_after;
  314. final_adv_steps = current_block->final_adv_steps;
  315. max_adv_steps = current_block->max_adv_steps;
  316. e_step_loops = current_block->advance_step_loops;
  317. LA_phase = -1;
  318. } else {
  319. nextAdvanceISR = ADV_NEVER;
  320. eISR_Rate = ADV_NEVER;
  321. e_step_loops = 1;
  322. LA_phase = -1;
  323. current_adv_steps = 0;
  324. }
  325. #endif
  326. if (current_block->flag & BLOCK_FLAG_DDA_LOWRES) {
  327. counter_x.lo = -(current_block->step_event_count.lo >> 1);
  328. counter_y.lo = counter_x.lo;
  329. counter_z.lo = counter_x.lo;
  330. counter_e.lo = counter_x.lo;
  331. } else {
  332. counter_x.wide = -(current_block->step_event_count.wide >> 1);
  333. counter_y.wide = counter_x.wide;
  334. counter_z.wide = counter_x.wide;
  335. counter_e.wide = counter_x.wide;
  336. }
  337. step_events_completed.wide = 0;
  338. // Set directions.
  339. out_bits = current_block->direction_bits;
  340. // Set the direction bits (X_AXIS=A_AXIS and Y_AXIS=B_AXIS for COREXY)
  341. if((out_bits & (1<<X_AXIS))!=0){
  342. WRITE_NC(X_DIR_PIN, INVERT_X_DIR);
  343. count_direction[X_AXIS]=-1;
  344. } else {
  345. WRITE_NC(X_DIR_PIN, !INVERT_X_DIR);
  346. count_direction[X_AXIS]=1;
  347. }
  348. if((out_bits & (1<<Y_AXIS))!=0){
  349. WRITE_NC(Y_DIR_PIN, INVERT_Y_DIR);
  350. count_direction[Y_AXIS]=-1;
  351. } else {
  352. WRITE_NC(Y_DIR_PIN, !INVERT_Y_DIR);
  353. count_direction[Y_AXIS]=1;
  354. }
  355. if ((out_bits & (1<<Z_AXIS)) != 0) { // -direction
  356. WRITE_NC(Z_DIR_PIN,INVERT_Z_DIR);
  357. count_direction[Z_AXIS]=-1;
  358. } else { // +direction
  359. WRITE_NC(Z_DIR_PIN,!INVERT_Z_DIR);
  360. count_direction[Z_AXIS]=1;
  361. }
  362. if ((out_bits & (1 << E_AXIS)) != 0) { // -direction
  363. #ifndef LIN_ADVANCE
  364. WRITE(E0_DIR_PIN,
  365. #ifdef SNMM
  366. (mmu_extruder == 0 || mmu_extruder == 2) ? !INVERT_E0_DIR :
  367. #endif // SNMM
  368. INVERT_E0_DIR);
  369. #endif /* LIN_ADVANCE */
  370. count_direction[E_AXIS] = -1;
  371. } else { // +direction
  372. #ifndef LIN_ADVANCE
  373. WRITE(E0_DIR_PIN,
  374. #ifdef SNMM
  375. (mmu_extruder == 0 || mmu_extruder == 2) ? INVERT_E0_DIR :
  376. #endif // SNMM
  377. !INVERT_E0_DIR);
  378. #endif /* LIN_ADVANCE */
  379. count_direction[E_AXIS] = 1;
  380. }
  381. }
  382. else {
  383. _NEXT_ISR(2000); // 1kHz.
  384. }
  385. //WRITE_NC(LOGIC_ANALYZER_CH2, false);
  386. }
  387. // Check limit switches.
  388. FORCE_INLINE void stepper_check_endstops()
  389. {
  390. if(check_endstops)
  391. {
  392. #ifndef COREXY
  393. if ((out_bits & (1<<X_AXIS)) != 0) // stepping along -X axis
  394. #else
  395. if ((((out_bits & (1<<X_AXIS)) != 0)&&(out_bits & (1<<Y_AXIS)) != 0)) //-X occurs for -A and -B
  396. #endif
  397. {
  398. #if ( (defined(X_MIN_PIN) && (X_MIN_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_XMINLIMIT)
  399. #ifdef TMC2130_SG_HOMING
  400. // Stall guard homing turned on
  401. x_min_endstop = (READ(X_TMC2130_DIAG) != 0);
  402. #else
  403. // Normal homing
  404. x_min_endstop = (READ(X_MIN_PIN) != X_MIN_ENDSTOP_INVERTING);
  405. #endif
  406. if(x_min_endstop && old_x_min_endstop && (current_block->steps_x.wide > 0)) {
  407. endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
  408. endstop_x_hit=true;
  409. step_events_completed.wide = current_block->step_event_count.wide;
  410. }
  411. old_x_min_endstop = x_min_endstop;
  412. #endif
  413. } else { // +direction
  414. #if ( (defined(X_MAX_PIN) && (X_MAX_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_XMAXLIMIT)
  415. #ifdef TMC2130_SG_HOMING
  416. // Stall guard homing turned on
  417. x_max_endstop = (READ(X_TMC2130_DIAG) != 0);
  418. #else
  419. // Normal homing
  420. x_max_endstop = (READ(X_MAX_PIN) != X_MAX_ENDSTOP_INVERTING);
  421. #endif
  422. if(x_max_endstop && old_x_max_endstop && (current_block->steps_x.wide > 0)){
  423. endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
  424. endstop_x_hit=true;
  425. step_events_completed.wide = current_block->step_event_count.wide;
  426. }
  427. old_x_max_endstop = x_max_endstop;
  428. #endif
  429. }
  430. #ifndef COREXY
  431. if ((out_bits & (1<<Y_AXIS)) != 0) // -direction
  432. #else
  433. if ((((out_bits & (1<<X_AXIS)) != 0)&&(out_bits & (1<<Y_AXIS)) == 0)) // -Y occurs for -A and +B
  434. #endif
  435. {
  436. #if ( (defined(Y_MIN_PIN) && (Y_MIN_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_YMINLIMIT)
  437. #ifdef TMC2130_SG_HOMING
  438. // Stall guard homing turned on
  439. y_min_endstop = (READ(Y_TMC2130_DIAG) != 0);
  440. #else
  441. // Normal homing
  442. y_min_endstop = (READ(Y_MIN_PIN) != Y_MIN_ENDSTOP_INVERTING);
  443. #endif
  444. if(y_min_endstop && old_y_min_endstop && (current_block->steps_y.wide > 0)) {
  445. endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
  446. endstop_y_hit=true;
  447. step_events_completed.wide = current_block->step_event_count.wide;
  448. }
  449. old_y_min_endstop = y_min_endstop;
  450. #endif
  451. } else { // +direction
  452. #if ( (defined(Y_MAX_PIN) && (Y_MAX_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_YMAXLIMIT)
  453. #ifdef TMC2130_SG_HOMING
  454. // Stall guard homing turned on
  455. y_max_endstop = (READ(Y_TMC2130_DIAG) != 0);
  456. #else
  457. // Normal homing
  458. y_max_endstop = (READ(Y_MAX_PIN) != Y_MAX_ENDSTOP_INVERTING);
  459. #endif
  460. if(y_max_endstop && old_y_max_endstop && (current_block->steps_y.wide > 0)){
  461. endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
  462. endstop_y_hit=true;
  463. step_events_completed.wide = current_block->step_event_count.wide;
  464. }
  465. old_y_max_endstop = y_max_endstop;
  466. #endif
  467. }
  468. if ((out_bits & (1<<Z_AXIS)) != 0) // -direction
  469. {
  470. #if defined(Z_MIN_PIN) && (Z_MIN_PIN > -1) && !defined(DEBUG_DISABLE_ZMINLIMIT)
  471. if (! check_z_endstop) {
  472. #ifdef TMC2130_SG_HOMING
  473. // Stall guard homing turned on
  474. #ifdef TMC2130_STEALTH_Z
  475. if ((tmc2130_mode == TMC2130_MODE_SILENT) && !(tmc2130_sg_homing_axes_mask & 0x04))
  476. z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING);
  477. else
  478. #endif //TMC2130_STEALTH_Z
  479. z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING) || (READ(Z_TMC2130_DIAG) != 0);
  480. #else
  481. z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING);
  482. #endif //TMC2130_SG_HOMING
  483. if(z_min_endstop && old_z_min_endstop && (current_block->steps_z.wide > 0)) {
  484. endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
  485. endstop_z_hit=true;
  486. step_events_completed.wide = current_block->step_event_count.wide;
  487. }
  488. old_z_min_endstop = z_min_endstop;
  489. }
  490. #endif
  491. } else { // +direction
  492. #if defined(Z_MAX_PIN) && (Z_MAX_PIN > -1) && !defined(DEBUG_DISABLE_ZMAXLIMIT)
  493. #ifdef TMC2130_SG_HOMING
  494. // Stall guard homing turned on
  495. #ifdef TMC2130_STEALTH_Z
  496. if ((tmc2130_mode == TMC2130_MODE_SILENT) && !(tmc2130_sg_homing_axes_mask & 0x04))
  497. z_max_endstop = false;
  498. else
  499. #endif //TMC2130_STEALTH_Z
  500. z_max_endstop = (READ(Z_TMC2130_DIAG) != 0);
  501. #else
  502. z_max_endstop = (READ(Z_MAX_PIN) != Z_MAX_ENDSTOP_INVERTING);
  503. #endif //TMC2130_SG_HOMING
  504. if(z_max_endstop && old_z_max_endstop && (current_block->steps_z.wide > 0)) {
  505. endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
  506. endstop_z_hit=true;
  507. step_events_completed.wide = current_block->step_event_count.wide;
  508. }
  509. old_z_max_endstop = z_max_endstop;
  510. #endif
  511. }
  512. }
  513. // Supporting stopping on a trigger of the Z-stop induction sensor, not only for the Z-minus movements.
  514. #if defined(Z_MIN_PIN) && (Z_MIN_PIN > -1) && !defined(DEBUG_DISABLE_ZMINLIMIT)
  515. if (check_z_endstop) {
  516. // Check the Z min end-stop no matter what.
  517. // Good for searching for the center of an induction target.
  518. #ifdef TMC2130_SG_HOMING
  519. // Stall guard homing turned on
  520. #ifdef TMC2130_STEALTH_Z
  521. if ((tmc2130_mode == TMC2130_MODE_SILENT) && !(tmc2130_sg_homing_axes_mask & 0x04))
  522. z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING);
  523. else
  524. #endif //TMC2130_STEALTH_Z
  525. z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING) || (READ(Z_TMC2130_DIAG) != 0);
  526. #else
  527. z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING);
  528. #endif //TMC2130_SG_HOMING
  529. if(z_min_endstop && old_z_min_endstop) {
  530. endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
  531. endstop_z_hit=true;
  532. step_events_completed.wide = current_block->step_event_count.wide;
  533. }
  534. old_z_min_endstop = z_min_endstop;
  535. }
  536. #endif
  537. }
  538. FORCE_INLINE void stepper_tick_lowres()
  539. {
  540. for (uint8_t i=0; i < step_loops; ++ i) { // Take multiple steps per interrupt (For high speed moves)
  541. MSerial.checkRx(); // Check for serial chars.
  542. // Step in X axis
  543. counter_x.lo += current_block->steps_x.lo;
  544. if (counter_x.lo > 0) {
  545. WRITE_NC(X_STEP_PIN, !INVERT_X_STEP_PIN);
  546. #ifdef DEBUG_XSTEP_DUP_PIN
  547. WRITE_NC(DEBUG_XSTEP_DUP_PIN,!INVERT_X_STEP_PIN);
  548. #endif //DEBUG_XSTEP_DUP_PIN
  549. counter_x.lo -= current_block->step_event_count.lo;
  550. count_position[X_AXIS]+=count_direction[X_AXIS];
  551. WRITE_NC(X_STEP_PIN, INVERT_X_STEP_PIN);
  552. #ifdef DEBUG_XSTEP_DUP_PIN
  553. WRITE_NC(DEBUG_XSTEP_DUP_PIN,INVERT_X_STEP_PIN);
  554. #endif //DEBUG_XSTEP_DUP_PIN
  555. }
  556. // Step in Y axis
  557. counter_y.lo += current_block->steps_y.lo;
  558. if (counter_y.lo > 0) {
  559. WRITE_NC(Y_STEP_PIN, !INVERT_Y_STEP_PIN);
  560. #ifdef DEBUG_YSTEP_DUP_PIN
  561. WRITE_NC(DEBUG_YSTEP_DUP_PIN,!INVERT_Y_STEP_PIN);
  562. #endif //DEBUG_YSTEP_DUP_PIN
  563. counter_y.lo -= current_block->step_event_count.lo;
  564. count_position[Y_AXIS]+=count_direction[Y_AXIS];
  565. WRITE_NC(Y_STEP_PIN, INVERT_Y_STEP_PIN);
  566. #ifdef DEBUG_YSTEP_DUP_PIN
  567. WRITE_NC(DEBUG_YSTEP_DUP_PIN,INVERT_Y_STEP_PIN);
  568. #endif //DEBUG_YSTEP_DUP_PIN
  569. }
  570. // Step in Z axis
  571. counter_z.lo += current_block->steps_z.lo;
  572. if (counter_z.lo > 0) {
  573. WRITE_NC(Z_STEP_PIN, !INVERT_Z_STEP_PIN);
  574. counter_z.lo -= current_block->step_event_count.lo;
  575. count_position[Z_AXIS]+=count_direction[Z_AXIS];
  576. WRITE_NC(Z_STEP_PIN, INVERT_Z_STEP_PIN);
  577. }
  578. // Step in E axis
  579. counter_e.lo += current_block->steps_e.lo;
  580. if (counter_e.lo > 0) {
  581. #ifndef LIN_ADVANCE
  582. WRITE(E0_STEP_PIN, !INVERT_E_STEP_PIN);
  583. #endif /* LIN_ADVANCE */
  584. counter_e.lo -= current_block->step_event_count.lo;
  585. count_position[E_AXIS] += count_direction[E_AXIS];
  586. #ifdef LIN_ADVANCE
  587. e_steps += count_direction[E_AXIS];
  588. #else
  589. #ifdef FILAMENT_SENSOR
  590. ++ fsensor_counter;
  591. #endif //FILAMENT_SENSOR
  592. WRITE(E0_STEP_PIN, INVERT_E_STEP_PIN);
  593. #endif
  594. }
  595. if(++ step_events_completed.lo >= current_block->step_event_count.lo)
  596. break;
  597. }
  598. }
  599. FORCE_INLINE void stepper_tick_highres()
  600. {
  601. for (uint8_t i=0; i < step_loops; ++ i) { // Take multiple steps per interrupt (For high speed moves)
  602. MSerial.checkRx(); // Check for serial chars.
  603. // Step in X axis
  604. counter_x.wide += current_block->steps_x.wide;
  605. if (counter_x.wide > 0) {
  606. WRITE_NC(X_STEP_PIN, !INVERT_X_STEP_PIN);
  607. #ifdef DEBUG_XSTEP_DUP_PIN
  608. WRITE_NC(DEBUG_XSTEP_DUP_PIN,!INVERT_X_STEP_PIN);
  609. #endif //DEBUG_XSTEP_DUP_PIN
  610. counter_x.wide -= current_block->step_event_count.wide;
  611. count_position[X_AXIS]+=count_direction[X_AXIS];
  612. WRITE_NC(X_STEP_PIN, INVERT_X_STEP_PIN);
  613. #ifdef DEBUG_XSTEP_DUP_PIN
  614. WRITE_NC(DEBUG_XSTEP_DUP_PIN,INVERT_X_STEP_PIN);
  615. #endif //DEBUG_XSTEP_DUP_PIN
  616. }
  617. // Step in Y axis
  618. counter_y.wide += current_block->steps_y.wide;
  619. if (counter_y.wide > 0) {
  620. WRITE_NC(Y_STEP_PIN, !INVERT_Y_STEP_PIN);
  621. #ifdef DEBUG_YSTEP_DUP_PIN
  622. WRITE_NC(DEBUG_YSTEP_DUP_PIN,!INVERT_Y_STEP_PIN);
  623. #endif //DEBUG_YSTEP_DUP_PIN
  624. counter_y.wide -= current_block->step_event_count.wide;
  625. count_position[Y_AXIS]+=count_direction[Y_AXIS];
  626. WRITE_NC(Y_STEP_PIN, INVERT_Y_STEP_PIN);
  627. #ifdef DEBUG_YSTEP_DUP_PIN
  628. WRITE_NC(DEBUG_YSTEP_DUP_PIN,INVERT_Y_STEP_PIN);
  629. #endif //DEBUG_YSTEP_DUP_PIN
  630. }
  631. // Step in Z axis
  632. counter_z.wide += current_block->steps_z.wide;
  633. if (counter_z.wide > 0) {
  634. WRITE_NC(Z_STEP_PIN, !INVERT_Z_STEP_PIN);
  635. counter_z.wide -= current_block->step_event_count.wide;
  636. count_position[Z_AXIS]+=count_direction[Z_AXIS];
  637. WRITE_NC(Z_STEP_PIN, INVERT_Z_STEP_PIN);
  638. }
  639. // Step in E axis
  640. counter_e.wide += current_block->steps_e.wide;
  641. if (counter_e.wide > 0) {
  642. #ifndef LIN_ADVANCE
  643. WRITE(E0_STEP_PIN, !INVERT_E_STEP_PIN);
  644. #endif /* LIN_ADVANCE */
  645. counter_e.wide -= current_block->step_event_count.wide;
  646. count_position[E_AXIS]+=count_direction[E_AXIS];
  647. #ifdef LIN_ADVANCE
  648. e_steps += count_direction[E_AXIS];
  649. #else
  650. #ifdef FILAMENT_SENSOR
  651. ++ fsensor_counter;
  652. #endif //FILAMENT_SENSOR
  653. WRITE(E0_STEP_PIN, INVERT_E_STEP_PIN);
  654. #endif
  655. }
  656. if(++ step_events_completed.wide >= current_block->step_event_count.wide)
  657. break;
  658. }
  659. }
  660. FORCE_INLINE void isr() {
  661. //WRITE_NC(LOGIC_ANALYZER_CH0, true);
  662. //if (UVLO) uvlo();
  663. // If there is no current block, attempt to pop one from the buffer
  664. if (current_block == NULL)
  665. stepper_next_block();
  666. if (current_block != NULL)
  667. {
  668. stepper_check_endstops();
  669. if (current_block->flag & BLOCK_FLAG_DDA_LOWRES)
  670. stepper_tick_lowres();
  671. else
  672. stepper_tick_highres();
  673. // Calculare new timer value
  674. // 13.38-14.63us for steady state,
  675. // 25.12us for acceleration / deceleration.
  676. {
  677. //WRITE_NC(LOGIC_ANALYZER_CH1, true);
  678. if (step_events_completed.wide <= (unsigned long int)current_block->accelerate_until) {
  679. // v = t * a -> acc_step_rate = acceleration_time * current_block->acceleration_rate
  680. MultiU24X24toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
  681. acc_step_rate += uint16_t(current_block->initial_rate);
  682. // upper limit
  683. if(acc_step_rate > uint16_t(current_block->nominal_rate))
  684. acc_step_rate = current_block->nominal_rate;
  685. // step_rate to timer interval
  686. uint16_t timer = calc_timer(acc_step_rate, step_loops);
  687. _NEXT_ISR(timer);
  688. acceleration_time += timer;
  689. #ifdef LIN_ADVANCE
  690. if (current_block->use_advance_lead) {
  691. if (step_events_completed.wide <= (unsigned long int)step_loops) {
  692. // First acceleration loop
  693. eISR_Rate = current_block->advance_rate;
  694. nextAdvanceISR = 0;
  695. }
  696. }
  697. #endif
  698. }
  699. else if (step_events_completed.wide > (unsigned long int)current_block->decelerate_after) {
  700. uint16_t step_rate;
  701. MultiU24X24toH16(step_rate, deceleration_time, current_block->acceleration_rate);
  702. step_rate = acc_step_rate - step_rate; // Decelerate from aceleration end point.
  703. if ((step_rate & 0x8000) || step_rate < uint16_t(current_block->final_rate)) {
  704. // Result is negative or too small.
  705. step_rate = uint16_t(current_block->final_rate);
  706. }
  707. // Step_rate to timer interval.
  708. uint16_t timer = calc_timer(step_rate, step_loops);
  709. _NEXT_ISR(timer);
  710. deceleration_time += timer;
  711. #ifdef LIN_ADVANCE
  712. if (current_block->use_advance_lead) {
  713. if (step_events_completed.wide <= (unsigned long int)current_block->decelerate_after + step_loops) {
  714. // First deceleration loop
  715. eISR_Rate = current_block->advance_rate;
  716. nextAdvanceISR = 0;
  717. }
  718. }
  719. #endif
  720. }
  721. else {
  722. if (! step_loops_nominal) {
  723. // Calculation of the steady state timer rate has been delayed to the 1st tick of the steady state to lower
  724. // the initial interrupt blocking.
  725. OCR1A_nominal = calc_timer(uint16_t(current_block->nominal_rate), step_loops);
  726. step_loops_nominal = step_loops;
  727. }
  728. _NEXT_ISR(OCR1A_nominal);
  729. }
  730. //WRITE_NC(LOGIC_ANALYZER_CH1, false);
  731. }
  732. // If current block is finished, reset pointer
  733. if (step_events_completed.wide >= current_block->step_event_count.wide) {
  734. #ifdef FILAMENT_SENSOR
  735. fsensor_st_block_chunk(current_block, fsensor_counter);
  736. fsensor_counter = 0;
  737. #endif //FILAMENT_SENSOR
  738. current_block = NULL;
  739. plan_discard_current_block();
  740. }
  741. #ifdef FILAMENT_SENSOR
  742. else if ((fsensor_counter >= fsensor_chunk_len))
  743. {
  744. fsensor_st_block_chunk(current_block, fsensor_counter);
  745. fsensor_counter = 0;
  746. }
  747. #endif //FILAMENT_SENSOR
  748. }
  749. #ifdef TMC2130
  750. tmc2130_st_isr();
  751. #endif //TMC2130
  752. //WRITE_NC(LOGIC_ANALYZER_CH0, false);
  753. }
  754. #ifdef LIN_ADVANCE
  755. // Timer interrupt for E. e_steps is set in the main routine.
  756. FORCE_INLINE void advance_isr() {
  757. if (step_events_completed.wide > LA_decelerate_after && current_adv_steps > final_adv_steps) {
  758. // decompression
  759. e_steps -= e_step_loops;
  760. current_adv_steps -= e_step_loops;
  761. nextAdvanceISR = eISR_Rate;
  762. if(nextAdvanceISR == ADV_NEVER)
  763. {
  764. LA_phase = 1;
  765. e_step_loops = 1;
  766. }
  767. else
  768. {
  769. if (step_loops == e_step_loops)
  770. LA_phase = (eISR_Rate > main_Rate);
  771. else
  772. {
  773. // avoid overflow through division (TODO: this can be
  774. // improved as both step_loops and e_step_loops are
  775. // guaranteed to be powers of two)
  776. LA_phase = (eISR_Rate / step_loops > main_Rate / e_step_loops);
  777. }
  778. }
  779. }
  780. else if (step_events_completed.wide < LA_decelerate_after && current_adv_steps < max_adv_steps) {
  781. // compression
  782. e_steps += e_step_loops;
  783. current_adv_steps += e_step_loops;
  784. nextAdvanceISR = eISR_Rate;
  785. LA_phase = -1;
  786. if(nextAdvanceISR == ADV_NEVER)
  787. e_step_loops = 1;
  788. }
  789. else {
  790. // advance steps completed
  791. nextAdvanceISR = ADV_NEVER;
  792. eISR_Rate = ADV_NEVER;
  793. LA_phase = -1;
  794. e_step_loops = 1;
  795. }
  796. }
  797. #define LA_FREQ_MDIV 8 // divider for the advance frequency for maximum
  798. // time allotted to merge regular and advance
  799. // ticks (stick to a power-of-two)
  800. FORCE_INLINE void advance_isr_scheduler() {
  801. // Integrate the final timer value, accounting for scheduling adjustments
  802. if(nextAdvanceISR && nextAdvanceISR != ADV_NEVER)
  803. {
  804. if(nextAdvanceISR > OCR1A)
  805. nextAdvanceISR -= OCR1A;
  806. else
  807. nextAdvanceISR = 0;
  808. }
  809. if(nextMainISR > OCR1A)
  810. nextMainISR -= OCR1A;
  811. else
  812. nextMainISR = 0;
  813. // Run main stepping ISR if flagged
  814. if (!nextMainISR)
  815. {
  816. #ifdef LA_DEBUG_LOGIC
  817. WRITE_NC(LOGIC_ANALYZER_CH0, true);
  818. #endif
  819. isr();
  820. #ifdef LA_DEBUG_LOGIC
  821. WRITE_NC(LOGIC_ANALYZER_CH0, false);
  822. #endif
  823. }
  824. // Run the next advance isr if triggered now or soon enough
  825. bool eisr = nextAdvanceISR < (TCNT1 + eISR_Rate / LA_FREQ_MDIV);
  826. if (eisr)
  827. {
  828. #ifdef LA_DEBUG_LOGIC
  829. WRITE_NC(LOGIC_ANALYZER_CH1, true);
  830. #endif
  831. advance_isr();
  832. #ifdef LA_DEBUG_LOGIC
  833. WRITE_NC(LOGIC_ANALYZER_CH1, false);
  834. #endif
  835. }
  836. // Tick E steps if any
  837. if (e_steps && (LA_phase < 0 || LA_phase == eisr)) {
  838. uint8_t max_ticks = max(e_step_loops, step_loops);
  839. max_ticks = min(abs(e_steps), max_ticks);
  840. #ifdef FILAMENT_SENSOR
  841. fsensor_counter += max_ticks;
  842. #endif
  843. WRITE(E0_DIR_PIN, e_steps < 0? INVERT_E0_DIR: !INVERT_E0_DIR);
  844. while(max_ticks--)
  845. {
  846. WRITE_NC(E0_STEP_PIN, !INVERT_E_STEP_PIN);
  847. e_steps += (e_steps < 0)? 1: -1;
  848. WRITE_NC(E0_STEP_PIN, INVERT_E_STEP_PIN);
  849. }
  850. }
  851. // Schedule the next closest tick, ignoring advance if scheduled too
  852. // soon in order to avoid skewing the regular stepper acceleration
  853. if (nextAdvanceISR != ADV_NEVER && (nextAdvanceISR + TCNT1 + eISR_Rate / LA_FREQ_MDIV) < nextMainISR)
  854. OCR1A = nextAdvanceISR;
  855. else
  856. OCR1A = nextMainISR;
  857. }
  858. void clear_current_adv_vars() {
  859. current_adv_steps = 0;
  860. }
  861. #endif // LIN_ADVANCE
  862. void st_init()
  863. {
  864. #ifdef TMC2130
  865. tmc2130_init();
  866. #endif //TMC2130
  867. st_current_init(); //Initialize Digipot Motor Current
  868. microstep_init(); //Initialize Microstepping Pins
  869. //Initialize Dir Pins
  870. #if defined(X_DIR_PIN) && X_DIR_PIN > -1
  871. SET_OUTPUT(X_DIR_PIN);
  872. #endif
  873. #if defined(X2_DIR_PIN) && X2_DIR_PIN > -1
  874. SET_OUTPUT(X2_DIR_PIN);
  875. #endif
  876. #if defined(Y_DIR_PIN) && Y_DIR_PIN > -1
  877. SET_OUTPUT(Y_DIR_PIN);
  878. #if defined(Y_DUAL_STEPPER_DRIVERS) && defined(Y2_DIR_PIN) && (Y2_DIR_PIN > -1)
  879. SET_OUTPUT(Y2_DIR_PIN);
  880. #endif
  881. #endif
  882. #if defined(Z_DIR_PIN) && Z_DIR_PIN > -1
  883. SET_OUTPUT(Z_DIR_PIN);
  884. #if defined(Z_DUAL_STEPPER_DRIVERS) && defined(Z2_DIR_PIN) && (Z2_DIR_PIN > -1)
  885. SET_OUTPUT(Z2_DIR_PIN);
  886. #endif
  887. #endif
  888. #if defined(E0_DIR_PIN) && E0_DIR_PIN > -1
  889. SET_OUTPUT(E0_DIR_PIN);
  890. #endif
  891. #if defined(E1_DIR_PIN) && (E1_DIR_PIN > -1)
  892. SET_OUTPUT(E1_DIR_PIN);
  893. #endif
  894. #if defined(E2_DIR_PIN) && (E2_DIR_PIN > -1)
  895. SET_OUTPUT(E2_DIR_PIN);
  896. #endif
  897. //Initialize Enable Pins - steppers default to disabled.
  898. #if defined(X_ENABLE_PIN) && X_ENABLE_PIN > -1
  899. SET_OUTPUT(X_ENABLE_PIN);
  900. if(!X_ENABLE_ON) WRITE(X_ENABLE_PIN,HIGH);
  901. #endif
  902. #if defined(X2_ENABLE_PIN) && X2_ENABLE_PIN > -1
  903. SET_OUTPUT(X2_ENABLE_PIN);
  904. if(!X_ENABLE_ON) WRITE(X2_ENABLE_PIN,HIGH);
  905. #endif
  906. #if defined(Y_ENABLE_PIN) && Y_ENABLE_PIN > -1
  907. SET_OUTPUT(Y_ENABLE_PIN);
  908. if(!Y_ENABLE_ON) WRITE(Y_ENABLE_PIN,HIGH);
  909. #if defined(Y_DUAL_STEPPER_DRIVERS) && defined(Y2_ENABLE_PIN) && (Y2_ENABLE_PIN > -1)
  910. SET_OUTPUT(Y2_ENABLE_PIN);
  911. if(!Y_ENABLE_ON) WRITE(Y2_ENABLE_PIN,HIGH);
  912. #endif
  913. #endif
  914. #if defined(Z_ENABLE_PIN) && Z_ENABLE_PIN > -1
  915. SET_OUTPUT(Z_ENABLE_PIN);
  916. if(!Z_ENABLE_ON) WRITE(Z_ENABLE_PIN,HIGH);
  917. #if defined(Z_DUAL_STEPPER_DRIVERS) && defined(Z2_ENABLE_PIN) && (Z2_ENABLE_PIN > -1)
  918. SET_OUTPUT(Z2_ENABLE_PIN);
  919. if(!Z_ENABLE_ON) WRITE(Z2_ENABLE_PIN,HIGH);
  920. #endif
  921. #endif
  922. #if defined(E0_ENABLE_PIN) && (E0_ENABLE_PIN > -1)
  923. SET_OUTPUT(E0_ENABLE_PIN);
  924. if(!E_ENABLE_ON) WRITE(E0_ENABLE_PIN,HIGH);
  925. #endif
  926. #if defined(E1_ENABLE_PIN) && (E1_ENABLE_PIN > -1)
  927. SET_OUTPUT(E1_ENABLE_PIN);
  928. if(!E_ENABLE_ON) WRITE(E1_ENABLE_PIN,HIGH);
  929. #endif
  930. #if defined(E2_ENABLE_PIN) && (E2_ENABLE_PIN > -1)
  931. SET_OUTPUT(E2_ENABLE_PIN);
  932. if(!E_ENABLE_ON) WRITE(E2_ENABLE_PIN,HIGH);
  933. #endif
  934. //endstops and pullups
  935. #ifdef TMC2130_SG_HOMING
  936. SET_INPUT(X_TMC2130_DIAG);
  937. WRITE(X_TMC2130_DIAG,HIGH);
  938. SET_INPUT(Y_TMC2130_DIAG);
  939. WRITE(Y_TMC2130_DIAG,HIGH);
  940. SET_INPUT(Z_TMC2130_DIAG);
  941. WRITE(Z_TMC2130_DIAG,HIGH);
  942. SET_INPUT(E0_TMC2130_DIAG);
  943. WRITE(E0_TMC2130_DIAG,HIGH);
  944. #endif
  945. #if defined(X_MIN_PIN) && X_MIN_PIN > -1
  946. SET_INPUT(X_MIN_PIN);
  947. #ifdef ENDSTOPPULLUP_XMIN
  948. WRITE(X_MIN_PIN,HIGH);
  949. #endif
  950. #endif
  951. #if defined(Y_MIN_PIN) && Y_MIN_PIN > -1
  952. SET_INPUT(Y_MIN_PIN);
  953. #ifdef ENDSTOPPULLUP_YMIN
  954. WRITE(Y_MIN_PIN,HIGH);
  955. #endif
  956. #endif
  957. #if defined(Z_MIN_PIN) && Z_MIN_PIN > -1
  958. SET_INPUT(Z_MIN_PIN);
  959. #ifdef ENDSTOPPULLUP_ZMIN
  960. WRITE(Z_MIN_PIN,HIGH);
  961. #endif
  962. #endif
  963. #if defined(X_MAX_PIN) && X_MAX_PIN > -1
  964. SET_INPUT(X_MAX_PIN);
  965. #ifdef ENDSTOPPULLUP_XMAX
  966. WRITE(X_MAX_PIN,HIGH);
  967. #endif
  968. #endif
  969. #if defined(Y_MAX_PIN) && Y_MAX_PIN > -1
  970. SET_INPUT(Y_MAX_PIN);
  971. #ifdef ENDSTOPPULLUP_YMAX
  972. WRITE(Y_MAX_PIN,HIGH);
  973. #endif
  974. #endif
  975. #if defined(Z_MAX_PIN) && Z_MAX_PIN > -1
  976. SET_INPUT(Z_MAX_PIN);
  977. #ifdef ENDSTOPPULLUP_ZMAX
  978. WRITE(Z_MAX_PIN,HIGH);
  979. #endif
  980. #endif
  981. #if (defined(FANCHECK) && defined(TACH_0) && (TACH_0 > -1))
  982. SET_INPUT(TACH_0);
  983. #ifdef TACH0PULLUP
  984. WRITE(TACH_0, HIGH);
  985. #endif
  986. #endif
  987. //Initialize Step Pins
  988. #if defined(X_STEP_PIN) && (X_STEP_PIN > -1)
  989. SET_OUTPUT(X_STEP_PIN);
  990. WRITE(X_STEP_PIN,INVERT_X_STEP_PIN);
  991. #ifdef DEBUG_XSTEP_DUP_PIN
  992. SET_OUTPUT(DEBUG_XSTEP_DUP_PIN);
  993. WRITE(DEBUG_XSTEP_DUP_PIN,INVERT_X_STEP_PIN);
  994. #endif //DEBUG_XSTEP_DUP_PIN
  995. disable_x();
  996. #endif
  997. #if defined(X2_STEP_PIN) && (X2_STEP_PIN > -1)
  998. SET_OUTPUT(X2_STEP_PIN);
  999. WRITE(X2_STEP_PIN,INVERT_X_STEP_PIN);
  1000. disable_x();
  1001. #endif
  1002. #if defined(Y_STEP_PIN) && (Y_STEP_PIN > -1)
  1003. SET_OUTPUT(Y_STEP_PIN);
  1004. WRITE(Y_STEP_PIN,INVERT_Y_STEP_PIN);
  1005. #ifdef DEBUG_YSTEP_DUP_PIN
  1006. SET_OUTPUT(DEBUG_YSTEP_DUP_PIN);
  1007. WRITE(DEBUG_YSTEP_DUP_PIN,INVERT_Y_STEP_PIN);
  1008. #endif //DEBUG_YSTEP_DUP_PIN
  1009. #if defined(Y_DUAL_STEPPER_DRIVERS) && defined(Y2_STEP_PIN) && (Y2_STEP_PIN > -1)
  1010. SET_OUTPUT(Y2_STEP_PIN);
  1011. WRITE(Y2_STEP_PIN,INVERT_Y_STEP_PIN);
  1012. #endif
  1013. disable_y();
  1014. #endif
  1015. #if defined(Z_STEP_PIN) && (Z_STEP_PIN > -1)
  1016. SET_OUTPUT(Z_STEP_PIN);
  1017. WRITE(Z_STEP_PIN,INVERT_Z_STEP_PIN);
  1018. #if defined(Z_DUAL_STEPPER_DRIVERS) && defined(Z2_STEP_PIN) && (Z2_STEP_PIN > -1)
  1019. SET_OUTPUT(Z2_STEP_PIN);
  1020. WRITE(Z2_STEP_PIN,INVERT_Z_STEP_PIN);
  1021. #endif
  1022. disable_z();
  1023. #endif
  1024. #if defined(E0_STEP_PIN) && (E0_STEP_PIN > -1)
  1025. SET_OUTPUT(E0_STEP_PIN);
  1026. WRITE(E0_STEP_PIN,INVERT_E_STEP_PIN);
  1027. disable_e0();
  1028. #endif
  1029. #if defined(E1_STEP_PIN) && (E1_STEP_PIN > -1)
  1030. SET_OUTPUT(E1_STEP_PIN);
  1031. WRITE(E1_STEP_PIN,INVERT_E_STEP_PIN);
  1032. disable_e1();
  1033. #endif
  1034. #if defined(E2_STEP_PIN) && (E2_STEP_PIN > -1)
  1035. SET_OUTPUT(E2_STEP_PIN);
  1036. WRITE(E2_STEP_PIN,INVERT_E_STEP_PIN);
  1037. disable_e2();
  1038. #endif
  1039. // waveform generation = 0100 = CTC
  1040. TCCR1B &= ~(1<<WGM13);
  1041. TCCR1B |= (1<<WGM12);
  1042. TCCR1A &= ~(1<<WGM11);
  1043. TCCR1A &= ~(1<<WGM10);
  1044. // output mode = 00 (disconnected)
  1045. TCCR1A &= ~(3<<COM1A0);
  1046. TCCR1A &= ~(3<<COM1B0);
  1047. // Set the timer pre-scaler
  1048. // Generally we use a divider of 8, resulting in a 2MHz timer
  1049. // frequency on a 16MHz MCU. If you are going to change this, be
  1050. // sure to regenerate speed_lookuptable.h with
  1051. // create_speed_lookuptable.py
  1052. TCCR1B = (TCCR1B & ~(0x07<<CS10)) | (2<<CS10);
  1053. // Plan the first interrupt after 8ms from now.
  1054. OCR1A = 0x4000;
  1055. TCNT1 = 0;
  1056. #ifdef LIN_ADVANCE
  1057. #ifdef LA_DEBUG_LOGIC
  1058. LOGIC_ANALYZER_CH0_ENABLE;
  1059. LOGIC_ANALYZER_CH1_ENABLE;
  1060. WRITE_NC(LOGIC_ANALYZER_CH0, false);
  1061. WRITE_NC(LOGIC_ANALYZER_CH1, false);
  1062. #endif
  1063. // Initialize state for the linear advance scheduler
  1064. use_advance_lead = false;
  1065. nextMainISR = 0;
  1066. nextAdvanceISR = ADV_NEVER;
  1067. main_Rate = ADV_NEVER;
  1068. eISR_Rate = ADV_NEVER;
  1069. e_steps = 0;
  1070. e_step_loops = 1;
  1071. LA_phase = -1;
  1072. current_adv_steps = 0;
  1073. #endif
  1074. enable_endstops(true); // Start with endstops active. After homing they can be disabled
  1075. ENABLE_STEPPER_DRIVER_INTERRUPT();
  1076. sei();
  1077. }
  1078. void st_reset_timer()
  1079. {
  1080. // Clear a possible pending interrupt on OCR1A overflow.
  1081. TIFR1 |= 1 << OCF1A;
  1082. // Reset the counter.
  1083. TCNT1 = 0;
  1084. // Wake up after 1ms from now.
  1085. OCR1A = 2000;
  1086. #ifdef LIN_ADVANCE
  1087. nextMainISR = 0;
  1088. if(nextAdvanceISR && nextAdvanceISR != ADV_NEVER)
  1089. nextAdvanceISR = 0;
  1090. #endif
  1091. }
  1092. // Block until all buffered steps are executed
  1093. void st_synchronize()
  1094. {
  1095. while(blocks_queued())
  1096. {
  1097. #ifdef TMC2130
  1098. manage_heater();
  1099. // Vojtech: Don't disable motors inside the planner!
  1100. if (!tmc2130_update_sg())
  1101. {
  1102. manage_inactivity(true);
  1103. lcd_update(0);
  1104. }
  1105. #else //TMC2130
  1106. manage_heater();
  1107. // Vojtech: Don't disable motors inside the planner!
  1108. manage_inactivity(true);
  1109. lcd_update(0);
  1110. #endif //TMC2130
  1111. }
  1112. }
  1113. void st_set_position(const long &x, const long &y, const long &z, const long &e)
  1114. {
  1115. CRITICAL_SECTION_START;
  1116. // Copy 4x4B.
  1117. // This block locks the interrupts globally for 4.56 us,
  1118. // which corresponds to a maximum repeat frequency of 219.18 kHz.
  1119. // This blocking is safe in the context of a 10kHz stepper driver interrupt
  1120. // or a 115200 Bd serial line receive interrupt, which will not trigger faster than 12kHz.
  1121. count_position[X_AXIS] = x;
  1122. count_position[Y_AXIS] = y;
  1123. count_position[Z_AXIS] = z;
  1124. count_position[E_AXIS] = e;
  1125. CRITICAL_SECTION_END;
  1126. }
  1127. void st_set_e_position(const long &e)
  1128. {
  1129. CRITICAL_SECTION_START;
  1130. count_position[E_AXIS] = e;
  1131. CRITICAL_SECTION_END;
  1132. }
  1133. long st_get_position(uint8_t axis)
  1134. {
  1135. long count_pos;
  1136. CRITICAL_SECTION_START;
  1137. count_pos = count_position[axis];
  1138. CRITICAL_SECTION_END;
  1139. return count_pos;
  1140. }
  1141. void st_get_position_xy(long &x, long &y)
  1142. {
  1143. CRITICAL_SECTION_START;
  1144. x = count_position[X_AXIS];
  1145. y = count_position[Y_AXIS];
  1146. CRITICAL_SECTION_END;
  1147. }
  1148. float st_get_position_mm(uint8_t axis)
  1149. {
  1150. float steper_position_in_steps = st_get_position(axis);
  1151. return steper_position_in_steps / cs.axis_steps_per_unit[axis];
  1152. }
  1153. void finishAndDisableSteppers()
  1154. {
  1155. st_synchronize();
  1156. disable_x();
  1157. disable_y();
  1158. disable_z();
  1159. disable_e0();
  1160. disable_e1();
  1161. disable_e2();
  1162. }
  1163. void quickStop()
  1164. {
  1165. DISABLE_STEPPER_DRIVER_INTERRUPT();
  1166. while (blocks_queued()) plan_discard_current_block();
  1167. current_block = NULL;
  1168. st_reset_timer();
  1169. ENABLE_STEPPER_DRIVER_INTERRUPT();
  1170. }
  1171. #ifdef BABYSTEPPING
  1172. void babystep(const uint8_t axis,const bool direction)
  1173. {
  1174. //MUST ONLY BE CALLED BY A ISR, it depends on that no other ISR interrupts this
  1175. //store initial pin states
  1176. switch(axis)
  1177. {
  1178. case X_AXIS:
  1179. {
  1180. enable_x();
  1181. uint8_t old_x_dir_pin= READ(X_DIR_PIN); //if dualzstepper, both point to same direction.
  1182. //setup new step
  1183. WRITE(X_DIR_PIN,(INVERT_X_DIR)^direction);
  1184. //perform step
  1185. WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN);
  1186. #ifdef DEBUG_XSTEP_DUP_PIN
  1187. WRITE(DEBUG_XSTEP_DUP_PIN,!INVERT_X_STEP_PIN);
  1188. #endif //DEBUG_XSTEP_DUP_PIN
  1189. delayMicroseconds(1);
  1190. WRITE(X_STEP_PIN, INVERT_X_STEP_PIN);
  1191. #ifdef DEBUG_XSTEP_DUP_PIN
  1192. WRITE(DEBUG_XSTEP_DUP_PIN,INVERT_X_STEP_PIN);
  1193. #endif //DEBUG_XSTEP_DUP_PIN
  1194. //get old pin state back.
  1195. WRITE(X_DIR_PIN,old_x_dir_pin);
  1196. }
  1197. break;
  1198. case Y_AXIS:
  1199. {
  1200. enable_y();
  1201. uint8_t old_y_dir_pin= READ(Y_DIR_PIN); //if dualzstepper, both point to same direction.
  1202. //setup new step
  1203. WRITE(Y_DIR_PIN,(INVERT_Y_DIR)^direction);
  1204. //perform step
  1205. WRITE(Y_STEP_PIN, !INVERT_Y_STEP_PIN);
  1206. #ifdef DEBUG_YSTEP_DUP_PIN
  1207. WRITE(DEBUG_YSTEP_DUP_PIN,!INVERT_Y_STEP_PIN);
  1208. #endif //DEBUG_YSTEP_DUP_PIN
  1209. delayMicroseconds(1);
  1210. WRITE(Y_STEP_PIN, INVERT_Y_STEP_PIN);
  1211. #ifdef DEBUG_YSTEP_DUP_PIN
  1212. WRITE(DEBUG_YSTEP_DUP_PIN,INVERT_Y_STEP_PIN);
  1213. #endif //DEBUG_YSTEP_DUP_PIN
  1214. //get old pin state back.
  1215. WRITE(Y_DIR_PIN,old_y_dir_pin);
  1216. }
  1217. break;
  1218. case Z_AXIS:
  1219. {
  1220. enable_z();
  1221. uint8_t old_z_dir_pin= READ(Z_DIR_PIN); //if dualzstepper, both point to same direction.
  1222. //setup new step
  1223. WRITE(Z_DIR_PIN,(INVERT_Z_DIR)^direction^BABYSTEP_INVERT_Z);
  1224. #ifdef Z_DUAL_STEPPER_DRIVERS
  1225. WRITE(Z2_DIR_PIN,(INVERT_Z_DIR)^direction^BABYSTEP_INVERT_Z);
  1226. #endif
  1227. //perform step
  1228. WRITE(Z_STEP_PIN, !INVERT_Z_STEP_PIN);
  1229. #ifdef Z_DUAL_STEPPER_DRIVERS
  1230. WRITE(Z2_STEP_PIN, !INVERT_Z_STEP_PIN);
  1231. #endif
  1232. delayMicroseconds(1);
  1233. WRITE(Z_STEP_PIN, INVERT_Z_STEP_PIN);
  1234. #ifdef Z_DUAL_STEPPER_DRIVERS
  1235. WRITE(Z2_STEP_PIN, INVERT_Z_STEP_PIN);
  1236. #endif
  1237. //get old pin state back.
  1238. WRITE(Z_DIR_PIN,old_z_dir_pin);
  1239. #ifdef Z_DUAL_STEPPER_DRIVERS
  1240. WRITE(Z2_DIR_PIN,old_z_dir_pin);
  1241. #endif
  1242. }
  1243. break;
  1244. default: break;
  1245. }
  1246. }
  1247. #endif //BABYSTEPPING
  1248. #if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1
  1249. void digitalPotWrite(int address, int value) // From Arduino DigitalPotControl example
  1250. {
  1251. digitalWrite(DIGIPOTSS_PIN,LOW); // take the SS pin low to select the chip
  1252. SPI.transfer(address); // send in the address and value via SPI:
  1253. SPI.transfer(value);
  1254. digitalWrite(DIGIPOTSS_PIN,HIGH); // take the SS pin high to de-select the chip:
  1255. //_delay(10);
  1256. }
  1257. #endif
  1258. void EEPROM_read_st(int pos, uint8_t* value, uint8_t size)
  1259. {
  1260. do
  1261. {
  1262. *value = eeprom_read_byte((unsigned char*)pos);
  1263. pos++;
  1264. value++;
  1265. }while(--size);
  1266. }
  1267. void st_current_init() //Initialize Digipot Motor Current
  1268. {
  1269. uint8_t SilentMode = eeprom_read_byte((uint8_t*)EEPROM_SILENT);
  1270. SilentModeMenu = SilentMode;
  1271. #ifdef MOTOR_CURRENT_PWM_XY_PIN
  1272. pinMode(MOTOR_CURRENT_PWM_XY_PIN, OUTPUT);
  1273. pinMode(MOTOR_CURRENT_PWM_Z_PIN, OUTPUT);
  1274. pinMode(MOTOR_CURRENT_PWM_E_PIN, OUTPUT);
  1275. if((SilentMode == SILENT_MODE_OFF) || (farm_mode) ){
  1276. motor_current_setting[0] = motor_current_setting_loud[0];
  1277. motor_current_setting[1] = motor_current_setting_loud[1];
  1278. motor_current_setting[2] = motor_current_setting_loud[2];
  1279. }else{
  1280. motor_current_setting[0] = motor_current_setting_silent[0];
  1281. motor_current_setting[1] = motor_current_setting_silent[1];
  1282. motor_current_setting[2] = motor_current_setting_silent[2];
  1283. }
  1284. st_current_set(0, motor_current_setting[0]);
  1285. st_current_set(1, motor_current_setting[1]);
  1286. st_current_set(2, motor_current_setting[2]);
  1287. //Set timer5 to 31khz so the PWM of the motor power is as constant as possible. (removes a buzzing noise)
  1288. TCCR5B = (TCCR5B & ~(_BV(CS50) | _BV(CS51) | _BV(CS52))) | _BV(CS50);
  1289. #endif
  1290. }
  1291. #ifdef MOTOR_CURRENT_PWM_XY_PIN
  1292. void st_current_set(uint8_t driver, int current)
  1293. {
  1294. if (driver == 0) analogWrite(MOTOR_CURRENT_PWM_XY_PIN, (long)current * 255L / (long)MOTOR_CURRENT_PWM_RANGE);
  1295. if (driver == 1) analogWrite(MOTOR_CURRENT_PWM_Z_PIN, (long)current * 255L / (long)MOTOR_CURRENT_PWM_RANGE);
  1296. if (driver == 2) analogWrite(MOTOR_CURRENT_PWM_E_PIN, (long)current * 255L / (long)MOTOR_CURRENT_PWM_RANGE);
  1297. }
  1298. #else //MOTOR_CURRENT_PWM_XY_PIN
  1299. void st_current_set(uint8_t, int ){}
  1300. #endif //MOTOR_CURRENT_PWM_XY_PIN
  1301. void microstep_init()
  1302. {
  1303. #if defined(E1_MS1_PIN) && E1_MS1_PIN > -1
  1304. pinMode(E1_MS1_PIN,OUTPUT);
  1305. pinMode(E1_MS2_PIN,OUTPUT);
  1306. #endif
  1307. #if defined(X_MS1_PIN) && X_MS1_PIN > -1
  1308. const uint8_t microstep_modes[] = MICROSTEP_MODES;
  1309. pinMode(X_MS1_PIN,OUTPUT);
  1310. pinMode(X_MS2_PIN,OUTPUT);
  1311. pinMode(Y_MS1_PIN,OUTPUT);
  1312. pinMode(Y_MS2_PIN,OUTPUT);
  1313. pinMode(Z_MS1_PIN,OUTPUT);
  1314. pinMode(Z_MS2_PIN,OUTPUT);
  1315. pinMode(E0_MS1_PIN,OUTPUT);
  1316. pinMode(E0_MS2_PIN,OUTPUT);
  1317. for(int i=0;i<=4;i++) microstep_mode(i,microstep_modes[i]);
  1318. #endif
  1319. }
  1320. #ifndef TMC2130
  1321. void microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2)
  1322. {
  1323. if(ms1 > -1) switch(driver)
  1324. {
  1325. case 0: digitalWrite( X_MS1_PIN,ms1); break;
  1326. case 1: digitalWrite( Y_MS1_PIN,ms1); break;
  1327. case 2: digitalWrite( Z_MS1_PIN,ms1); break;
  1328. case 3: digitalWrite(E0_MS1_PIN,ms1); break;
  1329. #if defined(E1_MS1_PIN) && E1_MS1_PIN > -1
  1330. case 4: digitalWrite(E1_MS1_PIN,ms1); break;
  1331. #endif
  1332. }
  1333. if(ms2 > -1) switch(driver)
  1334. {
  1335. case 0: digitalWrite( X_MS2_PIN,ms2); break;
  1336. case 1: digitalWrite( Y_MS2_PIN,ms2); break;
  1337. case 2: digitalWrite( Z_MS2_PIN,ms2); break;
  1338. case 3: digitalWrite(E0_MS2_PIN,ms2); break;
  1339. #if defined(E1_MS2_PIN) && E1_MS2_PIN > -1
  1340. case 4: digitalWrite(E1_MS2_PIN,ms2); break;
  1341. #endif
  1342. }
  1343. }
  1344. void microstep_mode(uint8_t driver, uint8_t stepping_mode)
  1345. {
  1346. switch(stepping_mode)
  1347. {
  1348. case 1: microstep_ms(driver,MICROSTEP1); break;
  1349. case 2: microstep_ms(driver,MICROSTEP2); break;
  1350. case 4: microstep_ms(driver,MICROSTEP4); break;
  1351. case 8: microstep_ms(driver,MICROSTEP8); break;
  1352. case 16: microstep_ms(driver,MICROSTEP16); break;
  1353. }
  1354. }
  1355. void microstep_readings()
  1356. {
  1357. SERIAL_PROTOCOLPGM("MS1,MS2 Pins\n");
  1358. SERIAL_PROTOCOLPGM("X: ");
  1359. SERIAL_PROTOCOL( digitalRead(X_MS1_PIN));
  1360. SERIAL_PROTOCOLLN( digitalRead(X_MS2_PIN));
  1361. SERIAL_PROTOCOLPGM("Y: ");
  1362. SERIAL_PROTOCOL( digitalRead(Y_MS1_PIN));
  1363. SERIAL_PROTOCOLLN( digitalRead(Y_MS2_PIN));
  1364. SERIAL_PROTOCOLPGM("Z: ");
  1365. SERIAL_PROTOCOL( digitalRead(Z_MS1_PIN));
  1366. SERIAL_PROTOCOLLN( digitalRead(Z_MS2_PIN));
  1367. SERIAL_PROTOCOLPGM("E0: ");
  1368. SERIAL_PROTOCOL( digitalRead(E0_MS1_PIN));
  1369. SERIAL_PROTOCOLLN( digitalRead(E0_MS2_PIN));
  1370. #if defined(E1_MS1_PIN) && E1_MS1_PIN > -1
  1371. SERIAL_PROTOCOLPGM("E1: ");
  1372. SERIAL_PROTOCOL( digitalRead(E1_MS1_PIN));
  1373. SERIAL_PROTOCOLLN( digitalRead(E1_MS2_PIN));
  1374. #endif
  1375. }
  1376. #endif //TMC2130