From 16f2f2bce79505d0b8e605f542d7c4b859e2083a Mon Sep 17 00:00:00 2001 From: Giuliano Zaro <3684609+GMagician@users.noreply.github.com> Date: Fri, 14 Aug 2020 15:41:44 +0200 Subject: [PATCH] Let laser/spindle use free AVR servo timers (#19011) --- Marlin/src/HAL/AVR/ServoTimers.h | 8 +++++--- Marlin/src/HAL/AVR/inc/SanityCheck.h | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Marlin/src/HAL/AVR/ServoTimers.h b/Marlin/src/HAL/AVR/ServoTimers.h index 564714df6..598db6257 100644 --- a/Marlin/src/HAL/AVR/ServoTimers.h +++ b/Marlin/src/HAL/AVR/ServoTimers.h @@ -60,9 +60,11 @@ #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //#define _useTimer1 #define _useTimer3 - #define _useTimer4 - #if !HAS_MOTOR_CURRENT_PWM - #define _useTimer5 // Timer 5 is used for motor current PWM and can't be used for servos. + #if NUM_SERVOS > SERVOS_PER_TIMER + #define _useTimer4 + #if !HAS_MOTOR_CURRENT_PWM && SERVOS > 2 * SERVOS_PER_TIMER + #define _useTimer5 // Timer 5 is used for motor current PWM and can't be used for servos. + #endif #endif #elif defined(__AVR_ATmega32U4__) #define _useTimer3 diff --git a/Marlin/src/HAL/AVR/inc/SanityCheck.h b/Marlin/src/HAL/AVR/inc/SanityCheck.h index e55e45b73..731cf9286 100644 --- a/Marlin/src/HAL/AVR/inc/SanityCheck.h +++ b/Marlin/src/HAL/AVR/inc/SanityCheck.h @@ -36,9 +36,10 @@ * Sanity checks for Spindle / Laser PWM */ #if ENABLED(SPINDLE_LASER_PWM) + #include "../ServoTimers.h" // Needed to check timer availability (_useTimer3) #if SPINDLE_LASER_PWM_PIN == 4 || WITHIN(SPINDLE_LASER_PWM_PIN, 11, 13) #error "Counter/Timer for SPINDLE_LASER_PWM_PIN is used by a system interrupt." - #elif NUM_SERVOS > 0 && (WITHIN(SPINDLE_LASER_PWM_PIN, 2, 3) || SPINDLE_LASER_PWM_PIN == 5) + #elif NUM_SERVOS > 0 && defined(_useTimer3) && (WITHIN(SPINDLE_LASER_PWM_PIN, 2, 3) || SPINDLE_LASER_PWM_PIN == 5) #error "Counter/Timer for SPINDLE_LASER_PWM_PIN is used by the servo system." #endif #elif defined(SPINDLE_LASER_FREQUENCY)