Просмотр исходного кода

Merge pull request #5184 from AnHardt/endstop_interrupts

Introduce endstop interrupts
Scott Lahteine 8 лет назад
Родитель
Сommit
832fe284b4
26 измененных файлов: 329 добавлений и 1 удалений
  1. 3
    0
      Marlin/Configuration.h
  2. 7
    0
      Marlin/Marlin_main.cpp
  3. 211
    0
      Marlin/endstop_interrupts.h
  4. 3
    0
      Marlin/example_configurations/Cartesio/Configuration.h
  5. 3
    0
      Marlin/example_configurations/Felix/Configuration.h
  6. 3
    0
      Marlin/example_configurations/Felix/DUAL/Configuration.h
  7. 3
    0
      Marlin/example_configurations/Hephestos/Configuration.h
  8. 3
    0
      Marlin/example_configurations/Hephestos_2/Configuration.h
  9. 3
    0
      Marlin/example_configurations/K8200/Configuration.h
  10. 3
    0
      Marlin/example_configurations/K8400/Configuration.h
  11. 3
    0
      Marlin/example_configurations/K8400/Dual-head/Configuration.h
  12. 3
    0
      Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h
  13. 3
    0
      Marlin/example_configurations/RigidBot/Configuration.h
  14. 3
    0
      Marlin/example_configurations/SCARA/Configuration.h
  15. 3
    0
      Marlin/example_configurations/TAZ4/Configuration.h
  16. 3
    0
      Marlin/example_configurations/WITBOX/Configuration.h
  17. 3
    0
      Marlin/example_configurations/adafruit/ST7565/Configuration.h
  18. 3
    0
      Marlin/example_configurations/delta/biv2.5/Configuration.h
  19. 3
    0
      Marlin/example_configurations/delta/generic/Configuration.h
  20. 3
    0
      Marlin/example_configurations/delta/kossel_mini/Configuration.h
  21. 3
    0
      Marlin/example_configurations/delta/kossel_pro/Configuration.h
  22. 3
    0
      Marlin/example_configurations/delta/kossel_xl/Configuration.h
  23. 3
    0
      Marlin/example_configurations/makibox/Configuration.h
  24. 3
    0
      Marlin/example_configurations/tvrrug/Round2/Configuration.h
  25. 13
    1
      Marlin/stepper.cpp
  26. 32
    0
      buildroot/share/pin_interrupt_test/pin_interrupt_test.ino

+ 3
- 0
Marlin/Configuration.h Просмотреть файл

@@ -445,6 +445,9 @@
445 445
 #define Z_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
446 446
 #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
447 447
 
448
+// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE.
449
+// Then the function testing the endstops will only be called, if the state of one of the endstops changed.
450
+//#define ENDSTOP_INTERRUPTS_FEATURE
448 451
 
449 452
 //=============================================================================
450 453
 //============================== Movement Settings ============================

+ 7
- 0
Marlin/Marlin_main.cpp Просмотреть файл

@@ -89,6 +89,9 @@
89 89
   #include "twibus.h"
90 90
 #endif
91 91
 
92
+#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
93
+  #include "endstop_interrupts.h"
94
+#endif
92 95
 /**
93 96
  * Look here for descriptions of G-codes:
94 97
  *  - http://linuxcnc.org/handbook/gcode/g-code.html
@@ -10015,6 +10018,10 @@ void setup() {
10015 10018
     i2c.onReceive(i2c_on_receive);
10016 10019
     i2c.onRequest(i2c_on_request);
10017 10020
   #endif
10021
+
10022
+  #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
10023
+    setup_enstop_interrupts();
10024
+  #endif
10018 10025
 }
10019 10026
 
10020 10027
 /**

+ 211
- 0
Marlin/endstop_interrupts.h Просмотреть файл

@@ -0,0 +1,211 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ *  Endstop interrupts
25
+ *  Without endstop interrups the stepper-ISR must always test all endstops when interested in their states (endstops.update()).
26
+ *  Most time the test will result in finding out nothing has changed.
27
+ *  With endstop interrupts endstops.update() is called only when we know that at least one endstop has changed its state.
28
+ *
29
+ *  This can work only if all __used__ endstop pins can provide ether an 'external interrupt' or a 'pin change interrupt'.
30
+ *  You can find out about pins issuing interrupts by running 'pin_interrupt_test.ino' (Marlin\buildroot\share\pin_interrupt_test\pin_interrupt_test.ino)
31
+ */
32
+
33
+ #ifndef _ENDSTOP_INTERRUPTS_H_
34
+   #define _ENDSTOP_INTERRUPTS_H_
35
+
36
+  /**
37
+   * Patch for pins_arduino.h (...\Arduino\hardware\arduino\avr\variants\mega\pins_arduino.h)  
38
+   *
39
+   * These macros for the Arduino MEGA do not include the two connected pins on Port J (D13, D14).
40
+   * So we extend them here because this are the normal pins for Y_MIN and Y_MAX on RAMPS.
41
+   * There are more PCI enabled processor pins on Port J, but they are not connected to Arduino MEGA.
42
+   */
43
+  #if defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_AVR_MEGA)
44
+    #undef  digitalPinToPCICR
45
+    #define digitalPinToPCICR(p)    ( (((p) >= 10) && ((p) <= 15)) || \
46
+                                    (((p) >= 50) && ((p) <= 53)) || \
47
+                                    (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) )
48
+    #undef  digitalPinToPCICRbit
49
+    #define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \
50
+                                    ( (((p) >= 14) && ((p) <= 15)) ? 1 : \
51
+                                    ( (((p) >= 62) && ((p) <= 69)) ? 2 : \
52
+                                    0 ) ) )
53
+    #undef  digitalPinToPCMSK
54
+    #define digitalPinToPCMSK(p)    ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \
55
+                                    ( (((p) >= 14) && ((p) <= 15)) ? (&PCMSK1) : \
56
+                                    ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \
57
+                                    ((uint8_t *)0) ) ) )
58
+    #undef  digitalPinToPCMSKbit
59
+    #define digitalPinToPCMSKbit(p) ( (((p) >= 10) && ((p) <= 13)) ? ((p) - 6) : \
60
+                                    ( ((p) == 14) ? 2 : \
61
+                                    ( ((p) == 15) ? 1 : \
62
+                                    ( ((p) == 50) ? 3 : \
63
+                                    ( ((p) == 51) ? 2 : \
64
+                                    ( ((p) == 52) ? 1 : \
65
+                                    ( ((p) == 53) ? 0 : \
66
+                                    ( (((p) >= 62) && ((p) <= 69)) ? ((p) - 62) : \
67
+                                    0 ) ) ) ) ) ) ) )
68
+  #endif
69
+
70
+  volatile uint8_t e_hit = 0; // Different from 0 when the endstops shall be tested in detail. 
71
+                              // Must be reset to 0 by the test function when the tests are finished.
72
+
73
+  // Install Pin change interrupt for a pin, can be called multiple times
74
+  void pciSetup(byte pin) {
75
+    *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin));  // enable pin
76
+    PCIFR  |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
77
+    PCICR  |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group
78
+  }
79
+
80
+  // This is what is really done inside the interrupts.
81
+  FORCE_INLINE void endstop_ISR_worker( void ) {
82
+    e_hit = 2; // Because the detection of a e-stop hit has a 1 step debouncer it has to be called at least twice.
83
+  }
84
+
85
+  // Use one Routine to handle each group
86
+  // One ISR for all EXT-Interrupts
87
+  void endstop_ISR(void) {
88
+    endstop_ISR_worker();
89
+  }
90
+
91
+  #ifdef PCINT0_vect
92
+    ISR(PCINT0_vect) { // handle pin change interrupt
93
+      endstop_ISR_worker();
94
+    }
95
+  #endif
96
+
97
+  #ifdef PCINT1_vect
98
+    ISR(PCINT1_vect) { // handle pin change interrupt
99
+      endstop_ISR_worker();
100
+    }
101
+  #endif
102
+
103
+  #ifdef PCINT2_vect
104
+    ISR(PCINT2_vect) { // handle pin change interrupt
105
+      endstop_ISR_worker();
106
+    }
107
+  #endif
108
+
109
+  #ifdef PCINT3_vect
110
+    ISR(PCINT3_vect) { // handle pin change interrupt
111
+      endstop_ISR_worker();
112
+    }
113
+  #endif
114
+
115
+  void setup_enstop_interrupts( void ) {
116
+
117
+    #if HAS_X_MAX
118
+      #if (digitalPinToInterrupt(X_MAX_PIN) != NOT_AN_INTERRUPT) // if pin has an external interrupt
119
+        attachInterrupt(digitalPinToInterrupt(X_MAX_PIN), endstop_ISR, CHANGE); // assign it
120
+      #else
121
+        // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
122
+        static_assert(digitalPinToPCICR(X_MAX_PIN) != NULL, "ENDSTOP_INTERRUPT_ERROR"); // if pin has no pin change interrupt - error
123
+        pciSetup(X_MAX_PIN);                                                            // assign it
124
+      #endif
125
+    #endif
126
+
127
+    #if HAS_X_MIN
128
+      #if (digitalPinToInterrupt(X_MIN_PIN) != NOT_AN_INTERRUPT)
129
+        attachInterrupt(digitalPinToInterrupt(X_MIN_PIN), endstop_ISR, CHANGE);
130
+      #else
131
+        // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
132
+        static_assert(digitalPinToPCICR(X_MIN_PIN) != NULL, "ENDSTOP_INTERRUPT_ERROR");
133
+        pciSetup(X_MIN_PIN);
134
+      #endif
135
+    #endif
136
+
137
+    #if HAS_Y_MAX
138
+      #if (digitalPinToInterrupt(Y_MAX_PIN) != NOT_AN_INTERRUPT)
139
+        attachInterrupt(digitalPinToInterrupt(Y_MAX_PIN), endstop_ISR, CHANGE);
140
+      #else
141
+        // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
142
+        static_assert(digitalPinToPCICR(Y_MAX_PIN) != NULL, "ENDSTOP_INTERRUPT_ERROR");
143
+        pciSetup(Y_MAX_PIN);
144
+      #endif
145
+    #endif
146
+
147
+    #if HAS_Y_MIN
148
+      #if (digitalPinToInterrupt(Y_MIN_PIN) != NOT_AN_INTERRUPT)
149
+        attachInterrupt(digitalPinToInterrupt(Y_MIN_PIN), endstop_ISR, CHANGE);
150
+      #else
151
+        // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
152
+        static_assert(digitalPinToPCICR(Y_MIN_PIN) != NULL, "ENDSTOP_INTERRUPT_ERROR");
153
+        pciSetup(Y_MIN_PIN);
154
+      #endif
155
+    #endif
156
+
157
+    #if HAS_Z_MAX
158
+      #if (digitalPinToInterrupt(Z_MAX_PIN) != NOT_AN_INTERRUPT)
159
+        attachInterrupt(digitalPinToInterrupt(Z_MAX_PIN), endstop_ISR, CHANGE);
160
+      #else
161
+        // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
162
+        static_assert(digitalPinToPCICR(Z_MAX_PIN) != NULL, "ENDSTOP_INTERRUPT_ERROR");
163
+        pciSetup(Z_MAX_PIN);
164
+      #endif
165
+    #endif
166
+
167
+    #if HAS_Z_MIN
168
+      #if (digitalPinToInterrupt(Z_MIN_PIN) != NOT_AN_INTERRUPT)
169
+        attachInterrupt(digitalPinToInterrupt(Z_MIN_PIN), endstop_ISR, CHANGE);
170
+      #else
171
+        // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
172
+        static_assert(digitalPinToPCICR(Z_MIN_PIN) != NULL, "ENDSTOP_INTERRUPT_ERROR");
173
+        pciSetup(Z_MIN_PIN);
174
+      #endif
175
+    #endif
176
+
177
+    #if HAS_Z2_MAX
178
+      #if (digitalPinToInterrupt(Z2_MAX_PIN) != NOT_AN_INTERRUPT)
179
+        attachInterrupt(digitalPinToInterrupt(Z2_MAX_PIN), endstop_ISR, CHANGE);
180
+      #else
181
+        // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
182
+        static_assert(digitalPinToPCICR(Z2_MAX_PIN) != NULL, "ENDSTOP_INTERRUPT_ERROR");
183
+        pciSetup(Z2_MAX_PIN);
184
+      #endif
185
+    #endif
186
+
187
+    #if HAS_Z2_MIN
188
+      #if (digitalPinToInterrupt(Z2_MIN_PIN) != NOT_AN_INTERRUPT)
189
+        attachInterrupt(digitalPinToInterrupt(Z2_MIN_PIN), endstop_ISR, CHANGE);
190
+      #else
191
+        // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
192
+        static_assert(digitalPinToPCICR(Z2_MIN_PIN) != NULL, "ENDSTOP_INTERRUPT_ERROR");
193
+        pciSetup(Z2_MIN_PIN);
194
+      #endif
195
+    #endif
196
+
197
+    #if HAS_Z_MIN_PROBE_PIN
198
+      #if (digitalPinToInterrupt(Z_MIN_PROBE_PIN) != NOT_AN_INTERRUPT)
199
+        attachInterrupt(digitalPinToInterrupt(Z_MIN_PROBE_PIN), endstop_ISR, CHANGE);
200
+      #else
201
+        // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
202
+        static_assert(digitalPinToPCICR(Z_MIN_PROBE_PIN) != NULL, "ENDSTOP_INTERRUPT_ERROR");
203
+        pciSetup(Z_MIN_PROBE_PIN);
204
+      #endif
205
+    #endif
206
+
207
+    // When we arive here without error each pin has ether a EXT-interrupt or a PCI.
208
+  }
209
+
210
+
211
+#endif //_ENDSTOP_INTERRUPTS_H_

+ 3
- 0
Marlin/example_configurations/Cartesio/Configuration.h Просмотреть файл

@@ -445,6 +445,9 @@
445 445
 #define Z_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
446 446
 #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
447 447
 
448
+// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE.
449
+// Then the function testing the endstops will only be called, if the state of one of the endstops changed.
450
+//#define ENDSTOP_INTERRUPTS_FEATURE
448 451
 
449 452
 //=============================================================================
450 453
 //============================== Movement Settings ============================

+ 3
- 0
Marlin/example_configurations/Felix/Configuration.h Просмотреть файл

@@ -427,6 +427,9 @@
427 427
 #define Z_MAX_ENDSTOP_INVERTING true  // set to true to invert the logic of the endstop.
428 428
 #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
429 429
 
430
+// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE.
431
+// Then the function testing the endstops will only be called, if the state of one of the endstops changed.
432
+//#define ENDSTOP_INTERRUPTS_FEATURE
430 433
 
431 434
 //=============================================================================
432 435
 //============================== Movement Settings ============================

+ 3
- 0
Marlin/example_configurations/Felix/DUAL/Configuration.h Просмотреть файл

@@ -427,6 +427,9 @@
427 427
 #define Z_MAX_ENDSTOP_INVERTING true  // set to true to invert the logic of the endstop.
428 428
 #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
429 429
 
430
+// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE.
431
+// Then the function testing the endstops will only be called, if the state of one of the endstops changed.
432
+//#define ENDSTOP_INTERRUPTS_FEATURE
430 433
 
431 434
 //=============================================================================
432 435
 //============================== Movement Settings ============================

+ 3
- 0
Marlin/example_configurations/Hephestos/Configuration.h Просмотреть файл

@@ -437,6 +437,9 @@
437 437
 #define Z_MAX_ENDSTOP_INVERTING true  // set to true to invert the logic of the endstop.
438 438
 #define Z_MIN_PROBE_ENDSTOP_INVERTING true  // set to true to invert the logic of the endstop.
439 439
 
440
+// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE.
441
+// Then the function testing the endstops will only be called, if the state of one of the endstops changed.
442
+//#define ENDSTOP_INTERRUPTS_FEATURE
440 443
 
441 444
 //=============================================================================
442 445
 //============================== Movement Settings ============================

+ 3
- 0
Marlin/example_configurations/Hephestos_2/Configuration.h Просмотреть файл

@@ -439,6 +439,9 @@
439 439
 #define Z_MAX_ENDSTOP_INVERTING true  // set to true to invert the logic of the endstop.
440 440
 #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
441 441
 
442
+// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE.
443
+// Then the function testing the endstops will only be called, if the state of one of the endstops changed.
444
+//#define ENDSTOP_INTERRUPTS_FEATURE
442 445
 
443 446
 //=============================================================================
444 447
 //============================== Movement Settings ============================

+ 3
- 0
Marlin/example_configurations/K8200/Configuration.h Просмотреть файл

@@ -462,6 +462,9 @@
462 462
 #define Z_MAX_ENDSTOP_INVERTING true  // set to true to invert the logic of the endstop.
463 463
 #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
464 464
 
465
+// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE.
466
+// Then the function testing the endstops will only be called, if the state of one of the endstops changed.
467
+//#define ENDSTOP_INTERRUPTS_FEATURE
465 468
 
466 469
 //=============================================================================
467 470
 //============================== Movement Settings ============================

+ 3
- 0
Marlin/example_configurations/K8400/Configuration.h Просмотреть файл

@@ -445,6 +445,9 @@
445 445
 #define Z_MAX_ENDSTOP_INVERTING true  // set to true to invert the logic of the endstop.
446 446
 #define Z_MIN_PROBE_ENDSTOP_INVERTING true  // set to true to invert the logic of the endstop.
447 447
 
448
+// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE.
449
+// Then the function testing the endstops will only be called, if the state of one of the endstops changed.
450
+//#define ENDSTOP_INTERRUPTS_FEATURE
448 451
 
449 452
 //=============================================================================
450 453
 //============================== Movement Settings ============================

+ 3
- 0
Marlin/example_configurations/K8400/Dual-head/Configuration.h Просмотреть файл

@@ -445,6 +445,9 @@
445 445
 #define Z_MAX_ENDSTOP_INVERTING true  // set to true to invert the logic of the endstop.
446 446
 #define Z_MIN_PROBE_ENDSTOP_INVERTING true  // set to true to invert the logic of the endstop.
447 447
 
448
+// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE.
449
+// Then the function testing the endstops will only be called, if the state of one of the endstops changed.
450
+//#define ENDSTOP_INTERRUPTS_FEATURE
448 451
 
449 452
 //=============================================================================
450 453
 //============================== Movement Settings ============================

+ 3
- 0
Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h Просмотреть файл

@@ -445,6 +445,9 @@
445 445
 #define Z_MAX_ENDSTOP_INVERTING true  // set to true to invert the logic of the endstop.
446 446
 #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
447 447
 
448
+// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE.
449
+// Then the function testing the endstops will only be called, if the state of one of the endstops changed.
450
+//#define ENDSTOP_INTERRUPTS_FEATURE
448 451
 
449 452
 //=============================================================================
450 453
 //============================== Movement Settings ============================

+ 3
- 0
Marlin/example_configurations/RigidBot/Configuration.h Просмотреть файл

@@ -442,6 +442,9 @@
442 442
 #define Z_MAX_ENDSTOP_INVERTING true  // set to true to invert the logic of the endstop.
443 443
 #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
444 444
 
445
+// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE.
446
+// Then the function testing the endstops will only be called, if the state of one of the endstops changed.
447
+//#define ENDSTOP_INTERRUPTS_FEATURE
445 448
 
446 449
 //=============================================================================
447 450
 //============================== Movement Settings ============================

+ 3
- 0
Marlin/example_configurations/SCARA/Configuration.h Просмотреть файл

@@ -460,6 +460,9 @@
460 460
 #define Z_MAX_ENDSTOP_INVERTING true  // set to true to invert the logic of the endstop.
461 461
 #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
462 462
 
463
+// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE.
464
+// Then the function testing the endstops will only be called, if the state of one of the endstops changed.
465
+//#define ENDSTOP_INTERRUPTS_FEATURE
463 466
 
464 467
 //=============================================================================
465 468
 //============================== Movement Settings ============================

+ 3
- 0
Marlin/example_configurations/TAZ4/Configuration.h Просмотреть файл

@@ -466,6 +466,9 @@
466 466
 #define Z_MAX_ENDSTOP_INVERTING true  // set to true to invert the logic of the endstop.
467 467
 #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
468 468
 
469
+// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE.
470
+// Then the function testing the endstops will only be called, if the state of one of the endstops changed.
471
+//#define ENDSTOP_INTERRUPTS_FEATURE
469 472
 
470 473
 //=============================================================================
471 474
 //============================== Movement Settings ============================

+ 3
- 0
Marlin/example_configurations/WITBOX/Configuration.h Просмотреть файл

@@ -437,6 +437,9 @@
437 437
 #define Z_MAX_ENDSTOP_INVERTING true  // set to true to invert the logic of the endstop.
438 438
 #define Z_MIN_PROBE_ENDSTOP_INVERTING true  // set to true to invert the logic of the endstop.
439 439
 
440
+// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE.
441
+// Then the function testing the endstops will only be called, if the state of one of the endstops changed.
442
+//#define ENDSTOP_INTERRUPTS_FEATURE
440 443
 
441 444
 //=============================================================================
442 445
 //============================== Movement Settings ============================

+ 3
- 0
Marlin/example_configurations/adafruit/ST7565/Configuration.h Просмотреть файл

@@ -445,6 +445,9 @@
445 445
 #define Z_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
446 446
 #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
447 447
 
448
+// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE.
449
+// Then the function testing the endstops will only be called, if the state of one of the endstops changed.
450
+//#define ENDSTOP_INTERRUPTS_FEATURE
448 451
 
449 452
 //=============================================================================
450 453
 //============================== Movement Settings ============================

+ 3
- 0
Marlin/example_configurations/delta/biv2.5/Configuration.h Просмотреть файл

@@ -489,6 +489,9 @@
489 489
 #define Z_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
490 490
 #define Z_MIN_PROBE_ENDSTOP_INVERTING true  // set to true to invert the logic of the endstop.
491 491
 
492
+// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE.
493
+// Then the function testing the endstops will only be called, if the state of one of the endstops changed.
494
+//#define ENDSTOP_INTERRUPTS_FEATURE
492 495
 
493 496
 //=============================================================================
494 497
 //============================== Movement Settings ============================

+ 3
- 0
Marlin/example_configurations/delta/generic/Configuration.h Просмотреть файл

@@ -489,6 +489,9 @@
489 489
 #define Z_MAX_ENDSTOP_INVERTING true  // set to true to invert the logic of the endstop.
490 490
 #define Z_MIN_PROBE_ENDSTOP_INVERTING true  // set to true to invert the logic of the endstop.
491 491
 
492
+// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE.
493
+// Then the function testing the endstops will only be called, if the state of one of the endstops changed.
494
+//#define ENDSTOP_INTERRUPTS_FEATURE
492 495
 
493 496
 //=============================================================================
494 497
 //============================== Movement Settings ============================

+ 3
- 0
Marlin/example_configurations/delta/kossel_mini/Configuration.h Просмотреть файл

@@ -489,6 +489,9 @@
489 489
 #define Z_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
490 490
 #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
491 491
 
492
+// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE.
493
+// Then the function testing the endstops will only be called, if the state of one of the endstops changed.
494
+//#define ENDSTOP_INTERRUPTS_FEATURE
492 495
 
493 496
 //=============================================================================
494 497
 //============================== Movement Settings ============================

+ 3
- 0
Marlin/example_configurations/delta/kossel_pro/Configuration.h Просмотреть файл

@@ -478,6 +478,9 @@
478 478
 #define Z_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
479 479
 #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
480 480
 
481
+// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE.
482
+// Then the function testing the endstops will only be called, if the state of one of the endstops changed.
483
+//#define ENDSTOP_INTERRUPTS_FEATURE
481 484
 
482 485
 //=============================================================================
483 486
 //============================== Movement Settings ============================

+ 3
- 0
Marlin/example_configurations/delta/kossel_xl/Configuration.h Просмотреть файл

@@ -487,6 +487,9 @@
487 487
 #define Z_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
488 488
 #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
489 489
 
490
+// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE.
491
+// Then the function testing the endstops will only be called, if the state of one of the endstops changed.
492
+//#define ENDSTOP_INTERRUPTS_FEATURE
490 493
 
491 494
 //=============================================================================
492 495
 //============================== Movement Settings ============================

+ 3
- 0
Marlin/example_configurations/makibox/Configuration.h Просмотреть файл

@@ -448,6 +448,9 @@
448 448
 #define Z_MAX_ENDSTOP_INVERTING true  // set to true to invert the logic of the endstop.
449 449
 #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
450 450
 
451
+// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE.
452
+// Then the function testing the endstops will only be called, if the state of one of the endstops changed.
453
+//#define ENDSTOP_INTERRUPTS_FEATURE
451 454
 
452 455
 //=============================================================================
453 456
 //============================== Movement Settings ============================

+ 3
- 0
Marlin/example_configurations/tvrrug/Round2/Configuration.h Просмотреть файл

@@ -435,6 +435,9 @@
435 435
 #define Z_MAX_ENDSTOP_INVERTING true  // set to true to invert the logic of the endstop.
436 436
 #define Z_MIN_PROBE_ENDSTOP_INVERTING true  // set to true to invert the logic of the endstop.
437 437
 
438
+// If all used endstop pins are able to cause interrupts, you can enable ENDSTOP_INTERRUPTS_FEATURE.
439
+// Then the function testing the endstops will only be called, if the state of one of the endstops changed.
440
+//#define ENDSTOP_INTERRUPTS_FEATURE
438 441
 
439 442
 //=============================================================================
440 443
 //============================== Movement Settings ============================

+ 13
- 1
Marlin/stepper.cpp Просмотреть файл

@@ -310,6 +310,10 @@ void Stepper::set_directions() {
310 310
   #endif // !ADVANCE && !LIN_ADVANCE
311 311
 }
312 312
 
313
+#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
314
+  extern volatile uint8_t e_hit;
315
+#endif
316
+
313 317
 /**
314 318
  * Stepper Driver Interrupt
315 319
  *
@@ -378,7 +382,15 @@ void Stepper::isr() {
378 382
     #if HAS_BED_PROBE
379 383
       || endstops.z_probe_enabled
380 384
     #endif
381
-  ) endstops.update();
385
+  )
386
+  #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
387
+    if(e_hit) {
388
+  #endif
389
+      endstops.update();
390
+  #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
391
+      e_hit--;
392
+    }
393
+  #endif
382 394
 
383 395
   // Take multiple steps per interrupt (For high speed moves)
384 396
   bool all_steps_done = false;

+ 32
- 0
buildroot/share/pin_interrupt_test/pin_interrupt_test.ino Просмотреть файл

@@ -0,0 +1,32 @@
1
+// Search pins uasable for endstop-interupts
2
+// Compile with the same settings you'd use with Marlin.
3
+
4
+#if defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_AVR_MEGA)
5
+    #undef  digitalPinToPCICR
6
+    #define digitalPinToPCICR(p)    ( (((p) >= 10) && ((p) <= 15)) || \
7
+                                    (((p) >= 50) && ((p) <= 53)) || \
8
+                                    (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) )
9
+#endif
10
+
11
+void setup() {
12
+  Serial.begin(9600);
13
+  Serial.println("PINs causing interrups are:");
14
+  for(int i=2; i<NUM_DIGITAL_PINS; i++){
15
+    if( digitalPinToPCICR(i) != NULL || (int)digitalPinToInterrupt(i) != -1 ) {
16
+      for (int j= 0; j<NUM_ANALOG_INPUTS; j++){
17
+        if(analogInputToDigitalPin(j) == i) {
18
+          Serial.print("A");
19
+          Serial.print(j);
20
+          Serial.print(" = ");
21
+        }
22
+      }
23
+      Serial.print("D");
24
+      Serial.println(i);
25
+    }
26
+  }
27
+  Serial.println("Arduino pin numbering!");
28
+}
29
+
30
+void loop() {
31
+  // put your main code here, to run repeatedly:
32
+}

Загрузка…
Отмена
Сохранить