Browse Source

rework out_bits

wurstnase 9 years ago
parent
commit
21ff773832
1 changed files with 84 additions and 82 deletions
  1. 84
    82
      Marlin/stepper.cpp

+ 84
- 82
Marlin/stepper.cpp View File

46
 //static makes it impossible to be called from outside of this file by extern.!
46
 //static makes it impossible to be called from outside of this file by extern.!
47
 
47
 
48
 // Variables used by The Stepper Driver Interrupt
48
 // Variables used by The Stepper Driver Interrupt
49
-static unsigned char out_bits;        // The next stepping-bits to be output
49
+static unsigned char out_bits = 0;        // The next stepping-bits to be output
50
 static unsigned int cleaning_buffer_counter;
50
 static unsigned int cleaning_buffer_counter;
51
 
51
 
52
 #ifdef Z_DUAL_ENDSTOPS
52
 #ifdef Z_DUAL_ENDSTOPS
364
   return timer;
364
   return timer;
365
 }
365
 }
366
 
366
 
367
+// set the stepper direction of each axis
368
+void set_stepper_direction() {
369
+  
370
+  // Set the direction bits (X_AXIS=A_AXIS and Y_AXIS=B_AXIS for COREXY)
371
+  if (TEST(out_bits, X_AXIS)) {
372
+    X_APPLY_DIR(INVERT_X_DIR,0);
373
+    count_direction[X_AXIS] = -1;
374
+  }
375
+  else {
376
+    X_APPLY_DIR(!INVERT_X_DIR,0);
377
+    count_direction[X_AXIS] = 1;
378
+  }
379
+
380
+  if (TEST(out_bits, Y_AXIS)) {
381
+    Y_APPLY_DIR(INVERT_Y_DIR,0);
382
+    count_direction[Y_AXIS] = -1;
383
+  }
384
+  else {
385
+    Y_APPLY_DIR(!INVERT_Y_DIR,0);
386
+    count_direction[Y_AXIS] = 1;
387
+  }
388
+  
389
+  if (TEST(out_bits, Z_AXIS)) {
390
+    Z_APPLY_DIR(INVERT_Z_DIR,0);
391
+    count_direction[Z_AXIS] = -1;
392
+  }
393
+  else {
394
+    Z_APPLY_DIR(!INVERT_Z_DIR,0);
395
+    count_direction[Z_AXIS] = 1;
396
+  }
397
+  
398
+  #ifndef ADVANCE
399
+    if (TEST(out_bits, E_AXIS)) {
400
+      REV_E_DIR();
401
+      count_direction[E_AXIS] = -1;
402
+    }
403
+    else {
404
+      NORM_E_DIR();
405
+      count_direction[E_AXIS] = 1;
406
+    }
407
+  #endif //!ADVANCE
408
+}
409
+
367
 // Initializes the trapezoid generator from the current block. Called whenever a new
410
 // Initializes the trapezoid generator from the current block. Called whenever a new
368
 // block begins.
411
 // block begins.
369
 FORCE_INLINE void trapezoid_generator_reset() {
412
 FORCE_INLINE void trapezoid_generator_reset() {
413
+
414
+  if (current_block->direction_bits != out_bits) {
415
+    out_bits = current_block->direction_bits;
416
+    set_stepper_direction();
417
+  }
418
+  
370
   #ifdef ADVANCE
419
   #ifdef ADVANCE
371
     advance = current_block->initial_advance;
420
     advance = current_block->initial_advance;
372
     final_advance = current_block->final_advance;
421
     final_advance = current_block->final_advance;
439
   }
488
   }
440
 
489
 
441
   if (current_block != NULL) {
490
   if (current_block != NULL) {
442
-    // Set directions TO DO This should be done once during init of trapezoid. Endstops -> interrupt
443
-    out_bits = current_block->direction_bits;
444
-
445
-    // Set the direction bits (X_AXIS=A_AXIS and Y_AXIS=B_AXIS for COREXY)
446
-    if (TEST(out_bits, X_AXIS)) {
447
-      X_APPLY_DIR(INVERT_X_DIR,0);
448
-      count_direction[X_AXIS] = -1;
449
-    }
450
-    else {
451
-      X_APPLY_DIR(!INVERT_X_DIR,0);
452
-      count_direction[X_AXIS] = 1;
453
-    }
454
-
455
-    if (TEST(out_bits, Y_AXIS)) {
456
-      Y_APPLY_DIR(INVERT_Y_DIR,0);
457
-      count_direction[Y_AXIS] = -1;
458
-    }
459
-    else {
460
-      Y_APPLY_DIR(!INVERT_Y_DIR,0);
461
-      count_direction[Y_AXIS] = 1;
462
-    }
463
-
464
-    #define _ENDSTOP(axis, minmax) axis ##_## minmax ##_endstop
465
-    #define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
466
-    #define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
467
-    #define _OLD_ENDSTOP(axis, minmax) old_## axis ##_## minmax ##_endstop
468
-    #define _AXIS(AXIS) AXIS ##_AXIS
469
-    #define _HIT_BIT(AXIS) AXIS ##_MIN
470
-    #define _ENDSTOP_HIT(AXIS) endstop_hit_bits |= BIT(_HIT_BIT(AXIS))
471
-
472
-    #define UPDATE_ENDSTOP(axis,AXIS,minmax,MINMAX) \
473
-      bool _ENDSTOP(axis, minmax) = (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)); \
474
-      if (_ENDSTOP(axis, minmax) && _OLD_ENDSTOP(axis, minmax) && (current_block->steps[_AXIS(AXIS)] > 0)) { \
475
-        endstops_trigsteps[_AXIS(AXIS)] = count_position[_AXIS(AXIS)]; \
476
-          _ENDSTOP_HIT(AXIS); \
477
-        step_events_completed = current_block->step_event_count; \
478
-      } \
479
-      _OLD_ENDSTOP(axis, minmax) = _ENDSTOP(axis, minmax);
480
 
491
 
481
-
482
-    // Check X and Y endstops
492
+    // Check endstops
483
     if (check_endstops) {
493
     if (check_endstops) {
494
+      
495
+      #define _ENDSTOP(axis, minmax) axis ##_## minmax ##_endstop
496
+      #define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
497
+      #define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
498
+      #define _OLD_ENDSTOP(axis, minmax) old_## axis ##_## minmax ##_endstop
499
+      #define _AXIS(AXIS) AXIS ##_AXIS
500
+      #define _HIT_BIT(AXIS) AXIS ##_MIN
501
+      #define _ENDSTOP_HIT(AXIS) endstop_hit_bits |= BIT(_HIT_BIT(AXIS))
502
+
503
+      #define UPDATE_ENDSTOP(axis,AXIS,minmax,MINMAX) \
504
+        bool _ENDSTOP(axis, minmax) = (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)); \
505
+        if (_ENDSTOP(axis, minmax) && _OLD_ENDSTOP(axis, minmax) && (current_block->steps[_AXIS(AXIS)] > 0)) { \
506
+          endstops_trigsteps[_AXIS(AXIS)] = count_position[_AXIS(AXIS)]; \
507
+          _ENDSTOP_HIT(AXIS); \
508
+          step_events_completed = current_block->step_event_count; \
509
+        } \
510
+        _OLD_ENDSTOP(axis, minmax) = _ENDSTOP(axis, minmax);
511
+      
484
       #ifdef COREXY
512
       #ifdef COREXY
485
         // Head direction in -X axis for CoreXY bots.
513
         // Head direction in -X axis for CoreXY bots.
486
         // If DeltaX == -DeltaY, the movement is only in Y axis
514
         // If DeltaX == -DeltaY, the movement is only in Y axis
533
       #ifdef COREXY
561
       #ifdef COREXY
534
         }
562
         }
535
       #endif
563
       #endif
536
-    }
537
-
538
-    if (TEST(out_bits, Z_AXIS)) {   // -direction
539
-
540
-      Z_APPLY_DIR(INVERT_Z_DIR,0);
541
-      count_direction[Z_AXIS] = -1;
542
-
543
-      if (check_endstops) {
544
-
564
+      if (TEST(out_bits, Z_AXIS)) { // z -direction
545
         #if HAS_Z_MIN
565
         #if HAS_Z_MIN
546
 
566
 
547
           #ifdef Z_DUAL_ENDSTOPS
567
           #ifdef Z_DUAL_ENDSTOPS
581
           {
601
           {
582
             endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
602
             endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
583
             endstop_hit_bits |= BIT(Z_PROBE);
603
             endstop_hit_bits |= BIT(Z_PROBE);
584
-
585
-//            if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true");
604
+  //        if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true");
586
           }
605
           }
587
           old_z_probe_endstop = z_probe_endstop;
606
           old_z_probe_endstop = z_probe_endstop;
588
         #endif
607
         #endif
589
-
590
-      } // check_endstops
591
-
592
-    }
593
-    else { // +direction
594
-
595
-      Z_APPLY_DIR(!INVERT_Z_DIR,0);
596
-      count_direction[Z_AXIS] = 1;
597
-
598
-      if (check_endstops) {
599
-
608
+      }
609
+      else { // z +direction
600
         #if HAS_Z_MAX
610
         #if HAS_Z_MAX
601
 
611
 
602
           #ifdef Z_DUAL_ENDSTOPS
612
           #ifdef Z_DUAL_ENDSTOPS
632
           #endif // !Z_DUAL_ENDSTOPS
642
           #endif // !Z_DUAL_ENDSTOPS
633
 
643
 
634
         #endif // Z_MAX_PIN
644
         #endif // Z_MAX_PIN
635
-
645
+        
636
         #ifdef Z_PROBE_ENDSTOP
646
         #ifdef Z_PROBE_ENDSTOP
637
           UPDATE_ENDSTOP(z, Z, probe, PROBE);
647
           UPDATE_ENDSTOP(z, Z, probe, PROBE);
638
           z_probe_endstop=(READ(Z_PROBE_PIN) != Z_PROBE_ENDSTOP_INVERTING);
648
           z_probe_endstop=(READ(Z_PROBE_PIN) != Z_PROBE_ENDSTOP_INVERTING);
640
           {
650
           {
641
             endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
651
             endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
642
             endstop_hit_bits |= BIT(Z_PROBE);
652
             endstop_hit_bits |= BIT(Z_PROBE);
643
-//            if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true");
653
+//          if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true");
644
           }
654
           }
645
           old_z_probe_endstop = z_probe_endstop;
655
           old_z_probe_endstop = z_probe_endstop;
646
         #endif
656
         #endif
657
+      }
647
 
658
 
648
-      } // check_endstops
659
+    }
649
 
660
 
650
-    } // +direction
651
 
661
 
652
-    #ifndef ADVANCE
653
-      if (TEST(out_bits, E_AXIS)) {  // -direction
654
-        REV_E_DIR();
655
-        count_direction[E_AXIS] = -1;
656
-      }
657
-      else { // +direction
658
-        NORM_E_DIR();
659
-        count_direction[E_AXIS] = 1;
660
-      }
661
-    #endif //!ADVANCE
662
 
662
 
663
     // Take multiple steps per interrupt (For high speed moves)
663
     // Take multiple steps per interrupt (For high speed moves)
664
     for (int8_t i = 0; i < step_loops; i++) {
664
     for (int8_t i = 0; i < step_loops; i++) {
989
     #endif
989
     #endif
990
   #endif
990
   #endif
991
 
991
 
992
-#if (defined(Z_PROBE_PIN) && Z_PROBE_PIN >= 0) && defined(Z_PROBE_ENDSTOP) // Check for Z_PROBE_ENDSTOP so we don't pull a pin high unless it's to be used.
993
-  SET_INPUT(Z_PROBE_PIN);
994
-  #ifdef ENDSTOPPULLUP_ZPROBE
995
-    WRITE(Z_PROBE_PIN,HIGH);
992
+  #if (defined(Z_PROBE_PIN) && Z_PROBE_PIN >= 0) && defined(Z_PROBE_ENDSTOP) // Check for Z_PROBE_ENDSTOP so we don't pull a pin high unless it's to be used.
993
+    SET_INPUT(Z_PROBE_PIN);
994
+    #ifdef ENDSTOPPULLUP_ZPROBE
995
+      WRITE(Z_PROBE_PIN,HIGH);
996
+    #endif
996
   #endif
997
   #endif
997
-#endif
998
 
998
 
999
   #define _STEP_INIT(AXIS) AXIS ##_STEP_INIT
999
   #define _STEP_INIT(AXIS) AXIS ##_STEP_INIT
1000
   #define _WRITE_STEP(AXIS, HIGHLOW) AXIS ##_STEP_WRITE(HIGHLOW)
1000
   #define _WRITE_STEP(AXIS, HIGHLOW) AXIS ##_STEP_WRITE(HIGHLOW)
1073
 
1073
 
1074
   enable_endstops(true); // Start with endstops active. After homing they can be disabled
1074
   enable_endstops(true); // Start with endstops active. After homing they can be disabled
1075
   sei();
1075
   sei();
1076
+  
1077
+  set_stepper_direction(); // Init directions to out_bits = 0
1076
 }
1078
 }
1077
 
1079
 
1078
 
1080
 

Loading…
Cancel
Save