Browse Source

Let laser/spindle use free AVR servo timers (#19011)

Giuliano Zaro 3 years ago
parent
commit
6cfc4b5711
No account linked to committer's email address
2 changed files with 7 additions and 4 deletions
  1. 5
    3
      Marlin/src/HAL/AVR/ServoTimers.h
  2. 2
    1
      Marlin/src/HAL/AVR/inc/SanityCheck.h

+ 5
- 3
Marlin/src/HAL/AVR/ServoTimers.h View File

@@ -60,9 +60,11 @@
60 60
 #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
61 61
   //#define _useTimer1
62 62
   #define _useTimer3
63
-  #define _useTimer4
64
-  #if !HAS_MOTOR_CURRENT_PWM
65
-    #define _useTimer5 // Timer 5 is used for motor current PWM and can't be used for servos.
63
+  #if NUM_SERVOS > SERVOS_PER_TIMER
64
+    #define _useTimer4
65
+    #if !HAS_MOTOR_CURRENT_PWM && SERVOS > 2 * SERVOS_PER_TIMER
66
+      #define _useTimer5 // Timer 5 is used for motor current PWM and can't be used for servos.
67
+    #endif
66 68
   #endif
67 69
 #elif defined(__AVR_ATmega32U4__)
68 70
   #define _useTimer3

+ 2
- 1
Marlin/src/HAL/AVR/inc/SanityCheck.h View File

@@ -36,9 +36,10 @@
36 36
  * Sanity checks for Spindle / Laser PWM
37 37
  */
38 38
 #if ENABLED(SPINDLE_LASER_PWM)
39
+  #include "../ServoTimers.h"   // Needed to check timer availability (_useTimer3)
39 40
   #if SPINDLE_LASER_PWM_PIN == 4 || WITHIN(SPINDLE_LASER_PWM_PIN, 11, 13)
40 41
     #error "Counter/Timer for SPINDLE_LASER_PWM_PIN is used by a system interrupt."
41
-  #elif NUM_SERVOS > 0 && (WITHIN(SPINDLE_LASER_PWM_PIN, 2, 3) || SPINDLE_LASER_PWM_PIN == 5)
42
+  #elif NUM_SERVOS > 0 && defined(_useTimer3) && (WITHIN(SPINDLE_LASER_PWM_PIN, 2, 3) || SPINDLE_LASER_PWM_PIN == 5)
42 43
     #error "Counter/Timer for SPINDLE_LASER_PWM_PIN is used by the servo system."
43 44
   #endif
44 45
 #elif defined(SPINDLE_LASER_FREQUENCY)

Loading…
Cancel
Save