Sfoglia il codice sorgente

Add MINIMUM_STEPPER_PULSE ability to babystepping

Sebastianv650 7 anni fa
parent
commit
80830919dc
1 ha cambiato i file con 46 aggiunte e 9 eliminazioni
  1. 46
    9
      Marlin/stepper.cpp

+ 46
- 9
Marlin/stepper.cpp Vedi File

@@ -1231,17 +1231,18 @@ void Stepper::report_positions() {
1231 1231
 
1232 1232
 #if ENABLED(BABYSTEPPING)
1233 1233
 
1234
+  #define CYCLES_EATEN_BY_BABYSTEP 60
1234 1235
   #define _ENABLE(axis) enable_## axis()
1235 1236
   #define _READ_DIR(AXIS) AXIS ##_DIR_READ
1236 1237
   #define _INVERT_DIR(AXIS) INVERT_## AXIS ##_DIR
1237 1238
   #define _APPLY_DIR(AXIS, INVERT) AXIS ##_APPLY_DIR(INVERT, true)
1238 1239
 
1239
-  #define BABYSTEP_AXIS(axis, AXIS, INVERT) { \
1240
-      _ENABLE(axis); \
1241
-      uint8_t old_pin = _READ_DIR(AXIS); \
1240
+  #define START_BABYSTEP_AXIS(AXIS, INVERT) { \
1242 1241
       _APPLY_DIR(AXIS, _INVERT_DIR(AXIS)^direction^INVERT); \
1243 1242
       _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS), true); \
1244
-      delayMicroseconds(2); \
1243
+    }
1244
+
1245
+  #define STOP_BABYSTEP_AXIS(AXIS) { \
1245 1246
       _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS), true); \
1246 1247
       _APPLY_DIR(AXIS, old_pin); \
1247 1248
     }
@@ -1249,22 +1250,53 @@ void Stepper::report_positions() {
1249 1250
   // MUST ONLY BE CALLED BY AN ISR,
1250 1251
   // No other ISR should ever interrupt this!
1251 1252
   void Stepper::babystep(const AxisEnum axis, const bool direction) {
1252
-
1253
+    static uint8_t old_pin;
1254
+    #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1255
+      static uint32_t pulse_start;
1256
+    #endif
1257
+    
1253 1258
     switch (axis) {
1254 1259
 
1255 1260
       case X_AXIS:
1256
-        BABYSTEP_AXIS(x, X, false);
1261
+        _ENABLE(x);
1262
+        old_pin = _READ_DIR(X);
1263
+        #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1264
+          pulse_start = TCNT0;
1265
+        #endif \
1266
+        START_BABYSTEP_AXIS(X, false);
1267
+        #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1268
+          while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_BABYSTEP) { /* nada */ }
1269
+        #endif
1270
+        STOP_BABYSTEP_AXIS(X);
1257 1271
         break;
1258 1272
 
1259 1273
       case Y_AXIS:
1260
-        BABYSTEP_AXIS(y, Y, false);
1274
+        _ENABLE(y);
1275
+        old_pin = _READ_DIR(Y);
1276
+        #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1277
+          pulse_start = TCNT0;
1278
+        #endif
1279
+        START_BABYSTEP_AXIS(Y, false);
1280
+        #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1281
+          while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_BABYSTEP) { /* nada */ }
1282
+        #endif
1283
+        STOP_BABYSTEP_AXIS(Y);
1261 1284
         break;
1262 1285
 
1263 1286
       case Z_AXIS: {
1264 1287
 
1265 1288
         #if DISABLED(DELTA)
1266 1289
 
1267
-          BABYSTEP_AXIS(z, Z, BABYSTEP_INVERT_Z);
1290
+          _ENABLE(z);
1291
+          old_pin = _READ_DIR(Z);
1292
+          #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1293
+            pulse_start = TCNT0;
1294
+          #endif
1295
+          START_BABYSTEP_AXIS(Z, BABYSTEP_INVERT_Z);
1296
+          #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1297
+            while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_BABYSTEP) { /* nada */ }
1298
+          #endif
1299
+          STOP_BABYSTEP_AXIS(Z);
1268 1300
 
1269 1301
         #else // DELTA
1270 1302
 
@@ -1281,10 +1313,15 @@ void Stepper::report_positions() {
1281 1313
           Y_DIR_WRITE(INVERT_Y_DIR ^ z_direction);
1282 1314
           Z_DIR_WRITE(INVERT_Z_DIR ^ z_direction);
1283 1315
           //perform step
1316
+          #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1317
+            pulse_start = TCNT0;
1318
+          #endif
1284 1319
           X_STEP_WRITE(!INVERT_X_STEP_PIN);
1285 1320
           Y_STEP_WRITE(!INVERT_Y_STEP_PIN);
1286 1321
           Z_STEP_WRITE(!INVERT_Z_STEP_PIN);
1287
-          delayMicroseconds(2);
1322
+          #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1323
+            while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_BABYSTEP) { /* nada */ }
1324
+          #endif
1288 1325
           X_STEP_WRITE(INVERT_X_STEP_PIN);
1289 1326
           Y_STEP_WRITE(INVERT_Y_STEP_PIN);
1290 1327
           Z_STEP_WRITE(INVERT_Z_STEP_PIN);

Loading…
Annulla
Salva