|
@@ -383,8 +383,9 @@ ISR(TIMER1_COMPA_vect)
|
383
|
383
|
}
|
384
|
384
|
#endif //!ADVANCE
|
385
|
385
|
for(int8_t i=0; i < step_loops; i++) { // Take multiple steps per interrupt (For high speed moves)
|
386
|
|
- MSerial.checkRx();
|
387
|
|
- /*
|
|
386
|
+ MSerial.checkRx(); // Check for serial chars.
|
|
387
|
+
|
|
388
|
+ #ifdef ADVANCE
|
388
|
389
|
counter_e += current_block->steps_e;
|
389
|
390
|
if (counter_e > 0) {
|
390
|
391
|
counter_e -= current_block->step_event_count;
|
|
@@ -399,15 +400,11 @@ ISR(TIMER1_COMPA_vect)
|
399
|
400
|
CRITICAL_SECTION_END;
|
400
|
401
|
}
|
401
|
402
|
}
|
402
|
|
- */
|
403
|
|
- /*
|
404
|
403
|
// Do E steps + advance steps
|
405
|
|
- CRITICAL_SECTION_START;
|
406
|
404
|
e_steps += ((advance >> 16) - old_advance);
|
407
|
|
- CRITICAL_SECTION_END;
|
408
|
405
|
old_advance = advance >> 16;
|
409
|
|
- */
|
410
|
|
-
|
|
406
|
+ #endif //ADVANCE
|
|
407
|
+
|
411
|
408
|
counter_x += current_block->steps_x;
|
412
|
409
|
if (counter_x > 0) {
|
413
|
410
|
WRITE(X_STEP_PIN, HIGH);
|
|
@@ -461,7 +458,9 @@ ISR(TIMER1_COMPA_vect)
|
461
|
458
|
OCR1A = timer;
|
462
|
459
|
acceleration_time += timer;
|
463
|
460
|
#ifdef ADVANCE
|
464
|
|
- advance += advance_rate;
|
|
461
|
+ for(int8_t i=0; i < step_loops; i++) {
|
|
462
|
+ advance += advance_rate;
|
|
463
|
+ }
|
465
|
464
|
#endif
|
466
|
465
|
}
|
467
|
466
|
else if (step_events_completed > current_block->decelerate_after) {
|
|
@@ -483,7 +482,9 @@ ISR(TIMER1_COMPA_vect)
|
483
|
482
|
OCR1A = timer;
|
484
|
483
|
deceleration_time += timer;
|
485
|
484
|
#ifdef ADVANCE
|
486
|
|
- advance -= advance_rate;
|
|
485
|
+ for(int8_t i=0; i < step_loops; i++) {
|
|
486
|
+ advance -= advance_rate;
|
|
487
|
+ }
|
487
|
488
|
if(advance < final_advance)
|
488
|
489
|
advance = final_advance;
|
489
|
490
|
#endif //ADVANCE
|
|
@@ -491,7 +492,7 @@ ISR(TIMER1_COMPA_vect)
|
491
|
492
|
else {
|
492
|
493
|
OCR1A = OCR1A_nominal;
|
493
|
494
|
}
|
494
|
|
-
|
|
495
|
+
|
495
|
496
|
// If current block is finished, reset pointer
|
496
|
497
|
if (step_events_completed >= current_block->step_event_count) {
|
497
|
498
|
current_block = NULL;
|
|
@@ -506,22 +507,24 @@ ISR(TIMER1_COMPA_vect)
|
506
|
507
|
// Timer 0 is shared with millies
|
507
|
508
|
ISR(TIMER0_COMPA_vect)
|
508
|
509
|
{
|
509
|
|
- // Critical section needed because Timer 1 interrupt has higher priority.
|
510
|
|
- // The pin set functions are placed on trategic position to comply with the stepper driver timing.
|
511
|
|
- WRITE(E_STEP_PIN, LOW);
|
|
510
|
+ old_OCR0A += 25; // ~10kHz interrupt
|
|
511
|
+ OCR0A = old_OCR0A;
|
512
|
512
|
// Set E direction (Depends on E direction + advance)
|
513
|
|
- if (e_steps < 0) {
|
514
|
|
- WRITE(E_DIR_PIN,INVERT_E_DIR);
|
515
|
|
- e_steps++;
|
516
|
|
- WRITE(E_STEP_PIN, HIGH);
|
517
|
|
- }
|
518
|
|
- if (e_steps > 0) {
|
519
|
|
- WRITE(E_DIR_PIN,!INVERT_E_DIR);
|
520
|
|
- e_steps--;
|
521
|
|
- WRITE(E_STEP_PIN, HIGH);
|
|
513
|
+ for(unsigned char i=0; i<4;) {
|
|
514
|
+ WRITE(E_STEP_PIN, LOW);
|
|
515
|
+ if (e_steps == 0) break;
|
|
516
|
+ i++;
|
|
517
|
+ if (e_steps < 0) {
|
|
518
|
+ WRITE(E_DIR_PIN,INVERT_E_DIR);
|
|
519
|
+ e_steps++;
|
|
520
|
+ WRITE(E_STEP_PIN, HIGH);
|
|
521
|
+ }
|
|
522
|
+ if (e_steps > 0) {
|
|
523
|
+ WRITE(E_DIR_PIN,!INVERT_E_DIR);
|
|
524
|
+ e_steps--;
|
|
525
|
+ WRITE(E_STEP_PIN, HIGH);
|
|
526
|
+ }
|
522
|
527
|
}
|
523
|
|
- old_OCR0A += 25; // 10kHz interrupt
|
524
|
|
- OCR0A = old_OCR0A;
|
525
|
528
|
}
|
526
|
529
|
#endif // ADVANCE
|
527
|
530
|
|
|
@@ -638,6 +641,10 @@ void st_init()
|
638
|
641
|
ENABLE_STEPPER_DRIVER_INTERRUPT();
|
639
|
642
|
|
640
|
643
|
#ifdef ADVANCE
|
|
644
|
+ #if defined(TCCR0A) && defined(WGM01)
|
|
645
|
+ TCCR0A &= ~(1<<WGM01);
|
|
646
|
+ TCCR0A &= ~(1<<WGM00);
|
|
647
|
+ #endif
|
641
|
648
|
e_steps = 0;
|
642
|
649
|
TIMSK0 |= (1<<OCIE0A);
|
643
|
650
|
#endif //ADVANCE
|