From 2165218f1349fd9b637ae7b78c286e815fdfcef5 Mon Sep 17 00:00:00 2001 From: lavolpecheprogramma Date: Tue, 11 Feb 2020 22:17:16 +0100 Subject: [PATCH] add servo motor support using cprezzi and DWiskow approach --- grbl/config.h | 10 ++++++++++ grbl/cpu_map.h | 15 ++++++++++----- grbl/spindle_control.c | 34 +++++++++++++++++++++++++++++++--- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/grbl/config.h b/grbl/config.h index f48d9586..f66a96d1 100644 --- a/grbl/config.h +++ b/grbl/config.h @@ -367,6 +367,16 @@ // NOTE: Requires USE_SPINDLE_DIR_AS_ENABLE_PIN to be enabled. // #define SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED // Default disabled. Uncomment to enable. +// If you use a servo instead of a spindle (like on EggBot or pen plotter), you need to uncomment this option. +// This will set the PWM frequency to 61Hz and limit the PWM range to 0.5 - 2.5ms, as used by most servos. +// #define SPINDLE_IS_SERVO // Default disabled. Uncomment to enable. + +#define SERVO_SHORT 7 // set min pulse duration to (7 = 0.5ms, 15 = 1.03ms, 20=1.40ms) +#define SERVO_LONG 38 // set max pulse duration (38 = 2.49ms, 31 = 2.05ms) +#define SERVO_RANGE (SERVO_LONG-SERVO_SHORT) +// #define SERVO_INVERT 1 // Uncomment to invert servo direction + + // With this enabled, Grbl sends back an echo of the line it has received, which has been pre-parsed (spaces // removed, capitalized letters, no comments) and is to be immediately executed by Grbl. Echoes will not be // sent upon a line buffer overflow, but should for all normal lines sent to Grbl. For example, if a user diff --git a/grbl/cpu_map.h b/grbl/cpu_map.h index 9f43a3fc..529d2ded 100644 --- a/grbl/cpu_map.h +++ b/grbl/cpu_map.h @@ -141,11 +141,16 @@ // Prescaled, 8-bit Fast PWM mode. #define SPINDLE_TCCRA_INIT_MASK ((1< 62.5kHz - // #define SPINDLE_TCCRB_INIT_MASK (1< 7.8kHz (Used in v0.9) - // #define SPINDLE_TCCRB_INIT_MASK ((1< 1.96kHz - #define SPINDLE_TCCRB_INIT_MASK (1< 0.98kHz (J-tech laser) - + + #ifdef SPINDLE_IS_SERVO + #define SPINDLE_TCCRB_INIT_MASK ((1< 61Hz (for Servo) + #else + // #define SPINDLE_TCCRB_INIT_MASK (1< 62.5kHz + // #define SPINDLE_TCCRB_INIT_MASK (1< 7.8kHz (Used in v0.9) + // #define SPINDLE_TCCRB_INIT_MASK ((1< 1.96kHz + #define SPINDLE_TCCRB_INIT_MASK (1< 0.98kHz (J-tech laser) + #endif + // NOTE: On the 328p, these must be the same as the SPINDLE_ENABLE settings. #define SPINDLE_PWM_DDR DDRB #define SPINDLE_PWM_PORT PORTB diff --git a/grbl/spindle_control.c b/grbl/spindle_control.c index 550b7520..594153f9 100644 --- a/grbl/spindle_control.c +++ b/grbl/spindle_control.c @@ -21,7 +21,6 @@ #include "grbl.h" - #ifdef VARIABLE_SPINDLE static float pwm_gradient; // Precalulated value to speed up rpm to PWM conversions. #endif @@ -113,6 +112,16 @@ void spindle_stop() SPINDLE_ENABLE_PORT &= ~(1<