Browse Source

Multiple axis TMC OTPW step down (#16044)

Scott Lahteine 4 years ago
parent
commit
27943f9e31
No account linked to committer's email address
3 changed files with 97 additions and 42 deletions
  1. 1
    1
      Marlin/src/Marlin.cpp
  2. 95
    40
      Marlin/src/feature/tmc_util.cpp
  3. 1
    1
      Marlin/src/feature/tmc_util.h

+ 1
- 1
Marlin/src/Marlin.cpp View File

@@ -601,7 +601,7 @@ void manage_inactivity(const bool ignore_stepper_queue/*=false*/) {
601 601
   #endif
602 602
 
603 603
   #if ENABLED(MONITOR_DRIVER_STATUS)
604
-    monitor_tmc_driver();
604
+    monitor_tmc_drivers();
605 605
   #endif
606 606
 
607 607
   #if ENABLED(MONITOR_L6470_DRIVER_STATUS)

+ 95
- 40
Marlin/src/feature/tmc_util.cpp View File

@@ -265,10 +265,30 @@
265 265
     SERIAL_CHAR('\t');
266 266
   }
267 267
 
268
+  #if CURRENT_STEP_DOWN > 0
269
+
270
+    template<typename TMC>
271
+    void step_current_down(TMC &st) {
272
+      if (st.isEnabled()) {
273
+        const uint16_t I_rms = st.getMilliamps() - (CURRENT_STEP_DOWN);
274
+        if (I_rms > 50) {
275
+          st.rms_current(I_rms);
276
+          #if ENABLED(REPORT_CURRENT_CHANGE)
277
+            st.printLabel();
278
+            SERIAL_ECHOLNPAIR(" current decreased to ", I_rms);
279
+          #endif
280
+        }
281
+      }
282
+    }
283
+
284
+  #endif
285
+
268 286
   template<typename TMC>
269
-  void monitor_tmc_driver(TMC &st, const bool need_update_error_counters, const bool need_debug_reporting) {
287
+  bool monitor_tmc_driver(TMC &st, const bool need_update_error_counters, const bool need_debug_reporting) {
270 288
     TMC_driver_data data = get_driver_data(st);
271
-    if (data.drv_status == 0xFFFFFFFF || data.drv_status == 0x0) return;
289
+    if (data.drv_status == 0xFFFFFFFF || data.drv_status == 0x0) return false;
290
+
291
+    bool did_step_down = false;
272 292
 
273 293
     if (need_update_error_counters) {
274 294
       if (data.is_ot /* | data.s2ga | data.s2gb*/) st.error_count++;
@@ -288,15 +308,9 @@
288 308
 
289 309
       #if CURRENT_STEP_DOWN > 0
290 310
         // Decrease current if is_otpw is true and driver is enabled and there's been more than 4 warnings
291
-        if (data.is_otpw && st.otpw_count > 4) {
292
-          uint16_t I_rms = st.getMilliamps();
293
-          if (st.isEnabled() && I_rms > 100) {
294
-            st.rms_current(I_rms - (CURRENT_STEP_DOWN));
295
-            #if ENABLED(REPORT_CURRENT_CHANGE)
296
-              st.printLabel();
297
-              SERIAL_ECHOLNPAIR(" current decreased to ", st.getMilliamps());
298
-            #endif
299
-          }
311
+        if (data.is_otpw && st.otpw_count > 4 && st.isEnabled()) {
312
+          step_current_down(st);
313
+          did_step_down = true;
300 314
         }
301 315
       #endif
302 316
 
@@ -308,64 +322,105 @@
308 322
     }
309 323
 
310 324
     #if ENABLED(TMC_DEBUG)
311
-      if (need_debug_reporting)
312
-        report_polled_driver_data(st, data);
325
+      if (need_debug_reporting) report_polled_driver_data(st, data);
313 326
     #endif
327
+
328
+    return did_step_down;
314 329
   }
315 330
 
316
-  void monitor_tmc_driver() {
317
-    static millis_t next_poll = 0;
331
+  void monitor_tmc_drivers() {
318 332
     const millis_t ms = millis();
319
-    bool need_update_error_counters = ELAPSED(ms, next_poll);
320
-    bool need_debug_reporting = false;
321
-    if (need_update_error_counters)
322
-      next_poll = ms + MONITOR_DRIVER_STATUS_INTERVAL_MS;
333
+
334
+    // Poll TMC drivers at the configured interval
335
+    static millis_t next_poll = 0;
336
+    const bool need_update_error_counters = ELAPSED(ms, next_poll);
337
+    if (need_update_error_counters) next_poll = ms + MONITOR_DRIVER_STATUS_INTERVAL_MS;
338
+
339
+    // Also poll at intervals for debugging
323 340
     #if ENABLED(TMC_DEBUG)
324 341
       static millis_t next_debug_reporting = 0;
325
-      if (report_tmc_status_interval && ELAPSED(ms, next_debug_reporting)) {
326
-        need_debug_reporting = true;
327
-        next_debug_reporting = ms + report_tmc_status_interval;
328
-      }
342
+      const bool need_debug_reporting = report_tmc_status_interval && ELAPSED(ms, next_debug_reporting);
343
+      if (need_debug_reporting) next_debug_reporting = ms + report_tmc_status_interval;
344
+    #else
345
+      constexpr bool need_debug_reporting = false;
329 346
     #endif
347
+
330 348
     if (need_update_error_counters || need_debug_reporting) {
331 349
       #if AXIS_IS_TMC(X)
332
-        monitor_tmc_driver(stepperX, need_update_error_counters, need_debug_reporting);
333
-      #endif
334
-      #if AXIS_IS_TMC(Y)
335
-        monitor_tmc_driver(stepperY, need_update_error_counters, need_debug_reporting);
336
-      #endif
337
-      #if AXIS_IS_TMC(Z)
338
-        monitor_tmc_driver(stepperZ, need_update_error_counters, need_debug_reporting);
350
+        if (monitor_tmc_driver(stepperX, need_update_error_counters, need_debug_reporting)) {
351
+          #if AXIS_IS_TMC(X2)
352
+            step_current_down(stepperX2)
353
+          #endif
354
+        }
339 355
       #endif
340 356
       #if AXIS_IS_TMC(X2)
341
-        monitor_tmc_driver(stepperX2, need_update_error_counters, need_debug_reporting);
357
+        if (monitor_tmc_driver(stepperX2, need_update_error_counters, need_debug_reporting)) {
358
+          #if AXIS_IS_TMC(X)
359
+            step_current_down(stepperX)
360
+          #endif
361
+        }
362
+      #endif
363
+      #if AXIS_IS_TMC(Y)
364
+        if (monitor_tmc_driver(stepperY, need_update_error_counters, need_debug_reporting)) {
365
+          #if AXIS_IS_TMC(Y2)
366
+            step_current_down(stepperY2)
367
+          #endif
368
+        }
342 369
       #endif
343 370
       #if AXIS_IS_TMC(Y2)
344
-        monitor_tmc_driver(stepperY2, need_update_error_counters, need_debug_reporting);
371
+        if (monitor_tmc_driver(stepperY2, need_update_error_counters, need_debug_reporting)) {
372
+          #if AXIS_IS_TMC(Y)
373
+            step_current_down(stepperY)
374
+          #endif
375
+        }
376
+      #endif
377
+      #if AXIS_IS_TMC(Z)
378
+        if (monitor_tmc_driver(stepperZ, need_update_error_counters, need_debug_reporting)) {
379
+          #if AXIS_IS_TMC(Z2)
380
+            step_current_down(stepperZ2)
381
+          #endif
382
+          #if AXIS_IS_TMC(Z3)
383
+            step_current_down(stepperZ3)
384
+          #endif
385
+        }
345 386
       #endif
346 387
       #if AXIS_IS_TMC(Z2)
347
-        monitor_tmc_driver(stepperZ2, need_update_error_counters, need_debug_reporting);
388
+        if (monitor_tmc_driver(stepperZ2, need_update_error_counters, need_debug_reporting)) {
389
+          #if AXIS_IS_TMC(Z)
390
+            step_current_down(stepperZ)
391
+          #endif
392
+          #if AXIS_IS_TMC(Z3)
393
+            step_current_down(stepperZ3)
394
+          #endif
395
+        }
348 396
       #endif
349 397
       #if AXIS_IS_TMC(Z3)
350
-        monitor_tmc_driver(stepperZ3, need_update_error_counters, need_debug_reporting);
398
+        if (monitor_tmc_driver(stepperZ3, need_update_error_counters, need_debug_reporting)) {
399
+          #if AXIS_IS_TMC(Z)
400
+            step_current_down(stepperZ)
401
+          #endif
402
+          #if AXIS_IS_TMC(Z2)
403
+            step_current_down(stepperZ2)
404
+          #endif
405
+        }
351 406
       #endif
352 407
       #if AXIS_IS_TMC(E0)
353
-        monitor_tmc_driver(stepperE0, need_update_error_counters, need_debug_reporting);
408
+        (void)monitor_tmc_driver(stepperE0, need_update_error_counters, need_debug_reporting);
354 409
       #endif
355 410
       #if AXIS_IS_TMC(E1)
356
-        monitor_tmc_driver(stepperE1, need_update_error_counters, need_debug_reporting);
411
+        (void)monitor_tmc_driver(stepperE1, need_update_error_counters, need_debug_reporting);
357 412
       #endif
358 413
       #if AXIS_IS_TMC(E2)
359
-        monitor_tmc_driver(stepperE2, need_update_error_counters, need_debug_reporting);
414
+        (void)monitor_tmc_driver(stepperE2, need_update_error_counters, need_debug_reporting);
360 415
       #endif
361 416
       #if AXIS_IS_TMC(E3)
362
-        monitor_tmc_driver(stepperE3, need_update_error_counters, need_debug_reporting);
417
+        (void)monitor_tmc_driver(stepperE3, need_update_error_counters, need_debug_reporting);
363 418
       #endif
364 419
       #if AXIS_IS_TMC(E4)
365
-        monitor_tmc_driver(stepperE4, need_update_error_counters, need_debug_reporting);
420
+        (void)monitor_tmc_driver(stepperE4, need_update_error_counters, need_debug_reporting);
366 421
       #endif
367 422
       #if AXIS_IS_TMC(E5)
368
-        monitor_tmc_driver(stepperE5, need_update_error_counters, need_debug_reporting);
423
+        (void)monitor_tmc_driver(stepperE5, need_update_error_counters, need_debug_reporting);
369 424
       #endif
370 425
 
371 426
       #if ENABLED(TMC_DEBUG)

+ 1
- 1
Marlin/src/feature/tmc_util.h View File

@@ -345,7 +345,7 @@ void tmc_print_current(TMC &st) {
345 345
   }
346 346
 #endif
347 347
 
348
-void monitor_tmc_driver();
348
+void monitor_tmc_drivers();
349 349
 void test_tmc_connection(const bool test_x, const bool test_y, const bool test_z, const bool test_e);
350 350
 
351 351
 #if ENABLED(TMC_DEBUG)

Loading…
Cancel
Save