Browse Source

Merge pull request #6081 from Sebastianv650/MIN_STEPPER_PULSE_for_Babystepping

Add MINIMUM_STEPPER_PULSE ability to babystepping
Scott Lahteine 8 years ago
parent
commit
782634b6c9
1 changed files with 48 additions and 9 deletions
  1. 48
    9
      Marlin/stepper.cpp

+ 48
- 9
Marlin/stepper.cpp View 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,54 @@ 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
+    cli();
1254
+    static uint8_t old_pin;
1255
+    #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1256
+      static uint32_t pulse_start;
1257
+    #endif
1258
+    
1253 1259
     switch (axis) {
1254 1260
 
1255 1261
       case X_AXIS:
1256
-        BABYSTEP_AXIS(x, X, false);
1262
+        _ENABLE(x);
1263
+        old_pin = _READ_DIR(X);
1264
+        #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1265
+          pulse_start = TCNT0;
1266
+        #endif \
1267
+        START_BABYSTEP_AXIS(X, false);
1268
+        #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1269
+          while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_BABYSTEP) { /* nada */ }
1270
+        #endif
1271
+        STOP_BABYSTEP_AXIS(X);
1257 1272
         break;
1258 1273
 
1259 1274
       case Y_AXIS:
1260
-        BABYSTEP_AXIS(y, Y, false);
1275
+        _ENABLE(y);
1276
+        old_pin = _READ_DIR(Y);
1277
+        #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1278
+          pulse_start = TCNT0;
1279
+        #endif
1280
+        START_BABYSTEP_AXIS(Y, false);
1281
+        #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1282
+          while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_BABYSTEP) { /* nada */ }
1283
+        #endif
1284
+        STOP_BABYSTEP_AXIS(Y);
1261 1285
         break;
1262 1286
 
1263 1287
       case Z_AXIS: {
1264 1288
 
1265 1289
         #if DISABLED(DELTA)
1266 1290
 
1267
-          BABYSTEP_AXIS(z, Z, BABYSTEP_INVERT_Z);
1291
+          _ENABLE(z);
1292
+          old_pin = _READ_DIR(Z);
1293
+          #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1294
+            pulse_start = TCNT0;
1295
+          #endif
1296
+          START_BABYSTEP_AXIS(Z, BABYSTEP_INVERT_Z);
1297
+          #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1298
+            while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_BABYSTEP) { /* nada */ }
1299
+          #endif
1300
+          STOP_BABYSTEP_AXIS(Z);
1268 1301
 
1269 1302
         #else // DELTA
1270 1303
 
@@ -1281,10 +1314,15 @@ void Stepper::report_positions() {
1281 1314
           Y_DIR_WRITE(INVERT_Y_DIR ^ z_direction);
1282 1315
           Z_DIR_WRITE(INVERT_Z_DIR ^ z_direction);
1283 1316
           //perform step
1317
+          #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1318
+            pulse_start = TCNT0;
1319
+          #endif
1284 1320
           X_STEP_WRITE(!INVERT_X_STEP_PIN);
1285 1321
           Y_STEP_WRITE(!INVERT_Y_STEP_PIN);
1286 1322
           Z_STEP_WRITE(!INVERT_Z_STEP_PIN);
1287
-          delayMicroseconds(2);
1323
+          #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1324
+            while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_BABYSTEP) { /* nada */ }
1325
+          #endif
1288 1326
           X_STEP_WRITE(INVERT_X_STEP_PIN);
1289 1327
           Y_STEP_WRITE(INVERT_Y_STEP_PIN);
1290 1328
           Z_STEP_WRITE(INVERT_Z_STEP_PIN);
@@ -1299,6 +1337,7 @@ void Stepper::report_positions() {
1299 1337
 
1300 1338
       default: break;
1301 1339
     }
1340
+    sei();
1302 1341
   }
1303 1342
 
1304 1343
 #endif //BABYSTEPPING

Loading…
Cancel
Save