My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

stepper.cpp 18KB

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