My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

stepper.cpp 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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 "stepper.h"
  19. #include "Configuration.h"
  20. #include "Marlin.h"
  21. #include "planner.h"
  22. #include "pins.h"
  23. #include "fastio.h"
  24. #include "temperature.h"
  25. #include "ultralcd.h"
  26. #include "speed_lookuptable.h"
  27. //===========================================================================
  28. //=============================public variables ============================
  29. //===========================================================================
  30. block_t *current_block; // A pointer to the block currently being traced
  31. //===========================================================================
  32. //=============================private variables ============================
  33. //===========================================================================
  34. //static makes it inpossible to be called from outside of this file by extern.!
  35. // Variables used by The Stepper Driver Interrupt
  36. static unsigned char out_bits; // The next stepping-bits to be output
  37. static long counter_x, // Counter variables for the bresenham line tracer
  38. counter_y,
  39. counter_z,
  40. counter_e;
  41. static unsigned long step_events_completed; // The number of step events executed in the current block
  42. #ifdef ADVANCE
  43. static long advance_rate, advance, final_advance = 0;
  44. static short old_advance = 0;
  45. static short e_steps;
  46. #endif
  47. static unsigned char busy = false; // TRUE when SIG_OUTPUT_COMPARE1A is being serviced. Used to avoid retriggering that handler.
  48. static long acceleration_time, deceleration_time;
  49. //static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
  50. static unsigned short acc_step_rate; // needed for deccelaration start point
  51. static char step_loops;
  52. // if DEBUG_STEPS is enabled, M114 can be used to compare two methods of determining the X,Y,Z position of the printer.
  53. // for debugging purposes only, should be disabled by default
  54. #ifdef DEBUG_STEPS
  55. volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0};
  56. volatile int count_direction[NUM_AXIS] = { 1, 1, 1, 1};
  57. #endif
  58. //===========================================================================
  59. //=============================functions ============================
  60. //===========================================================================
  61. // intRes = intIn1 * intIn2 >> 16
  62. // uses:
  63. // r26 to store 0
  64. // r27 to store the byte 1 of the 24 bit result
  65. #define MultiU16X8toH16(intRes, charIn1, intIn2) \
  66. asm volatile ( \
  67. "clr r26 \n\t" \
  68. "mul %A1, %B2 \n\t" \
  69. "movw %A0, r0 \n\t" \
  70. "mul %A1, %A2 \n\t" \
  71. "add %A0, r1 \n\t" \
  72. "adc %B0, r26 \n\t" \
  73. "lsr r0 \n\t" \
  74. "adc %A0, r26 \n\t" \
  75. "adc %B0, r26 \n\t" \
  76. "clr r1 \n\t" \
  77. : \
  78. "=&r" (intRes) \
  79. : \
  80. "d" (charIn1), \
  81. "d" (intIn2) \
  82. : \
  83. "r26" \
  84. )
  85. // intRes = longIn1 * longIn2 >> 24
  86. // uses:
  87. // r26 to store 0
  88. // r27 to store the byte 1 of the 48bit result
  89. #define MultiU24X24toH16(intRes, longIn1, longIn2) \
  90. asm volatile ( \
  91. "clr r26 \n\t" \
  92. "mul %A1, %B2 \n\t" \
  93. "mov r27, r1 \n\t" \
  94. "mul %B1, %C2 \n\t" \
  95. "movw %A0, r0 \n\t" \
  96. "mul %C1, %C2 \n\t" \
  97. "add %B0, r0 \n\t" \
  98. "mul %C1, %B2 \n\t" \
  99. "add %A0, r0 \n\t" \
  100. "adc %B0, r1 \n\t" \
  101. "mul %A1, %C2 \n\t" \
  102. "add r27, r0 \n\t" \
  103. "adc %A0, r1 \n\t" \
  104. "adc %B0, r26 \n\t" \
  105. "mul %B1, %B2 \n\t" \
  106. "add r27, r0 \n\t" \
  107. "adc %A0, r1 \n\t" \
  108. "adc %B0, r26 \n\t" \
  109. "mul %C1, %A2 \n\t" \
  110. "add r27, r0 \n\t" \
  111. "adc %A0, r1 \n\t" \
  112. "adc %B0, r26 \n\t" \
  113. "mul %B1, %A2 \n\t" \
  114. "add r27, r1 \n\t" \
  115. "adc %A0, r26 \n\t" \
  116. "adc %B0, r26 \n\t" \
  117. "lsr r27 \n\t" \
  118. "adc %A0, r26 \n\t" \
  119. "adc %B0, r26 \n\t" \
  120. "clr r1 \n\t" \
  121. : \
  122. "=&r" (intRes) \
  123. : \
  124. "d" (longIn1), \
  125. "d" (longIn2) \
  126. : \
  127. "r26" , "r27" \
  128. )
  129. // Some useful constants
  130. #define ENABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 |= (1<<OCIE1A)
  131. #define DISABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 &= ~(1<<OCIE1A)
  132. // __________________________
  133. // /| |\ _________________ ^
  134. // / | | \ /| |\ |
  135. // / | | \ / | | \ s
  136. // / | | | | | \ p
  137. // / | | | | | \ e
  138. // +-----+------------------------+---+--+---------------+----+ e
  139. // | BLOCK 1 | BLOCK 2 | d
  140. //
  141. // time ----->
  142. //
  143. // The trapezoid is the shape the speed curve over time. It starts at block->initial_rate, accelerates
  144. // first block->accelerate_until step_events_completed, then keeps going at constant speed until
  145. // step_events_completed reaches block->decelerate_after after which it decelerates until the trapezoid generator is reset.
  146. // The slope of acceleration is calculated with the leib ramp alghorithm.
  147. void st_wake_up() {
  148. // TCNT1 = 0;
  149. ENABLE_STEPPER_DRIVER_INTERRUPT();
  150. }
  151. inline unsigned short calc_timer(unsigned short step_rate) {
  152. unsigned short timer;
  153. if(step_rate > MAX_STEP_FREQUENCY) step_rate = MAX_STEP_FREQUENCY;
  154. if(step_rate > 20000) { // If steprate > 20kHz >> step 4 times
  155. step_rate = step_rate >> 2;
  156. step_loops = 4;
  157. }
  158. else if(step_rate > 10000) { // If steprate > 10kHz >> step 2 times
  159. step_rate = step_rate >> 1;
  160. step_loops = 2;
  161. }
  162. else {
  163. step_loops = 1;
  164. }
  165. if(step_rate < 32) step_rate = 32;
  166. step_rate -= 32; // Correct for minimal speed
  167. if(step_rate >= (8*256)){ // higher step rate
  168. unsigned short table_address = (unsigned short)&speed_lookuptable_fast[(unsigned char)(step_rate>>8)][0];
  169. unsigned char tmp_step_rate = (step_rate & 0x00ff);
  170. unsigned short gain = (unsigned short)pgm_read_word_near(table_address+2);
  171. MultiU16X8toH16(timer, tmp_step_rate, gain);
  172. timer = (unsigned short)pgm_read_word_near(table_address) - timer;
  173. }
  174. else { // lower step rates
  175. unsigned short table_address = (unsigned short)&speed_lookuptable_slow[0][0];
  176. table_address += ((step_rate)>>1) & 0xfffc;
  177. timer = (unsigned short)pgm_read_word_near(table_address);
  178. timer -= (((unsigned short)pgm_read_word_near(table_address+2) * (unsigned char)(step_rate & 0x0007))>>3);
  179. }
  180. if(timer < 100) timer = 100;
  181. return timer;
  182. }
  183. // Initializes the trapezoid generator from the current block. Called whenever a new
  184. // block begins.
  185. inline void trapezoid_generator_reset() {
  186. #ifdef ADVANCE
  187. advance = current_block->initial_advance;
  188. final_advance = current_block->final_advance;
  189. #endif
  190. deceleration_time = 0;
  191. // advance_rate = current_block->advance_rate;
  192. // step_rate to timer interval
  193. acc_step_rate = current_block->initial_rate;
  194. acceleration_time = calc_timer(acc_step_rate);
  195. OCR1A = acceleration_time;
  196. }
  197. // "The Stepper Driver Interrupt" - This timer interrupt is the workhorse.
  198. // It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately.
  199. ISR(TIMER1_COMPA_vect)
  200. {
  201. if(busy){
  202. SERIAL_ERRORLN(*(unsigned short *)OCR1A<< " ISR overtaking itself.");
  203. return;
  204. } // The busy-flag is used to avoid reentering this interrupt
  205. busy = true;
  206. sei(); // Re enable interrupts (normally disabled while inside an interrupt handler)
  207. // If there is no current block, attempt to pop one from the buffer
  208. if (current_block == NULL) {
  209. // Anything in the buffer?
  210. current_block = plan_get_current_block();
  211. if (current_block != NULL) {
  212. trapezoid_generator_reset();
  213. counter_x = -(current_block->step_event_count >> 1);
  214. counter_y = counter_x;
  215. counter_z = counter_x;
  216. counter_e = counter_x;
  217. step_events_completed = 0;
  218. #ifdef ADVANCE
  219. e_steps = 0;
  220. #endif
  221. }
  222. else {
  223. // DISABLE_STEPPER_DRIVER_INTERRUPT();
  224. }
  225. }
  226. if (current_block != NULL) {
  227. // Set directions TO DO This should be done once during init of trapezoid. Endstops -> interrupt
  228. out_bits = current_block->direction_bits;
  229. #ifdef ADVANCE
  230. // Calculate E early.
  231. counter_e += current_block->steps_e;
  232. if (counter_e > 0) {
  233. counter_e -= current_block->step_event_count;
  234. if ((out_bits & (1<<E_AXIS)) != 0) { // - direction
  235. CRITICAL_SECTION_START;
  236. e_steps--;
  237. CRITICAL_SECTION_END;
  238. }
  239. else {
  240. CRITICAL_SECTION_START;
  241. e_steps++;
  242. CRITICAL_SECTION_END;
  243. }
  244. }
  245. // Do E steps + advance steps
  246. CRITICAL_SECTION_START;
  247. e_steps += ((advance >> 16) - old_advance);
  248. CRITICAL_SECTION_END;
  249. old_advance = advance >> 16;
  250. #endif //ADVANCE
  251. // Set direction en check limit switches
  252. if ((out_bits & (1<<X_AXIS)) != 0) { // -direction
  253. WRITE(X_DIR_PIN, INVERT_X_DIR);
  254. #ifdef DEBUG_STEPS
  255. count_direction[X_AXIS]=-1;
  256. #endif
  257. #if X_MIN_PIN > -1
  258. if(READ(X_MIN_PIN) != ENDSTOPS_INVERTING) {
  259. step_events_completed = current_block->step_event_count;
  260. }
  261. #endif
  262. }
  263. else { // +direction
  264. WRITE(X_DIR_PIN,!INVERT_X_DIR);
  265. #ifdef DEBUG_STEPS
  266. count_direction[X_AXIS]=1;
  267. #endif
  268. #if X_MAX_PIN > -1
  269. if((READ(X_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_x >0)){
  270. step_events_completed = current_block->step_event_count;
  271. }
  272. #endif
  273. }
  274. if ((out_bits & (1<<Y_AXIS)) != 0) { // -direction
  275. WRITE(Y_DIR_PIN,INVERT_Y_DIR);
  276. #ifdef DEBUG_STEPS
  277. count_direction[Y_AXIS]=-1;
  278. #endif
  279. #if Y_MIN_PIN > -1
  280. if(READ(Y_MIN_PIN) != ENDSTOPS_INVERTING) {
  281. step_events_completed = current_block->step_event_count;
  282. }
  283. #endif
  284. }
  285. else { // +direction
  286. WRITE(Y_DIR_PIN,!INVERT_Y_DIR);
  287. #ifdef DEBUG_STEPS
  288. count_direction[Y_AXIS]=1;
  289. #endif
  290. #if Y_MAX_PIN > -1
  291. if((READ(Y_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_y >0)){
  292. step_events_completed = current_block->step_event_count;
  293. }
  294. #endif
  295. }
  296. if ((out_bits & (1<<Z_AXIS)) != 0) { // -direction
  297. WRITE(Z_DIR_PIN,INVERT_Z_DIR);
  298. #ifdef DEBUG_STEPS
  299. count_direction[Z_AXIS]=-1;
  300. #endif
  301. #if Z_MIN_PIN > -1
  302. if(READ(Z_MIN_PIN) != ENDSTOPS_INVERTING) {
  303. step_events_completed = current_block->step_event_count;
  304. }
  305. #endif
  306. }
  307. else { // +direction
  308. WRITE(Z_DIR_PIN,!INVERT_Z_DIR);
  309. #ifdef DEBUG_STEPS
  310. count_direction[Z_AXIS]=1;
  311. #endif
  312. #if Z_MAX_PIN > -1
  313. if((READ(Z_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_z >0)){
  314. step_events_completed = current_block->step_event_count;
  315. }
  316. #endif
  317. }
  318. #ifndef ADVANCE
  319. if ((out_bits & (1<<E_AXIS)) != 0) // -direction
  320. WRITE(E_DIR_PIN,INVERT_E_DIR);
  321. else // +direction
  322. WRITE(E_DIR_PIN,!INVERT_E_DIR);
  323. #endif //!ADVANCE
  324. for(int8_t i=0; i < step_loops; i++) { // Take multiple steps per interrupt (For high speed moves)
  325. counter_x += current_block->steps_x;
  326. if (counter_x > 0) {
  327. WRITE(X_STEP_PIN, HIGH);
  328. counter_x -= current_block->step_event_count;
  329. WRITE(X_STEP_PIN, LOW);
  330. #ifdef DEBUG_STEPS
  331. count_position[X_AXIS]+=count_direction[X_AXIS];
  332. #endif
  333. }
  334. counter_y += current_block->steps_y;
  335. if (counter_y > 0) {
  336. WRITE(Y_STEP_PIN, HIGH);
  337. counter_y -= current_block->step_event_count;
  338. WRITE(Y_STEP_PIN, LOW);
  339. #ifdef DEBUG_STEPS
  340. count_position[Y_AXIS]+=count_direction[Y_AXIS];
  341. #endif
  342. }
  343. counter_z += current_block->steps_z;
  344. if (counter_z > 0) {
  345. WRITE(Z_STEP_PIN, HIGH);
  346. counter_z -= current_block->step_event_count;
  347. WRITE(Z_STEP_PIN, LOW);
  348. #ifdef DEBUG_STEPS
  349. count_position[Z_AXIS]+=count_direction[Z_AXIS];
  350. #endif
  351. }
  352. #ifndef ADVANCE
  353. counter_e += current_block->steps_e;
  354. if (counter_e > 0) {
  355. WRITE(E_STEP_PIN, HIGH);
  356. counter_e -= current_block->step_event_count;
  357. WRITE(E_STEP_PIN, LOW);
  358. }
  359. #endif //!ADVANCE
  360. step_events_completed += 1;
  361. if(step_events_completed >= current_block->step_event_count) break;
  362. }
  363. // Calculare new timer value
  364. unsigned short timer;
  365. unsigned short step_rate;
  366. if (step_events_completed <= current_block->accelerate_until) {
  367. MultiU24X24toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
  368. acc_step_rate += current_block->initial_rate;
  369. // upper limit
  370. if(acc_step_rate > current_block->nominal_rate)
  371. acc_step_rate = current_block->nominal_rate;
  372. // step_rate to timer interval
  373. timer = calc_timer(acc_step_rate);
  374. #ifdef ADVANCE
  375. advance += advance_rate;
  376. #endif
  377. acceleration_time += timer;
  378. OCR1A = timer;
  379. }
  380. else if (step_events_completed > current_block->decelerate_after) {
  381. MultiU24X24toH16(step_rate, deceleration_time, current_block->acceleration_rate);
  382. if(step_rate > acc_step_rate) { // Check step_rate stays positive
  383. step_rate = current_block->final_rate;
  384. }
  385. else {
  386. step_rate = acc_step_rate - step_rate; // Decelerate from aceleration end point.
  387. }
  388. // lower limit
  389. if(step_rate < current_block->final_rate)
  390. step_rate = current_block->final_rate;
  391. // step_rate to timer interval
  392. timer = calc_timer(step_rate);
  393. #ifdef ADVANCE
  394. advance -= advance_rate;
  395. if(advance < final_advance)
  396. advance = final_advance;
  397. #endif //ADVANCE
  398. deceleration_time += timer;
  399. OCR1A = timer;
  400. }
  401. // If current block is finished, reset pointer
  402. if (step_events_completed >= current_block->step_event_count) {
  403. current_block = NULL;
  404. plan_discard_current_block();
  405. }
  406. }
  407. cli(); // disable interrupts
  408. busy=false;
  409. }
  410. #ifdef ADVANCE
  411. unsigned char old_OCR0A;
  412. // Timer interrupt for E. e_steps is set in the main routine;
  413. // Timer 0 is shared with millies
  414. ISR(TIMER0_COMPA_vect)
  415. {
  416. // Critical section needed because Timer 1 interrupt has higher priority.
  417. // The pin set functions are placed on trategic position to comply with the stepper driver timing.
  418. WRITE(E_STEP_PIN, LOW);
  419. // Set E direction (Depends on E direction + advance)
  420. if (e_steps < 0) {
  421. WRITE(E_DIR_PIN,INVERT_E_DIR);
  422. e_steps++;
  423. WRITE(E_STEP_PIN, HIGH);
  424. }
  425. if (e_steps > 0) {
  426. WRITE(E_DIR_PIN,!INVERT_E_DIR);
  427. e_steps--;
  428. WRITE(E_STEP_PIN, HIGH);
  429. }
  430. old_OCR0A += 25; // 10kHz interrupt
  431. OCR0A = old_OCR0A;
  432. }
  433. #endif // ADVANCE
  434. void st_init()
  435. {
  436. //Initialize Dir Pins
  437. #if X_DIR_PIN > -1
  438. SET_OUTPUT(X_DIR_PIN);
  439. #endif
  440. #if Y_DIR_PIN > -1
  441. SET_OUTPUT(Y_DIR_PIN);
  442. #endif
  443. #if Z_DIR_PIN > -1
  444. SET_OUTPUT(Z_DIR_PIN);
  445. #endif
  446. #if E_DIR_PIN > -1
  447. SET_OUTPUT(E_DIR_PIN);
  448. #endif
  449. //Initialize Enable Pins - steppers default to disabled.
  450. #if (X_ENABLE_PIN > -1)
  451. SET_OUTPUT(X_ENABLE_PIN);
  452. if(!X_ENABLE_ON) WRITE(X_ENABLE_PIN,HIGH);
  453. #endif
  454. #if (Y_ENABLE_PIN > -1)
  455. SET_OUTPUT(Y_ENABLE_PIN);
  456. if(!Y_ENABLE_ON) WRITE(Y_ENABLE_PIN,HIGH);
  457. #endif
  458. #if (Z_ENABLE_PIN > -1)
  459. SET_OUTPUT(Z_ENABLE_PIN);
  460. if(!Z_ENABLE_ON) WRITE(Z_ENABLE_PIN,HIGH);
  461. #endif
  462. #if (E_ENABLE_PIN > -1)
  463. SET_OUTPUT(E_ENABLE_PIN);
  464. if(!E_ENABLE_ON) WRITE(E_ENABLE_PIN,HIGH);
  465. #endif
  466. //endstops and pullups
  467. #ifdef ENDSTOPPULLUPS
  468. #if X_MIN_PIN > -1
  469. SET_INPUT(X_MIN_PIN);
  470. WRITE(X_MIN_PIN,HIGH);
  471. #endif
  472. #if X_MAX_PIN > -1
  473. SET_INPUT(X_MAX_PIN);
  474. WRITE(X_MAX_PIN,HIGH);
  475. #endif
  476. #if Y_MIN_PIN > -1
  477. SET_INPUT(Y_MIN_PIN);
  478. WRITE(Y_MIN_PIN,HIGH);
  479. #endif
  480. #if Y_MAX_PIN > -1
  481. SET_INPUT(Y_MAX_PIN);
  482. WRITE(Y_MAX_PIN,HIGH);
  483. #endif
  484. #if Z_MIN_PIN > -1
  485. SET_INPUT(Z_MIN_PIN);
  486. WRITE(Z_MIN_PIN,HIGH);
  487. #endif
  488. #if Z_MAX_PIN > -1
  489. SET_INPUT(Z_MAX_PIN);
  490. WRITE(Z_MAX_PIN,HIGH);
  491. #endif
  492. #else //ENDSTOPPULLUPS
  493. #if X_MIN_PIN > -1
  494. SET_INPUT(X_MIN_PIN);
  495. #endif
  496. #if X_MAX_PIN > -1
  497. SET_INPUT(X_MAX_PIN);
  498. #endif
  499. #if Y_MIN_PIN > -1
  500. SET_INPUT(Y_MIN_PIN);
  501. #endif
  502. #if Y_MAX_PIN > -1
  503. SET_INPUT(Y_MAX_PIN);
  504. #endif
  505. #if Z_MIN_PIN > -1
  506. SET_INPUT(Z_MIN_PIN);
  507. #endif
  508. #if Z_MAX_PIN > -1
  509. SET_INPUT(Z_MAX_PIN);
  510. #endif
  511. #endif //ENDSTOPPULLUPS
  512. //Initialize Step Pins
  513. #if (X_STEP_PIN > -1)
  514. SET_OUTPUT(X_STEP_PIN);
  515. #endif
  516. #if (Y_STEP_PIN > -1)
  517. SET_OUTPUT(Y_STEP_PIN);
  518. #endif
  519. #if (Z_STEP_PIN > -1)
  520. SET_OUTPUT(Z_STEP_PIN);
  521. #endif
  522. #if (E_STEP_PIN > -1)
  523. SET_OUTPUT(E_STEP_PIN);
  524. #endif
  525. // waveform generation = 0100 = CTC
  526. TCCR1B &= ~(1<<WGM13);
  527. TCCR1B |= (1<<WGM12);
  528. TCCR1A &= ~(1<<WGM11);
  529. TCCR1A &= ~(1<<WGM10);
  530. // output mode = 00 (disconnected)
  531. TCCR1A &= ~(3<<COM1A0);
  532. TCCR1A &= ~(3<<COM1B0);
  533. TCCR1B = (TCCR1B & ~(0x07<<CS10)) | (2<<CS10); // 2MHz timer
  534. OCR1A = 0x4000;
  535. DISABLE_STEPPER_DRIVER_INTERRUPT();
  536. #ifdef ADVANCE
  537. e_steps = 0;
  538. TIMSK0 |= (1<<OCIE0A);
  539. #endif //ADVANCE
  540. sei();
  541. }
  542. // Block until all buffered steps are executed
  543. void st_synchronize()
  544. {
  545. while(plan_get_current_block()) {
  546. manage_heater();
  547. manage_inactivity(1);
  548. LCD_STATUS;
  549. }
  550. }