|
@@ -46,7 +46,7 @@ block_t *current_block; // A pointer to the block currently being traced
|
46
|
46
|
|
47
|
47
|
// Variables used by The Stepper Driver Interrupt
|
48
|
48
|
static unsigned char out_bits; // The next stepping-bits to be output
|
49
|
|
-static unsigned int cleaning_buffer_counter;
|
|
49
|
+static unsigned int cleaning_buffer_counter;
|
50
|
50
|
|
51
|
51
|
#ifdef Z_DUAL_ENDSTOPS
|
52
|
52
|
static bool performing_homing = false,
|
|
@@ -285,8 +285,8 @@ void checkHitEndstops() {
|
285
|
285
|
}
|
286
|
286
|
#ifdef Z_PROBE_ENDSTOP
|
287
|
287
|
if (endstop_z_probe_hit) {
|
288
|
|
- SERIAL_ECHOPAIR(" Z_PROBE:", (float)endstops_trigsteps[Z_AXIS] / axis_steps_per_unit[Z_AXIS]);
|
289
|
|
- LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "ZP");
|
|
288
|
+ SERIAL_ECHOPAIR(" Z_PROBE:", (float)endstops_trigsteps[Z_AXIS] / axis_steps_per_unit[Z_AXIS]);
|
|
289
|
+ LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "ZP");
|
290
|
290
|
}
|
291
|
291
|
#endif
|
292
|
292
|
SERIAL_EOL;
|
|
@@ -411,7 +411,7 @@ ISR(TIMER1_COMPA_vect) {
|
411
|
411
|
OCR1A = 200;
|
412
|
412
|
return;
|
413
|
413
|
}
|
414
|
|
-
|
|
414
|
+
|
415
|
415
|
// If there is no current block, attempt to pop one from the buffer
|
416
|
416
|
if (!current_block) {
|
417
|
417
|
// Anything in the buffer?
|
|
@@ -463,14 +463,22 @@ ISR(TIMER1_COMPA_vect) {
|
463
|
463
|
count_direction[Y_AXIS] = 1;
|
464
|
464
|
}
|
465
|
465
|
|
|
466
|
+ #define _ENDSTOP(axis, minmax) axis ##_## minmax ##_endstop
|
|
467
|
+ #define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
|
|
468
|
+ #define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
|
|
469
|
+ #define _OLD_ENDSTOP(axis, minmax) old_## axis ##_## minmax ##_endstop
|
|
470
|
+ #define _AXIS(AXIS) AXIS ##_AXIS
|
|
471
|
+ #define _ENDSTOP_HIT(axis) endstop_## axis ##_hit
|
|
472
|
+
|
466
|
473
|
#define UPDATE_ENDSTOP(axis,AXIS,minmax,MINMAX) \
|
467
|
|
- bool axis ##_## minmax ##_endstop = (READ(AXIS ##_## MINMAX ##_PIN) != AXIS ##_## MINMAX ##_ENDSTOP_INVERTING); \
|
468
|
|
- if (axis ##_## minmax ##_endstop && old_## axis ##_## minmax ##_endstop && (current_block->steps[AXIS ##_AXIS] > 0)) { \
|
469
|
|
- endstops_trigsteps[AXIS ##_AXIS] = count_position[AXIS ##_AXIS]; \
|
470
|
|
- endstop_## axis ##_hit = true; \
|
|
474
|
+ bool _ENDSTOP(axis, minmax) = (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)); \
|
|
475
|
+ if (_ENDSTOP(axis, minmax) && _OLD_ENDSTOP(axis, minmax) && (current_block->steps[_AXIS(AXIS)] > 0)) { \
|
|
476
|
+ endstops_trigsteps[_AXIS(AXIS)] = count_position[_AXIS(AXIS)]; \
|
|
477
|
+ _ENDSTOP_HIT(axis) = true; \
|
471
|
478
|
step_events_completed = current_block->step_event_count; \
|
472
|
479
|
} \
|
473
|
|
- old_## axis ##_## minmax ##_endstop = axis ##_## minmax ##_endstop;
|
|
480
|
+ _OLD_ENDSTOP(axis, minmax) = _ENDSTOP(axis, minmax);
|
|
481
|
+
|
474
|
482
|
|
475
|
483
|
// Check X and Y endstops
|
476
|
484
|
if (check_endstops) {
|
|
@@ -486,7 +494,7 @@ ISR(TIMER1_COMPA_vect) {
|
486
|
494
|
#ifdef DUAL_X_CARRIAGE
|
487
|
495
|
// with 2 x-carriages, endstops are only checked in the homing direction for the active extruder
|
488
|
496
|
if ((current_block->active_extruder == 0 && X_HOME_DIR == -1) || (current_block->active_extruder != 0 && X2_HOME_DIR == -1))
|
489
|
|
- #endif
|
|
497
|
+ #endif
|
490
|
498
|
{
|
491
|
499
|
#if HAS_X_MIN
|
492
|
500
|
UPDATE_ENDSTOP(x, X, min, MIN);
|
|
@@ -572,14 +580,14 @@ ISR(TIMER1_COMPA_vect) {
|
572
|
580
|
z_probe_endstop=(READ(Z_PROBE_PIN) != Z_PROBE_ENDSTOP_INVERTING);
|
573
|
581
|
if(z_probe_endstop && old_z_probe_endstop)
|
574
|
582
|
{
|
575
|
|
- endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
576
|
|
- endstop_z_probe_hit=true;
|
|
583
|
+ endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
|
584
|
+ endstop_z_probe_hit=true;
|
577
|
585
|
|
578
|
|
-// if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true");
|
|
586
|
+// if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true");
|
579
|
587
|
}
|
580
|
588
|
old_z_probe_endstop = z_probe_endstop;
|
581
|
589
|
#endif
|
582
|
|
-
|
|
590
|
+
|
583
|
591
|
} // check_endstops
|
584
|
592
|
|
585
|
593
|
}
|
|
@@ -625,15 +633,15 @@ ISR(TIMER1_COMPA_vect) {
|
625
|
633
|
#endif // !Z_DUAL_ENDSTOPS
|
626
|
634
|
|
627
|
635
|
#endif // Z_MAX_PIN
|
628
|
|
-
|
|
636
|
+
|
629
|
637
|
#ifdef Z_PROBE_ENDSTOP
|
630
|
638
|
UPDATE_ENDSTOP(z, Z, probe, PROBE);
|
631
|
639
|
z_probe_endstop=(READ(Z_PROBE_PIN) != Z_PROBE_ENDSTOP_INVERTING);
|
632
|
640
|
if(z_probe_endstop && old_z_probe_endstop)
|
633
|
641
|
{
|
634
|
|
- endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
635
|
|
- endstop_z_probe_hit=true;
|
636
|
|
-// if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true");
|
|
642
|
+ endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
|
643
|
+ endstop_z_probe_hit=true;
|
|
644
|
+// if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true");
|
637
|
645
|
}
|
638
|
646
|
old_z_probe_endstop = z_probe_endstop;
|
639
|
647
|
#endif
|
|
@@ -667,6 +675,11 @@ ISR(TIMER1_COMPA_vect) {
|
667
|
675
|
}
|
668
|
676
|
#endif //ADVANCE
|
669
|
677
|
|
|
678
|
+ #define _COUNTER(axis) counter_## axis
|
|
679
|
+ #define _WRITE_STEP(AXIS, HIGHLOW) AXIS ##_STEP_WRITE(HIGHLOW)
|
|
680
|
+ #define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP
|
|
681
|
+ #define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN
|
|
682
|
+
|
670
|
683
|
#ifdef CONFIG_STEPPERS_TOSHIBA
|
671
|
684
|
/**
|
672
|
685
|
* The Toshiba stepper controller require much longer pulses.
|
|
@@ -675,8 +688,8 @@ ISR(TIMER1_COMPA_vect) {
|
675
|
688
|
* lag to allow it work with without needing NOPs
|
676
|
689
|
*/
|
677
|
690
|
#define STEP_ADD(axis, AXIS) \
|
678
|
|
- counter_## axis += current_block->steps[AXIS ##_AXIS]; \
|
679
|
|
- if (counter_## axis > 0) { AXIS ##_STEP_WRITE(HIGH); }
|
|
691
|
+ _COUNTER(axis) += current_block->steps[_AXIS(AXIS)]; \
|
|
692
|
+ if (_COUNTER(axis) > 0) { _WRITE_STEP(AXIS, HIGH); }
|
680
|
693
|
STEP_ADD(x,X);
|
681
|
694
|
STEP_ADD(y,Y);
|
682
|
695
|
STEP_ADD(z,Z);
|
|
@@ -685,10 +698,10 @@ ISR(TIMER1_COMPA_vect) {
|
685
|
698
|
#endif
|
686
|
699
|
|
687
|
700
|
#define STEP_IF_COUNTER(axis, AXIS) \
|
688
|
|
- if (counter_## axis > 0) { \
|
689
|
|
- counter_## axis -= current_block->step_event_count; \
|
690
|
|
- count_position[AXIS ##_AXIS] += count_direction[AXIS ##_AXIS]; \
|
691
|
|
- AXIS ##_STEP_WRITE(LOW); \
|
|
701
|
+ if (_COUNTER(axis) > 0) { \
|
|
702
|
+ _COUNTER(axis) -= current_block->step_event_count; \
|
|
703
|
+ count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \
|
|
704
|
+ _WRITE_STEP(AXIS, LOW); \
|
692
|
705
|
}
|
693
|
706
|
|
694
|
707
|
STEP_IF_COUNTER(x, X);
|
|
@@ -701,12 +714,12 @@ ISR(TIMER1_COMPA_vect) {
|
701
|
714
|
#else // !CONFIG_STEPPERS_TOSHIBA
|
702
|
715
|
|
703
|
716
|
#define APPLY_MOVEMENT(axis, AXIS) \
|
704
|
|
- counter_## axis += current_block->steps[AXIS ##_AXIS]; \
|
705
|
|
- if (counter_## axis > 0) { \
|
706
|
|
- AXIS ##_APPLY_STEP(!INVERT_## AXIS ##_STEP_PIN,0); \
|
707
|
|
- counter_## axis -= current_block->step_event_count; \
|
708
|
|
- count_position[AXIS ##_AXIS] += count_direction[AXIS ##_AXIS]; \
|
709
|
|
- AXIS ##_APPLY_STEP(INVERT_## AXIS ##_STEP_PIN,0); \
|
|
717
|
+ _COUNTER(axis) += current_block->steps[_AXIS(AXIS)]; \
|
|
718
|
+ if (_COUNTER(axis) > 0) { \
|
|
719
|
+ _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS),0); \
|
|
720
|
+ _COUNTER(axis) -= current_block->step_event_count; \
|
|
721
|
+ count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \
|
|
722
|
+ _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \
|
710
|
723
|
}
|
711
|
724
|
|
712
|
725
|
APPLY_MOVEMENT(x, X);
|
|
@@ -874,7 +887,7 @@ void st_init() {
|
874
|
887
|
#ifdef HAVE_L6470DRIVER
|
875
|
888
|
L6470_init();
|
876
|
889
|
#endif
|
877
|
|
-
|
|
890
|
+
|
878
|
891
|
// Initialize Dir Pins
|
879
|
892
|
#if HAS_X_DIR
|
880
|
893
|
X_DIR_INIT;
|
|
@@ -920,11 +933,11 @@ void st_init() {
|
920
|
933
|
#if HAS_Y_ENABLE
|
921
|
934
|
Y_ENABLE_INIT;
|
922
|
935
|
if (!Y_ENABLE_ON) Y_ENABLE_WRITE(HIGH);
|
923
|
|
-
|
924
|
|
- #if defined(Y_DUAL_STEPPER_DRIVERS) && HAS_Y2_ENABLE
|
925
|
|
- Y2_ENABLE_INIT;
|
926
|
|
- if (!Y_ENABLE_ON) Y2_ENABLE_WRITE(HIGH);
|
927
|
|
- #endif
|
|
936
|
+
|
|
937
|
+ #if defined(Y_DUAL_STEPPER_DRIVERS) && HAS_Y2_ENABLE
|
|
938
|
+ Y2_ENABLE_INIT;
|
|
939
|
+ if (!Y_ENABLE_ON) Y2_ENABLE_WRITE(HIGH);
|
|
940
|
+ #endif
|
928
|
941
|
#endif
|
929
|
942
|
#if HAS_Z_ENABLE
|
930
|
943
|
Z_ENABLE_INIT;
|
|
@@ -1001,8 +1014,8 @@ void st_init() {
|
1001
|
1014
|
#ifdef ENDSTOPPULLUP_ZMAX
|
1002
|
1015
|
WRITE(Z2_MAX_PIN,HIGH);
|
1003
|
1016
|
#endif
|
1004
|
|
- #endif
|
1005
|
|
-
|
|
1017
|
+ #endif
|
|
1018
|
+
|
1006
|
1019
|
#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.
|
1007
|
1020
|
SET_INPUT(Z_PROBE_PIN);
|
1008
|
1021
|
#ifdef ENDSTOPPULLUP_ZPROBE
|
|
@@ -1010,10 +1023,13 @@ void st_init() {
|
1010
|
1023
|
#endif
|
1011
|
1024
|
#endif
|
1012
|
1025
|
|
|
1026
|
+ #define _STEP_INIT(AXIS) AXIS ##_STEP_INIT
|
|
1027
|
+ #define _DISABLE(axis) disable_## axis()
|
|
1028
|
+
|
1013
|
1029
|
#define AXIS_INIT(axis, AXIS, PIN) \
|
1014
|
|
- AXIS ##_STEP_INIT; \
|
1015
|
|
- AXIS ##_STEP_WRITE(INVERT_## PIN ##_STEP_PIN); \
|
1016
|
|
- disable_## axis()
|
|
1030
|
+ _STEP_INIT(AXIS); \
|
|
1031
|
+ _WRITE_STEP(AXIS, _INVERT_STEP_PIN(PIN)); \
|
|
1032
|
+ _DISABLE(axis)
|
1017
|
1033
|
|
1018
|
1034
|
#define E_AXIS_INIT(NUM) AXIS_INIT(e## NUM, E## NUM, E)
|
1019
|
1035
|
|
|
@@ -1146,14 +1162,19 @@ void quickStop() {
|
1146
|
1162
|
// No other ISR should ever interrupt this!
|
1147
|
1163
|
void babystep(const uint8_t axis, const bool direction) {
|
1148
|
1164
|
|
|
1165
|
+ #define _ENABLE(axis) enable_## axis()
|
|
1166
|
+ #define _READ_DIR(AXIS) AXIS ##_DIR_READ
|
|
1167
|
+ #define _INVERT_DIR(AXIS) INVERT_## AXIS ##_DIR
|
|
1168
|
+ #define _APPLY_DIR(AXIS, INVERT) AXIS ##_APPLY_DIR(INVERT, true)
|
|
1169
|
+
|
1149
|
1170
|
#define BABYSTEP_AXIS(axis, AXIS, INVERT) { \
|
1150
|
|
- enable_## axis(); \
|
1151
|
|
- uint8_t old_pin = AXIS ##_DIR_READ; \
|
1152
|
|
- AXIS ##_APPLY_DIR(INVERT_## AXIS ##_DIR^direction^INVERT, true); \
|
1153
|
|
- AXIS ##_APPLY_STEP(!INVERT_## AXIS ##_STEP_PIN, true); \
|
|
1171
|
+ _ENABLE(axis); \
|
|
1172
|
+ uint8_t old_pin = _READ_DIR(AXIS); \
|
|
1173
|
+ _APPLY_DIR(AXIS, _INVERT_DIR(AXIS)^direction^INVERT); \
|
|
1174
|
+ _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS), true); \
|
1154
|
1175
|
delayMicroseconds(2); \
|
1155
|
|
- AXIS ##_APPLY_STEP(INVERT_## AXIS ##_STEP_PIN, true); \
|
1156
|
|
- AXIS ##_APPLY_DIR(old_pin, true); \
|
|
1176
|
+ _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS), true); \
|
|
1177
|
+ _APPLY_DIR(AXIS, old_pin); \
|
1157
|
1178
|
}
|
1158
|
1179
|
|
1159
|
1180
|
switch(axis) {
|
|
@@ -1165,7 +1186,7 @@ void quickStop() {
|
1165
|
1186
|
case Y_AXIS:
|
1166
|
1187
|
BABYSTEP_AXIS(y, Y, false);
|
1167
|
1188
|
break;
|
1168
|
|
-
|
|
1189
|
+
|
1169
|
1190
|
case Z_AXIS: {
|
1170
|
1191
|
|
1171
|
1192
|
#ifndef DELTA
|
|
@@ -1202,7 +1223,7 @@ void quickStop() {
|
1202
|
1223
|
#endif
|
1203
|
1224
|
|
1204
|
1225
|
} break;
|
1205
|
|
-
|
|
1226
|
+
|
1206
|
1227
|
default: break;
|
1207
|
1228
|
}
|
1208
|
1229
|
}
|
|
@@ -1266,7 +1287,7 @@ void microstep_init() {
|
1266
|
1287
|
|
1267
|
1288
|
#if HAS_MICROSTEPS
|
1268
|
1289
|
pinMode(X_MS1_PIN,OUTPUT);
|
1269
|
|
- pinMode(X_MS2_PIN,OUTPUT);
|
|
1290
|
+ pinMode(X_MS2_PIN,OUTPUT);
|
1270
|
1291
|
pinMode(Y_MS1_PIN,OUTPUT);
|
1271
|
1292
|
pinMode(Y_MS2_PIN,OUTPUT);
|
1272
|
1293
|
pinMode(Z_MS1_PIN,OUTPUT);
|