|
@@ -351,6 +351,22 @@ void Stepper::isr() {
|
351
|
351
|
e_steps[current_block->active_extruder] += motor_direction(E_AXIS) ? -1 : 1;
|
352
|
352
|
}
|
353
|
353
|
#endif //ADVANCE
|
|
354
|
+
|
|
355
|
+ #if ENABLED(LIN_ADVANCE)
|
|
356
|
+ counter_E += current_block->steps[E_AXIS];
|
|
357
|
+ if (counter_E > 0) {
|
|
358
|
+ counter_E -= current_block->step_event_count;
|
|
359
|
+ count_position[_AXIS(E)] += count_direction[_AXIS(E)];
|
|
360
|
+ e_steps[current_block->active_extruder] += motor_direction(E_AXIS) ? -1 : 1;
|
|
361
|
+ }
|
|
362
|
+
|
|
363
|
+ if (current_block->use_advance_lead){
|
|
364
|
+ int delta_adv_steps; //Maybe a char would be enough?
|
|
365
|
+ delta_adv_steps = (((long)extruder_advance_k * current_estep_rate[current_block->active_extruder]) >> 9) - current_adv_steps[current_block->active_extruder];
|
|
366
|
+ e_steps[current_block->active_extruder] += delta_adv_steps;
|
|
367
|
+ current_adv_steps[current_block->active_extruder] += delta_adv_steps;
|
|
368
|
+ }
|
|
369
|
+ #endif //LIN_ADVANCE
|
354
|
370
|
|
355
|
371
|
#define _COUNTER(AXIS) counter_## AXIS
|
356
|
372
|
#define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP
|
|
@@ -363,7 +379,7 @@ void Stepper::isr() {
|
363
|
379
|
STEP_ADD(X);
|
364
|
380
|
STEP_ADD(Y);
|
365
|
381
|
STEP_ADD(Z);
|
366
|
|
- #if DISABLED(ADVANCE)
|
|
382
|
+ #if (DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE))
|
367
|
383
|
STEP_ADD(E);
|
368
|
384
|
#endif
|
369
|
385
|
|
|
@@ -377,7 +393,7 @@ void Stepper::isr() {
|
377
|
393
|
STEP_IF_COUNTER(X);
|
378
|
394
|
STEP_IF_COUNTER(Y);
|
379
|
395
|
STEP_IF_COUNTER(Z);
|
380
|
|
- #if DISABLED(ADVANCE)
|
|
396
|
+ #if (DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE))
|
381
|
397
|
STEP_IF_COUNTER(E);
|
382
|
398
|
#endif
|
383
|
399
|
|
|
@@ -398,6 +414,12 @@ void Stepper::isr() {
|
398
|
414
|
timer = calc_timer(acc_step_rate);
|
399
|
415
|
OCR1A = timer;
|
400
|
416
|
acceleration_time += timer;
|
|
417
|
+
|
|
418
|
+ #if ENABLED(LIN_ADVANCE)
|
|
419
|
+ if (current_block->use_advance_lead){
|
|
420
|
+ current_estep_rate[current_block->active_extruder] = ((unsigned long)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
|
|
421
|
+ }
|
|
422
|
+ #endif
|
401
|
423
|
|
402
|
424
|
#if ENABLED(ADVANCE)
|
403
|
425
|
|
|
@@ -424,6 +446,12 @@ void Stepper::isr() {
|
424
|
446
|
timer = calc_timer(step_rate);
|
425
|
447
|
OCR1A = timer;
|
426
|
448
|
deceleration_time += timer;
|
|
449
|
+
|
|
450
|
+ #if ENABLED(LIN_ADVANCE)
|
|
451
|
+ if (current_block->use_advance_lead){
|
|
452
|
+ current_estep_rate[current_block->active_extruder] = ((unsigned long)step_rate * current_block->e_speed_multiplier8) >> 8;
|
|
453
|
+ }
|
|
454
|
+ #endif
|
427
|
455
|
|
428
|
456
|
#if ENABLED(ADVANCE)
|
429
|
457
|
advance -= advance_rate * step_loops;
|
|
@@ -436,6 +464,12 @@ void Stepper::isr() {
|
436
|
464
|
#endif //ADVANCE
|
437
|
465
|
}
|
438
|
466
|
else {
|
|
467
|
+ #ifdef LIN_ADVANCE
|
|
468
|
+ if (current_block->use_advance_lead){
|
|
469
|
+ current_estep_rate[current_block->active_extruder] = final_estep_rate;
|
|
470
|
+ }
|
|
471
|
+ #endif
|
|
472
|
+
|
439
|
473
|
OCR1A = OCR1A_nominal;
|
440
|
474
|
// ensure we're running at the correct step rate, even if we just came off an acceleration
|
441
|
475
|
step_loops = step_loops_nominal;
|
|
@@ -491,6 +525,55 @@ void Stepper::isr() {
|
491
|
525
|
|
492
|
526
|
#endif // ADVANCE
|
493
|
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
|
+ }
|
|
551
|
+
|
|
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
|
|
576
|
+
|
494
|
577
|
void Stepper::init() {
|
495
|
578
|
|
496
|
579
|
digipot_init(); //Initialize Digipot Motor Current
|
|
@@ -655,6 +738,18 @@ void Stepper::init() {
|
655
|
738
|
OCR1A = 0x4000;
|
656
|
739
|
TCNT1 = 0;
|
657
|
740
|
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);
|
|
750
|
+ #endif
|
|
751
|
+ SBI(TIMSK0, OCIE0A);
|
|
752
|
+ #endif //LIN_ADVANCE
|
658
|
753
|
|
659
|
754
|
#if ENABLED(ADVANCE)
|
660
|
755
|
#if defined(TCCR0A) && defined(WGM01)
|
|
@@ -1040,3 +1135,17 @@ void Stepper::microstep_readings() {
|
1040
|
1135
|
SERIAL_PROTOCOLLN(digitalRead(E1_MS2_PIN));
|
1041
|
1136
|
#endif
|
1042
|
1137
|
}
|
|
1138
|
+
|
|
1139
|
+#if ENABLED(LIN_ADVANCE)
|
|
1140
|
+ void Stepper::advance_M905() {
|
|
1141
|
+ if (code_seen('K')) extruder_advance_k = code_value();
|
|
1142
|
+ SERIAL_ECHO_START;
|
|
1143
|
+ SERIAL_ECHOPGM("Advance factor:");
|
|
1144
|
+ SERIAL_CHAR(' ');
|
|
1145
|
+ SERIAL_ECHOLN(extruder_advance_k);
|
|
1146
|
+ }
|
|
1147
|
+
|
|
1148
|
+ int Stepper::get_advance_k(){
|
|
1149
|
+ return extruder_advance_k;
|
|
1150
|
+ }
|
|
1151
|
+#endif
|