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.

stepper.cpp 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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_ERROR_START
  203. SERIAL_ERROR(*(unsigned short *)OCR1A);
  204. SERIAL_ERRORLNPGM(" ISR overtaking itself.");
  205. return;
  206. } // The busy-flag is used to avoid reentering this interrupt
  207. busy = true;
  208. sei(); // Re enable interrupts (normally disabled while inside an interrupt handler)
  209. // If there is no current block, attempt to pop one from the buffer
  210. if (current_block == NULL) {
  211. // Anything in the buffer?
  212. current_block = plan_get_current_block();
  213. if (current_block != NULL) {
  214. trapezoid_generator_reset();
  215. counter_x = -(current_block->step_event_count >> 1);
  216. counter_y = counter_x;
  217. counter_z = counter_x;
  218. counter_e = counter_x;
  219. step_events_completed = 0;
  220. #ifdef ADVANCE
  221. e_steps = 0;
  222. #endif
  223. }
  224. else {
  225. // DISABLE_STEPPER_DRIVER_INTERRUPT();
  226. }
  227. }
  228. if (current_block != NULL) {
  229. // Set directions TO DO This should be done once during init of trapezoid. Endstops -> interrupt
  230. out_bits = current_block->direction_bits;
  231. #ifdef ADVANCE
  232. // Calculate E early.
  233. counter_e += current_block->steps_e;
  234. if (counter_e > 0) {
  235. counter_e -= current_block->step_event_count;
  236. if ((out_bits & (1<<E_AXIS)) != 0) { // - direction
  237. CRITICAL_SECTION_START;
  238. e_steps--;
  239. CRITICAL_SECTION_END;
  240. }
  241. else {
  242. CRITICAL_SECTION_START;
  243. e_steps++;
  244. CRITICAL_SECTION_END;
  245. }
  246. }
  247. // Do E steps + advance steps
  248. CRITICAL_SECTION_START;
  249. e_steps += ((advance >> 16) - old_advance);
  250. CRITICAL_SECTION_END;
  251. old_advance = advance >> 16;
  252. #endif //ADVANCE
  253. // Set direction en check limit switches
  254. if ((out_bits & (1<<X_AXIS)) != 0) { // -direction
  255. WRITE(X_DIR_PIN, INVERT_X_DIR);
  256. #ifdef DEBUG_STEPS
  257. count_direction[X_AXIS]=-1;
  258. #endif
  259. #if X_MIN_PIN > -1
  260. if(READ(X_MIN_PIN) != ENDSTOPS_INVERTING) {
  261. step_events_completed = current_block->step_event_count;
  262. }
  263. #endif
  264. }
  265. else { // +direction
  266. WRITE(X_DIR_PIN,!INVERT_X_DIR);
  267. #ifdef DEBUG_STEPS
  268. count_direction[X_AXIS]=1;
  269. #endif
  270. #if X_MAX_PIN > -1
  271. if((READ(X_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_x >0)){
  272. step_events_completed = current_block->step_event_count;
  273. }
  274. #endif
  275. }
  276. if ((out_bits & (1<<Y_AXIS)) != 0) { // -direction
  277. WRITE(Y_DIR_PIN,INVERT_Y_DIR);
  278. #ifdef DEBUG_STEPS
  279. count_direction[Y_AXIS]=-1;
  280. #endif
  281. #if Y_MIN_PIN > -1
  282. if(READ(Y_MIN_PIN) != ENDSTOPS_INVERTING) {
  283. step_events_completed = current_block->step_event_count;
  284. }
  285. #endif
  286. }
  287. else { // +direction
  288. WRITE(Y_DIR_PIN,!INVERT_Y_DIR);
  289. #ifdef DEBUG_STEPS
  290. count_direction[Y_AXIS]=1;
  291. #endif
  292. #if Y_MAX_PIN > -1
  293. if((READ(Y_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_y >0)){
  294. step_events_completed = current_block->step_event_count;
  295. }
  296. #endif
  297. }
  298. if ((out_bits & (1<<Z_AXIS)) != 0) { // -direction
  299. WRITE(Z_DIR_PIN,INVERT_Z_DIR);
  300. #ifdef DEBUG_STEPS
  301. count_direction[Z_AXIS]=-1;
  302. #endif
  303. #if Z_MIN_PIN > -1
  304. if(READ(Z_MIN_PIN) != ENDSTOPS_INVERTING) {
  305. step_events_completed = current_block->step_event_count;
  306. }
  307. #endif
  308. }
  309. else { // +direction
  310. WRITE(Z_DIR_PIN,!INVERT_Z_DIR);
  311. #ifdef DEBUG_STEPS
  312. count_direction[Z_AXIS]=1;
  313. #endif
  314. #if Z_MAX_PIN > -1
  315. if((READ(Z_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_z >0)){
  316. step_events_completed = current_block->step_event_count;
  317. }
  318. #endif
  319. }
  320. #ifndef ADVANCE
  321. if ((out_bits & (1<<E_AXIS)) != 0) // -direction
  322. WRITE(E_DIR_PIN,INVERT_E_DIR);
  323. else // +direction
  324. WRITE(E_DIR_PIN,!INVERT_E_DIR);
  325. #endif //!ADVANCE
  326. for(int8_t i=0; i < step_loops; i++) { // Take multiple steps per interrupt (For high speed moves)
  327. counter_x += current_block->steps_x;
  328. if (counter_x > 0) {
  329. WRITE(X_STEP_PIN, HIGH);
  330. counter_x -= current_block->step_event_count;
  331. WRITE(X_STEP_PIN, LOW);
  332. #ifdef DEBUG_STEPS
  333. count_position[X_AXIS]+=count_direction[X_AXIS];
  334. #endif
  335. }
  336. counter_y += current_block->steps_y;
  337. if (counter_y > 0) {
  338. WRITE(Y_STEP_PIN, HIGH);
  339. counter_y -= current_block->step_event_count;
  340. WRITE(Y_STEP_PIN, LOW);
  341. #ifdef DEBUG_STEPS
  342. count_position[Y_AXIS]+=count_direction[Y_AXIS];
  343. #endif
  344. }
  345. counter_z += current_block->steps_z;
  346. if (counter_z > 0) {
  347. WRITE(Z_STEP_PIN, HIGH);
  348. counter_z -= current_block->step_event_count;
  349. WRITE(Z_STEP_PIN, LOW);
  350. #ifdef DEBUG_STEPS
  351. count_position[Z_AXIS]+=count_direction[Z_AXIS];
  352. #endif
  353. }
  354. #ifndef ADVANCE
  355. counter_e += current_block->steps_e;
  356. if (counter_e > 0) {
  357. WRITE(E_STEP_PIN, HIGH);
  358. counter_e -= current_block->step_event_count;
  359. WRITE(E_STEP_PIN, LOW);
  360. }
  361. #endif //!ADVANCE
  362. step_events_completed += 1;
  363. if(step_events_completed >= current_block->step_event_count) break;
  364. }
  365. // Calculare new timer value
  366. unsigned short timer;
  367. unsigned short step_rate;
  368. if (step_events_completed <= current_block->accelerate_until) {
  369. MultiU24X24toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
  370. acc_step_rate += current_block->initial_rate;
  371. // upper limit
  372. if(acc_step_rate > current_block->nominal_rate)
  373. acc_step_rate = current_block->nominal_rate;
  374. // step_rate to timer interval
  375. timer = calc_timer(acc_step_rate);
  376. #ifdef ADVANCE
  377. advance += advance_rate;
  378. #endif
  379. acceleration_time += timer;
  380. OCR1A = timer;
  381. }
  382. else if (step_events_completed > current_block->decelerate_after) {
  383. MultiU24X24toH16(step_rate, deceleration_time, current_block->acceleration_rate);
  384. if(step_rate > acc_step_rate) { // Check step_rate stays positive
  385. step_rate = current_block->final_rate;
  386. }
  387. else {
  388. step_rate = acc_step_rate - step_rate; // Decelerate from aceleration end point.
  389. }
  390. // lower limit
  391. if(step_rate < current_block->final_rate)
  392. step_rate = current_block->final_rate;
  393. // step_rate to timer interval
  394. timer = calc_timer(step_rate);
  395. #ifdef ADVANCE
  396. advance -= advance_rate;
  397. if(advance < final_advance)
  398. advance = final_advance;
  399. #endif //ADVANCE
  400. deceleration_time += timer;
  401. OCR1A = timer;
  402. }
  403. // If current block is finished, reset pointer
  404. if (step_events_completed >= current_block->step_event_count) {
  405. current_block = NULL;
  406. plan_discard_current_block();
  407. }
  408. }
  409. cli(); // disable interrupts
  410. busy=false;
  411. }
  412. #ifdef ADVANCE
  413. unsigned char old_OCR0A;
  414. // Timer interrupt for E. e_steps is set in the main routine;
  415. // Timer 0 is shared with millies
  416. ISR(TIMER0_COMPA_vect)
  417. {
  418. // Critical section needed because Timer 1 interrupt has higher priority.
  419. // The pin set functions are placed on trategic position to comply with the stepper driver timing.
  420. WRITE(E_STEP_PIN, LOW);
  421. // Set E direction (Depends on E direction + advance)
  422. if (e_steps < 0) {
  423. WRITE(E_DIR_PIN,INVERT_E_DIR);
  424. e_steps++;
  425. WRITE(E_STEP_PIN, HIGH);
  426. }
  427. if (e_steps > 0) {
  428. WRITE(E_DIR_PIN,!INVERT_E_DIR);
  429. e_steps--;
  430. WRITE(E_STEP_PIN, HIGH);
  431. }
  432. old_OCR0A += 25; // 10kHz interrupt
  433. OCR0A = old_OCR0A;
  434. }
  435. #endif // ADVANCE
  436. void st_init()
  437. {
  438. //Initialize Dir Pins
  439. #if X_DIR_PIN > -1
  440. SET_OUTPUT(X_DIR_PIN);
  441. #endif
  442. #if Y_DIR_PIN > -1
  443. SET_OUTPUT(Y_DIR_PIN);
  444. #endif
  445. #if Z_DIR_PIN > -1
  446. SET_OUTPUT(Z_DIR_PIN);
  447. #endif
  448. #if E_DIR_PIN > -1
  449. SET_OUTPUT(E_DIR_PIN);
  450. #endif
  451. //Initialize Enable Pins - steppers default to disabled.
  452. #if (X_ENABLE_PIN > -1)
  453. SET_OUTPUT(X_ENABLE_PIN);
  454. if(!X_ENABLE_ON) WRITE(X_ENABLE_PIN,HIGH);
  455. #endif
  456. #if (Y_ENABLE_PIN > -1)
  457. SET_OUTPUT(Y_ENABLE_PIN);
  458. if(!Y_ENABLE_ON) WRITE(Y_ENABLE_PIN,HIGH);
  459. #endif
  460. #if (Z_ENABLE_PIN > -1)
  461. SET_OUTPUT(Z_ENABLE_PIN);
  462. if(!Z_ENABLE_ON) WRITE(Z_ENABLE_PIN,HIGH);
  463. #endif
  464. #if (E_ENABLE_PIN > -1)
  465. SET_OUTPUT(E_ENABLE_PIN);
  466. if(!E_ENABLE_ON) WRITE(E_ENABLE_PIN,HIGH);
  467. #endif
  468. //endstops and pullups
  469. #ifdef ENDSTOPPULLUPS
  470. #if X_MIN_PIN > -1
  471. SET_INPUT(X_MIN_PIN);
  472. WRITE(X_MIN_PIN,HIGH);
  473. #endif
  474. #if X_MAX_PIN > -1
  475. SET_INPUT(X_MAX_PIN);
  476. WRITE(X_MAX_PIN,HIGH);
  477. #endif
  478. #if Y_MIN_PIN > -1
  479. SET_INPUT(Y_MIN_PIN);
  480. WRITE(Y_MIN_PIN,HIGH);
  481. #endif
  482. #if Y_MAX_PIN > -1
  483. SET_INPUT(Y_MAX_PIN);
  484. WRITE(Y_MAX_PIN,HIGH);
  485. #endif
  486. #if Z_MIN_PIN > -1
  487. SET_INPUT(Z_MIN_PIN);
  488. WRITE(Z_MIN_PIN,HIGH);
  489. #endif
  490. #if Z_MAX_PIN > -1
  491. SET_INPUT(Z_MAX_PIN);
  492. WRITE(Z_MAX_PIN,HIGH);
  493. #endif
  494. #else //ENDSTOPPULLUPS
  495. #if X_MIN_PIN > -1
  496. SET_INPUT(X_MIN_PIN);
  497. #endif
  498. #if X_MAX_PIN > -1
  499. SET_INPUT(X_MAX_PIN);
  500. #endif
  501. #if Y_MIN_PIN > -1
  502. SET_INPUT(Y_MIN_PIN);
  503. #endif
  504. #if Y_MAX_PIN > -1
  505. SET_INPUT(Y_MAX_PIN);
  506. #endif
  507. #if Z_MIN_PIN > -1
  508. SET_INPUT(Z_MIN_PIN);
  509. #endif
  510. #if Z_MAX_PIN > -1
  511. SET_INPUT(Z_MAX_PIN);
  512. #endif
  513. #endif //ENDSTOPPULLUPS
  514. //Initialize Step Pins
  515. #if (X_STEP_PIN > -1)
  516. SET_OUTPUT(X_STEP_PIN);
  517. #endif
  518. #if (Y_STEP_PIN > -1)
  519. SET_OUTPUT(Y_STEP_PIN);
  520. #endif
  521. #if (Z_STEP_PIN > -1)
  522. SET_OUTPUT(Z_STEP_PIN);
  523. #endif
  524. #if (E_STEP_PIN > -1)
  525. SET_OUTPUT(E_STEP_PIN);
  526. #endif
  527. // waveform generation = 0100 = CTC
  528. TCCR1B &= ~(1<<WGM13);
  529. TCCR1B |= (1<<WGM12);
  530. TCCR1A &= ~(1<<WGM11);
  531. TCCR1A &= ~(1<<WGM10);
  532. // output mode = 00 (disconnected)
  533. TCCR1A &= ~(3<<COM1A0);
  534. TCCR1A &= ~(3<<COM1B0);
  535. TCCR1B = (TCCR1B & ~(0x07<<CS10)) | (2<<CS10); // 2MHz timer
  536. OCR1A = 0x4000;
  537. DISABLE_STEPPER_DRIVER_INTERRUPT();
  538. #ifdef ADVANCE
  539. e_steps = 0;
  540. TIMSK0 |= (1<<OCIE0A);
  541. #endif //ADVANCE
  542. sei();
  543. }
  544. // Block until all buffered steps are executed
  545. void st_synchronize()
  546. {
  547. while(plan_get_current_block()) {
  548. manage_heater();
  549. manage_inactivity(1);
  550. LCD_STATUS;
  551. }
  552. }