From 21b45327887d228d65d967857ac77b6b883b34fc Mon Sep 17 00:00:00 2001 From: lavolpecheprogramma Date: Mon, 10 Feb 2020 22:45:28 +0100 Subject: [PATCH] add servo support by DWiskow --- grbl/config.h | 6 +++--- grbl/cpu_map.h | 3 ++- grbl/spindle_control.c | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/grbl/config.h b/grbl/config.h index f48d958..dfa9355 100644 --- a/grbl/config.h +++ b/grbl/config.h @@ -102,12 +102,12 @@ // on separate pin, but homed in one cycle. Also, it should be noted that the function of hard limits // will not be affected by pin sharing. // NOTE: Defaults are set for a traditional 3-axis CNC machine. Z-axis first to clear, followed by X & Y. -#define HOMING_CYCLE_0 (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) + // #define SPINDLE_TCCRB_INIT_MASK (1< 0.98kHz (J-tech laser) + #define SPINDLE_TCCRB_INIT_MASK ((1< 61Hz (for Servo) // NOTE: On the 328p, these must be the same as the SPINDLE_ENABLE settings. #define SPINDLE_PWM_DDR DDRB diff --git a/grbl/spindle_control.c b/grbl/spindle_control.c index 550b752..4671ff2 100644 --- a/grbl/spindle_control.c +++ b/grbl/spindle_control.c @@ -21,6 +21,10 @@ #include "grbl.h" +#define RC_SERVO_SHORT 15 // set min pulse duration to (7 = 0.5ms, 15 = 1.03ms, 20=1.40ms) // RC Servo +#define RC_SERVO_LONG 31 // set max pulse duration (38 = 2.49ms, 31 = 2.05ms) // RC Servo +#define RC_SERVO_RANGE (RC_SERVO_LONG-RC_SERVO_SHORT) // RC Servo +// #define RC_SERVO_INVERT 1 // Uncomment to invert servo direction // RC Servo #ifdef VARIABLE_SPINDLE static float pwm_gradient; // Precalulated value to speed up rpm to PWM conversions. @@ -113,6 +117,16 @@ void spindle_stop() SPINDLE_ENABLE_PORT &= ~(1<