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 17KB

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