From 827a4c9231f760cf8b0add1dfdd7adba02df2379 Mon Sep 17 00:00:00 2001 From: cprezzi Date: Wed, 8 Mar 2017 22:01:38 +0100 Subject: [PATCH 1/6] Set PWM frequency to 62.5Hz for Servo & don't stop PWM on S0. --- README.md | 2 +- grbl/cpu_map.h | 9 ++--- grbl/spindle_control.c | 74 +++++++++++++++++++++--------------------- 3 files changed, 43 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index ec951559..1526fa6d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![GitHub Logo](/doc/media/Grbl Logo 250px.png) *** -_Click the `Release` tab to download pre-compiled `.hex` files or just [click here](https://github.com/gnea/grbl/releases)_ +_This is a special version with servo support instead of spindle/laser PWM_ *** Grbl is a no-compromise, high performance, low cost alternative to parallel-port-based motion control for CNC milling. This version of Grbl runs on an Arduino with a 328p processor (Uno, Duemilanove, Nano, Micro, etc). diff --git a/grbl/cpu_map.h b/grbl/cpu_map.h index 0e2b25e5..64fa1182 100644 --- a/grbl/cpu_map.h +++ b/grbl/cpu_map.h @@ -124,11 +124,11 @@ // Variable spindle configuration below. Do not change unless you know what you are doing. // NOTE: Only used when variable spindle is enabled. - #define SPINDLE_PWM_MAX_VALUE 255 // Don't change. 328p fast PWM mode fixes top value as 255. + #define SPINDLE_PWM_MAX_VALUE 35 // Don't change. 328p fast PWM mode fixes top value as 255. #ifndef SPINDLE_PWM_MIN_VALUE - #define SPINDLE_PWM_MIN_VALUE 1 // Must be greater than zero. + #define SPINDLE_PWM_MIN_VALUE 10 // Must be greater than zero. #endif - #define SPINDLE_PWM_OFF_VALUE 0 + #define SPINDLE_PWM_OFF_VALUE -1 #define SPINDLE_PWM_RANGE (SPINDLE_PWM_MAX_VALUE-SPINDLE_PWM_MIN_VALUE) #define SPINDLE_TCCRA_REGISTER TCCR2A #define SPINDLE_TCCRB_REGISTER TCCR2B @@ -140,7 +140,8 @@ // #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) + // #define SPINDLE_TCCRB_INIT_MASK (1< 0.98kHz (J-tech laser) + #define SPINDLE_TCCRB_INIT_MASK ((1< 62.5Hz (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 a66a8688..4ebd2675 100644 --- a/grbl/spindle_control.c +++ b/grbl/spindle_control.c @@ -59,28 +59,28 @@ void spindle_init() uint8_t spindle_get_state() { #ifdef VARIABLE_SPINDLE - #ifdef USE_SPINDLE_DIR_AS_ENABLE_PIN - // No spindle direction output pin. - #ifdef INVERT_SPINDLE_ENABLE_PIN - if (bit_isfalse(SPINDLE_ENABLE_PORT,(1< Date: Thu, 9 Mar 2017 09:14:48 +0100 Subject: [PATCH 2/6] Updated README --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 1526fa6d..8d3f849b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,14 @@ ![GitHub Logo](/doc/media/Grbl Logo 250px.png) *** _This is a special version with servo support instead of spindle/laser PWM_ + +- The PWM frequency is set to 62.5Hz (prescaler 1/1024) +- The pulse width range is 0.63ms to 2.2ms +- S0 does not deactivate the PWM, but instead send min pulse width +- Set the max. S-value to `$30=255` to get a S-value range of 0-255 +- You should have a M3S0 at the start of your gcode to activate the servo and M5 at end to deactivate it *** + Grbl is a no-compromise, high performance, low cost alternative to parallel-port-based motion control for CNC milling. This version of Grbl runs on an Arduino with a 328p processor (Uno, Duemilanove, Nano, Micro, etc). The controller is written in highly optimized C utilizing every clever feature of the AVR-chips to achieve precise timing and asynchronous operation. It is able to maintain up to 30kHz of stable, jitter free control pulses. From aceeb8b846c72bda17f2111044b0b5f802a025ee Mon Sep 17 00:00:00 2001 From: Claudio Prezzi Date: Thu, 9 Mar 2017 09:25:21 +0100 Subject: [PATCH 3/6] Corrected README --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d3f849b..745e9b98 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ _This is a special version with servo support instead of spindle/laser PWM_ - The pulse width range is 0.63ms to 2.2ms - S0 does not deactivate the PWM, but instead send min pulse width - Set the max. S-value to `$30=255` to get a S-value range of 0-255 -- You should have a M3S0 at the start of your gcode to activate the servo and M5 at end to deactivate it +- You should have a M3S0 at the start of your gcode to activate the servo and M5 at end to deactivate it + *** Grbl is a no-compromise, high performance, low cost alternative to parallel-port-based motion control for CNC milling. This version of Grbl runs on an Arduino with a 328p processor (Uno, Duemilanove, Nano, Micro, etc). From fb5f6ae130a50a693432b71fca56ff0df8e9acf9 Mon Sep 17 00:00:00 2001 From: cprezzi Date: Fri, 10 Mar 2017 16:01:34 +0100 Subject: [PATCH 4/6] Added config define SPINDLE_IS_SERVO to activate servo spindle. --- grbl/config.h | 5 +++++ grbl/cpu_map.h | 28 +++++++++++++++++++--------- grbl/spindle_control.c | 31 +++++++++++++++++++++++-------- 3 files changed, 47 insertions(+), 17 deletions(-) diff --git a/grbl/config.h b/grbl/config.h index 063e6767..39913a4a 100644 --- a/grbl/config.h +++ b/grbl/config.h @@ -367,6 +367,11 @@ // 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. +// See cpu_map.h, if you need to change the PWM range. +#define SPINDLE_IS_SERVO // Default disabled. Uncomment to enable. + // 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 64fa1182..453810e3 100644 --- a/grbl/cpu_map.h +++ b/grbl/cpu_map.h @@ -124,11 +124,18 @@ // Variable spindle configuration below. Do not change unless you know what you are doing. // NOTE: Only used when variable spindle is enabled. - #define SPINDLE_PWM_MAX_VALUE 35 // Don't change. 328p fast PWM mode fixes top value as 255. - #ifndef SPINDLE_PWM_MIN_VALUE - #define SPINDLE_PWM_MIN_VALUE 10 // Must be greater than zero. + #ifdef SPINDLE_IS_SERVO + #define SPINDLE_PWM_MAX_VALUE 38 // set max pulse duration to 2.5ms + #ifndef SPINDLE_PWM_MIN_VALUE + #define SPINDLE_PWM_MIN_VALUE 7 // set min pulse duration to 0.5ms + #endif + #else + #define SPINDLE_PWM_MAX_VALUE 255 // Don't change. 328p fast PWM mode fixes top value as 255. + #ifndef SPINDLE_PWM_MIN_VALUE + #define SPINDLE_PWM_MIN_VALUE 1 // Must be greater than zero. + #endif #endif - #define SPINDLE_PWM_OFF_VALUE -1 + #define SPINDLE_PWM_OFF_VALUE 0 #define SPINDLE_PWM_RANGE (SPINDLE_PWM_MAX_VALUE-SPINDLE_PWM_MIN_VALUE) #define SPINDLE_TCCRA_REGISTER TCCR2A #define SPINDLE_TCCRB_REGISTER TCCR2B @@ -137,11 +144,14 @@ // 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) - #define SPINDLE_TCCRB_INIT_MASK ((1< 62.5Hz (Servo) + #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 diff --git a/grbl/spindle_control.c b/grbl/spindle_control.c index 4ebd2675..37abcb14 100644 --- a/grbl/spindle_control.c +++ b/grbl/spindle_control.c @@ -141,20 +141,27 @@ void spindle_stop() uint8_t spindle_compute_pwm_value(float rpm) // 328p PWM register is 8-bit. { uint8_t pwm_value; - rpm *= (0.010*sys.spindle_speed_ovr); // Scale by spindle speed override value. + #ifndef SPINDLE_IS_SERVO + rpm *= (0.010*sys.spindle_speed_ovr); // Scale by spindle speed override value. + #endif // Calculate PWM register value based on rpm max/min settings and programmed rpm. if ((settings.rpm_min >= settings.rpm_max) || (rpm >= settings.rpm_max)) { // No PWM range possible. Set simple on/off spindle control pin state. sys.spindle_speed = settings.rpm_max; pwm_value = SPINDLE_PWM_MAX_VALUE; } else if (rpm <= settings.rpm_min) { -// if (rpm == 0.0) { // S0 disables spindle -// sys.spindle_speed = 0.0; -// pwm_value = SPINDLE_PWM_OFF_VALUE; -// } else { // Set minimum PWM output + if (rpm == 0.0) { // S0 disables spindle + #ifndef SPINDLE_IS_SERVO + sys.spindle_speed = 0.0; + pwm_value = SPINDLE_PWM_OFF_VALUE; + #else + sys.spindle_speed = settings.rpm_min; + pwm_value = SPINDLE_PWM_MIN_VALUE; + #endif + } else { // Set minimum PWM output sys.spindle_speed = settings.rpm_min; pwm_value = SPINDLE_PWM_MIN_VALUE; -// } + } } else { // Compute intermediate PWM value with linear spindle speed model. // NOTE: A nonlinear model could be installed here, if required, but keep it VERY light-weight. @@ -179,9 +186,17 @@ void spindle_stop() if (state == SPINDLE_DISABLE) { // Halt or set spindle direction and rpm. #ifdef VARIABLE_SPINDLE - sys.spindle_speed = 0.0; + #ifndef SPINDLE_IS_SERVO + sys.spindle_speed = 0.0; + spindle_stop(); + #else + // For servo send min. PWM instead of deactivate PWM + sys.spindle_speed = SPINDLE_PWM_MIN_VALUE; + spindle_set_speed(spindle_compute_pwm_value(SPINDLE_PWM_MIN_VALUE)); + #endif + #else + spindle_stop(); #endif - spindle_stop(); } else { From 39c5b914b337ea52e157de087aadc58840c7c9ae Mon Sep 17 00:00:00 2001 From: cprezzi Date: Fri, 10 Mar 2017 16:08:52 +0100 Subject: [PATCH 5/6] Updated README.md --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 745e9b98..f6bb2018 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ ![GitHub Logo](/doc/media/Grbl Logo 250px.png) *** -_This is a special version with servo support instead of spindle/laser PWM_ +_This is a special version with servo support (swichable in config.h)_ -- The PWM frequency is set to 62.5Hz (prescaler 1/1024) -- The pulse width range is 0.63ms to 2.2ms -- S0 does not deactivate the PWM, but instead send min pulse width -- Set the max. S-value to `$30=255` to get a S-value range of 0-255 -- You should have a M3S0 at the start of your gcode to activate the servo and M5 at end to deactivate it +- The PWM frequency is set to 61Hz (prescaler 1/1024). +- The pulse width range is 0.5 - 2.5ms. +- S0 does not deactivate the PWM, but instead send min pulse width. +- Set the max. S-value to `$30=255` to get a S-value range of 0-255. +- You should have a M3S0 at the start of your gcode to activate the servo and M5 at end to deactivate it. *** From 162df1faf469bc068980a528cc142ebf09f8bdef Mon Sep 17 00:00:00 2001 From: cprezzi Date: Thu, 22 Feb 2018 20:48:46 +0100 Subject: [PATCH 6/6] Added #define HOMING_FORCE_POSITIVE_SPACE to force Grbl to always set the machine origin at bottom left. --- grbl/config.h | 20 ++++++++++++-------- grbl/limits.c | 12 ++++++++++-- grbl/system.c | 6 +++++- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/grbl/config.h b/grbl/config.h index 39913a4a..ffa1de7d 100644 --- a/grbl/config.h +++ b/grbl/config.h @@ -102,15 +102,16 @@ // 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< 0 || target[idx] < settings.max_travel[idx]) { return(true); } + #ifdef HOMING_FORCE_POSITIVE_SPACE + if (target[idx] < 0 || target[idx] > -settings.max_travel[idx]) { return(true); } + #else + if (target[idx] > 0 || target[idx] < settings.max_travel[idx]) { return(true); } + #endif #endif } return(false);