|
@@ -89,13 +89,24 @@ long Stepper::counter_X = 0,
|
89
|
89
|
|
90
|
90
|
volatile unsigned long Stepper::step_events_completed = 0; // The number of step events executed in the current block
|
91
|
91
|
|
92
|
|
-#if ENABLED(ADVANCE)
|
|
92
|
+#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
|
|
93
|
+
|
93
|
94
|
unsigned char Stepper::old_OCR0A;
|
94
|
|
- long Stepper::final_advance = 0,
|
95
|
|
- Stepper::old_advance = 0,
|
96
|
|
- Stepper::e_steps[EXTRUDERS],
|
97
|
|
- Stepper::advance_rate,
|
98
|
|
- Stepper::advance;
|
|
95
|
+ volatile unsigned char Stepper::eISR_Rate = 200; // Keep the ISR at a low rate until needed
|
|
96
|
+
|
|
97
|
+ #if ENABLED(LIN_ADVANCE)
|
|
98
|
+ volatile int Stepper::e_steps[EXTRUDERS];
|
|
99
|
+ int Stepper::extruder_advance_k = LIN_ADVANCE_K,
|
|
100
|
+ Stepper::final_estep_rate,
|
|
101
|
+ Stepper::current_estep_rate[EXTRUDERS],
|
|
102
|
+ Stepper::current_adv_steps[EXTRUDERS];
|
|
103
|
+ #else
|
|
104
|
+ long Stepper::e_steps[EXTRUDERS],
|
|
105
|
+ Stepper::final_advance = 0,
|
|
106
|
+ Stepper::old_advance = 0,
|
|
107
|
+ Stepper::advance_rate,
|
|
108
|
+ Stepper::advance;
|
|
109
|
+ #endif
|
99
|
110
|
#endif
|
100
|
111
|
|
101
|
112
|
long Stepper::acceleration_time, Stepper::deceleration_time;
|
|
@@ -344,30 +355,32 @@ void Stepper::isr() {
|
344
|
355
|
customizedSerial.checkRx(); // Check for serial chars.
|
345
|
356
|
#endif
|
346
|
357
|
|
347
|
|
- #if ENABLED(ADVANCE)
|
348
|
|
- counter_E += current_block->steps[E_AXIS];
|
349
|
|
- if (counter_E > 0) {
|
350
|
|
- counter_E -= current_block->step_event_count;
|
351
|
|
- e_steps[current_block->active_extruder] += motor_direction(E_AXIS) ? -1 : 1;
|
352
|
|
- }
|
353
|
|
- #endif //ADVANCE
|
354
|
|
-
|
355
|
358
|
#if ENABLED(LIN_ADVANCE)
|
|
359
|
+
|
356
|
360
|
counter_E += current_block->steps[E_AXIS];
|
357
|
361
|
if (counter_E > 0) {
|
358
|
362
|
counter_E -= current_block->step_event_count;
|
359
|
|
- count_position[_AXIS(E)] += count_direction[_AXIS(E)];
|
|
363
|
+ count_position[E_AXIS] += count_direction[E_AXIS];
|
360
|
364
|
e_steps[current_block->active_extruder] += motor_direction(E_AXIS) ? -1 : 1;
|
361
|
365
|
}
|
362
|
|
-
|
363
|
|
- if (current_block->use_advance_lead){
|
|
366
|
+
|
|
367
|
+ if (current_block->use_advance_lead) {
|
364
|
368
|
int delta_adv_steps; //Maybe a char would be enough?
|
365
|
369
|
delta_adv_steps = (((long)extruder_advance_k * current_estep_rate[current_block->active_extruder]) >> 9) - current_adv_steps[current_block->active_extruder];
|
366
|
370
|
e_steps[current_block->active_extruder] += delta_adv_steps;
|
367
|
371
|
current_adv_steps[current_block->active_extruder] += delta_adv_steps;
|
368
|
372
|
}
|
369
|
|
- #endif //LIN_ADVANCE
|
370
|
373
|
|
|
374
|
+ #elif ENABLED(ADVANCE)
|
|
375
|
+
|
|
376
|
+ counter_E += current_block->steps[E_AXIS];
|
|
377
|
+ if (counter_E > 0) {
|
|
378
|
+ counter_E -= current_block->step_event_count;
|
|
379
|
+ e_steps[current_block->active_extruder] += motor_direction(E_AXIS) ? -1 : 1;
|
|
380
|
+ }
|
|
381
|
+
|
|
382
|
+ #endif // ADVANCE or LIN_ADVANCE
|
|
383
|
+
|
371
|
384
|
#define _COUNTER(AXIS) counter_## AXIS
|
372
|
385
|
#define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP
|
373
|
386
|
#define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN
|
|
@@ -379,7 +392,7 @@ void Stepper::isr() {
|
379
|
392
|
STEP_ADD(X);
|
380
|
393
|
STEP_ADD(Y);
|
381
|
394
|
STEP_ADD(Z);
|
382
|
|
- #if (DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE))
|
|
395
|
+ #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
|
383
|
396
|
STEP_ADD(E);
|
384
|
397
|
#endif
|
385
|
398
|
|
|
@@ -393,7 +406,7 @@ void Stepper::isr() {
|
393
|
406
|
STEP_IF_COUNTER(X);
|
394
|
407
|
STEP_IF_COUNTER(Y);
|
395
|
408
|
STEP_IF_COUNTER(Z);
|
396
|
|
- #if (DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE))
|
|
409
|
+ #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
|
397
|
410
|
STEP_IF_COUNTER(E);
|
398
|
411
|
#endif
|
399
|
412
|
|
|
@@ -416,12 +429,11 @@ void Stepper::isr() {
|
416
|
429
|
acceleration_time += timer;
|
417
|
430
|
|
418
|
431
|
#if ENABLED(LIN_ADVANCE)
|
419
|
|
- if (current_block->use_advance_lead){
|
|
432
|
+
|
|
433
|
+ if (current_block->use_advance_lead)
|
420
|
434
|
current_estep_rate[current_block->active_extruder] = ((unsigned long)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
|
421
|
|
- }
|
422
|
|
- #endif
|
423
|
435
|
|
424
|
|
- #if ENABLED(ADVANCE)
|
|
436
|
+ #elif ENABLED(ADVANCE)
|
425
|
437
|
|
426
|
438
|
advance += advance_rate * step_loops;
|
427
|
439
|
//NOLESS(advance, current_block->advance);
|
|
@@ -430,7 +442,8 @@ void Stepper::isr() {
|
430
|
442
|
e_steps[current_block->active_extruder] += ((advance >> 8) - old_advance);
|
431
|
443
|
old_advance = advance >> 8;
|
432
|
444
|
|
433
|
|
- #endif //ADVANCE
|
|
445
|
+ #endif // ADVANCE or LIN_ADVANCE
|
|
446
|
+
|
434
|
447
|
}
|
435
|
448
|
else if (step_events_completed > (unsigned long)current_block->decelerate_after) {
|
436
|
449
|
MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate);
|
|
@@ -448,12 +461,12 @@ void Stepper::isr() {
|
448
|
461
|
deceleration_time += timer;
|
449
|
462
|
|
450
|
463
|
#if ENABLED(LIN_ADVANCE)
|
451
|
|
- if (current_block->use_advance_lead){
|
|
464
|
+
|
|
465
|
+ if (current_block->use_advance_lead)
|
452
|
466
|
current_estep_rate[current_block->active_extruder] = ((unsigned long)step_rate * current_block->e_speed_multiplier8) >> 8;
|
453
|
|
- }
|
454
|
|
- #endif
|
455
|
467
|
|
456
|
|
- #if ENABLED(ADVANCE)
|
|
468
|
+ #elif ENABLED(ADVANCE)
|
|
469
|
+
|
457
|
470
|
advance -= advance_rate * step_loops;
|
458
|
471
|
NOLESS(advance, final_advance);
|
459
|
472
|
|
|
@@ -461,15 +474,15 @@ void Stepper::isr() {
|
461
|
474
|
uint32_t advance_whole = advance >> 8;
|
462
|
475
|
e_steps[current_block->active_extruder] += advance_whole - old_advance;
|
463
|
476
|
old_advance = advance_whole;
|
464
|
|
- #endif //ADVANCE
|
|
477
|
+
|
|
478
|
+ #endif // ADVANCE or LIN_ADVANCE
|
465
|
479
|
}
|
466
|
480
|
else {
|
467
|
|
- #ifdef LIN_ADVANCE
|
468
|
|
- if (current_block->use_advance_lead){
|
|
481
|
+ #if ENABLED(LIN_ADVANCE)
|
|
482
|
+ if (current_block->use_advance_lead)
|
469
|
483
|
current_estep_rate[current_block->active_extruder] = final_estep_rate;
|
470
|
|
- }
|
471
|
484
|
#endif
|
472
|
|
-
|
|
485
|
+
|
473
|
486
|
OCR1A = OCR1A_nominal;
|
474
|
487
|
// ensure we're running at the correct step rate, even if we just came off an acceleration
|
475
|
488
|
step_loops = step_loops_nominal;
|
|
@@ -485,12 +498,14 @@ void Stepper::isr() {
|
485
|
498
|
}
|
486
|
499
|
}
|
487
|
500
|
|
488
|
|
-#if ENABLED(ADVANCE)
|
|
501
|
+#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
|
|
502
|
+
|
489
|
503
|
// Timer interrupt for E. e_steps is set in the main routine;
|
490
|
504
|
// Timer 0 is shared with millies
|
491
|
505
|
ISR(TIMER0_COMPA_vect) { Stepper::advance_isr(); }
|
492
|
506
|
|
493
|
507
|
void Stepper::advance_isr() {
|
|
508
|
+
|
494
|
509
|
old_OCR0A += 52; // ~10kHz interrupt (250000 / 26 = 9615kHz)
|
495
|
510
|
OCR0A = old_OCR0A;
|
496
|
511
|
|
|
@@ -521,58 +536,10 @@ void Stepper::isr() {
|
521
|
536
|
#endif
|
522
|
537
|
#endif
|
523
|
538
|
}
|
524
|
|
- }
|
525
|
539
|
|
526
|
|
-#endif // ADVANCE
|
527
|
|
-
|
528
|
|
-#if ENABLED(LIN_ADVANCE)
|
529
|
|
-unsigned char old_OCR0A;
|
530
|
|
-// Timer interrupt for E. e_steps is set in the main routine;
|
531
|
|
-// Timer 0 is shared with millies
|
532
|
|
-ISR(TIMER0_COMPA_vect) { stepper.advance_isr(); }
|
533
|
|
-
|
534
|
|
-void Stepper::advance_isr() {
|
535
|
|
- old_OCR0A += 52; // ~10kHz interrupt (250000 / 26 = 9615kHz) war 52
|
536
|
|
- OCR0A = old_OCR0A;
|
537
|
|
-
|
538
|
|
-#define STEP_E_ONCE(INDEX) \
|
539
|
|
- if (e_steps[INDEX] != 0) { \
|
540
|
|
- E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN); \
|
541
|
|
- if (e_steps[INDEX] < 0) { \
|
542
|
|
- E## INDEX ##_DIR_WRITE(INVERT_E## INDEX ##_DIR); \
|
543
|
|
- e_steps[INDEX]++; \
|
544
|
|
- } \
|
545
|
|
- else if (e_steps[INDEX] > 0) { \
|
546
|
|
- E## INDEX ##_DIR_WRITE(!INVERT_E## INDEX ##_DIR); \
|
547
|
|
- e_steps[INDEX]--; \
|
548
|
|
- } \
|
549
|
|
- E## INDEX ##_STEP_WRITE(!INVERT_E_STEP_PIN); \
|
550
|
540
|
}
|
551
|
541
|
|
552
|
|
- // Step all E steppers that have steps, up to 4 steps per interrupt
|
553
|
|
- for (unsigned char i = 0; i < 4; i++) {
|
554
|
|
- #if EXTRUDERS > 3
|
555
|
|
- switch(current_block->active_extruder){case 3:STEP_E_ONCE(3);break;case 2:STEP_E_ONCE(2);break;case 1:STEP_E_ONCE(1);break;default:STEP_E_ONCE(0);}
|
556
|
|
- #elif EXTRUDERS > 2
|
557
|
|
- switch(current_block->active_extruder){case 2:STEP_E_ONCE(2);break;case 1:STEP_E_ONCE(1);break;default:STEP_E_ONCE(0);}
|
558
|
|
- #elif EXTRUDERS > 1
|
559
|
|
- #if DISABLED(DUAL_X_CARRIAGE)
|
560
|
|
- if(current_block->active_extruder == 1){STEP_E_ONCE(1)}else{STEP_E_ONCE(0);}
|
561
|
|
- #else
|
562
|
|
- extern bool extruder_duplication_enabled;
|
563
|
|
- if(extruder_duplication_enabled){
|
564
|
|
- STEP_E_ONCE(0);
|
565
|
|
- STEP_E_ONCE(1);
|
566
|
|
- }else {
|
567
|
|
- if(current_block->active_extruder == 1){STEP_E_ONCE(1)}else{STEP_E_ONCE(0);}
|
568
|
|
- }
|
569
|
|
- #endif
|
570
|
|
- #else
|
571
|
|
- STEP_E_ONCE(0);
|
572
|
|
- #endif
|
573
|
|
- }
|
574
|
|
-}
|
575
|
|
-#endif // LIN_ADVANCE
|
|
542
|
+#endif // ADVANCE or LIN_ADVANCE
|
576
|
543
|
|
577
|
544
|
void Stepper::init() {
|
578
|
545
|
|
|
@@ -738,27 +705,29 @@ void Stepper::init() {
|
738
|
705
|
OCR1A = 0x4000;
|
739
|
706
|
TCNT1 = 0;
|
740
|
707
|
ENABLE_STEPPER_DRIVER_INTERRUPT();
|
741
|
|
-
|
742
|
|
- #if ENABLED(LIN_ADVANCE)
|
743
|
|
- for (int i = 0; i < EXTRUDERS; i++){
|
744
|
|
- e_steps[i] = 0;
|
745
|
|
- current_adv_steps[i] = 0;
|
746
|
|
- }
|
747
|
|
- #if defined(TCCR0A) && defined(WGM01)
|
748
|
|
- CBI(TCCR0A, WGM01);
|
749
|
|
- CBI(TCCR0A, WGM00);
|
|
708
|
+
|
|
709
|
+ #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
|
|
710
|
+
|
|
711
|
+ #if ENABLED(LIN_ADVANCE)
|
|
712
|
+
|
|
713
|
+ for (int i = 0; i < EXTRUDERS; i++) {
|
|
714
|
+ e_steps[i] = 0;
|
|
715
|
+ current_adv_steps[i] = 0;
|
|
716
|
+ }
|
|
717
|
+
|
|
718
|
+ #elif ENABLED(ADVANCE)
|
|
719
|
+
|
|
720
|
+ for (uint8_t i = 0; i < EXTRUDERS; i++) e_steps[i] = 0;
|
|
721
|
+
|
750
|
722
|
#endif
|
751
|
|
- SBI(TIMSK0, OCIE0A);
|
752
|
|
- #endif //LIN_ADVANCE
|
753
|
723
|
|
754
|
|
- #if ENABLED(ADVANCE)
|
755
|
724
|
#if defined(TCCR0A) && defined(WGM01)
|
756
|
725
|
CBI(TCCR0A, WGM01);
|
757
|
726
|
CBI(TCCR0A, WGM00);
|
758
|
727
|
#endif
|
759
|
|
- for (uint8_t i = 0; i < EXTRUDERS; i++) e_steps[i] = 0;
|
760
|
728
|
SBI(TIMSK0, OCIE0A);
|
761
|
|
- #endif //ADVANCE
|
|
729
|
+
|
|
730
|
+ #endif // ADVANCE or LIN_ADVANCE
|
762
|
731
|
|
763
|
732
|
endstops.enable(true); // Start with endstops active. After homing they can be disabled
|
764
|
733
|
sei();
|
|
@@ -1137,15 +1106,12 @@ void Stepper::microstep_readings() {
|
1137
|
1106
|
}
|
1138
|
1107
|
|
1139
|
1108
|
#if ENABLED(LIN_ADVANCE)
|
|
1109
|
+
|
1140
|
1110
|
void Stepper::advance_M905() {
|
1141
|
1111
|
if (code_seen('K')) extruder_advance_k = code_value();
|
1142
|
1112
|
SERIAL_ECHO_START;
|
1143
|
|
- SERIAL_ECHOPGM("Advance factor:");
|
1144
|
|
- SERIAL_CHAR(' ');
|
1145
|
|
- SERIAL_ECHOLN(extruder_advance_k);
|
|
1113
|
+ SERIAL_ECHOPAIR("Advance factor: ", extruder_advance_k);
|
|
1114
|
+ SERIAL_EOL;
|
1146
|
1115
|
}
|
1147
|
1116
|
|
1148
|
|
- int Stepper::get_advance_k(){
|
1149
|
|
- return extruder_advance_k;
|
1150
|
|
- }
|
1151
|
|
-#endif
|
|
1117
|
+#endif // LIN_ADVANCE
|