diff --git a/README.md b/README.md index ec951559..f6bb2018 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,15 @@ ![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 (swichable in config.h)_ + +- 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. + *** + 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. diff --git a/grbl/config.h b/grbl/config.h index 063e6767..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< 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 diff --git a/grbl/limits.c b/grbl/limits.c index 3cc2556b..a99e77ae 100644 --- a/grbl/limits.c +++ b/grbl/limits.c @@ -307,9 +307,17 @@ void limits_go_home(uint8_t cycle_mask) set_axis_position = 0; #else if ( bit_istrue(settings.homing_dir_mask,bit(idx)) ) { - set_axis_position = lround((settings.max_travel[idx]+settings.homing_pulloff)*settings.steps_per_mm[idx]); + #ifdef HOMING_FORCE_POSITIVE_SPACE + set_axis_position = 0; //lround(settings.homing_pulloff*settings.steps_per_mm[idx]); + #else + set_axis_position = lround((settings.max_travel[idx]+settings.homing_pulloff)*settings.steps_per_mm[idx]); + #endif } else { - set_axis_position = lround(-settings.homing_pulloff*settings.steps_per_mm[idx]); + #ifdef HOMING_FORCE_POSITIVE_SPACE + set_axis_position = lround((-settings.max_travel[idx]-settings.homing_pulloff)*settings.steps_per_mm[idx]); + #else + set_axis_position = lround(-settings.homing_pulloff*settings.steps_per_mm[idx]); + #endif } #endif diff --git a/grbl/spindle_control.c b/grbl/spindle_control.c index a66a8688..37abcb14 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<= settings.rpm_max) || (rpm >= settings.rpm_max)) { // No PWM range possible. Set simple on/off spindle control pin state. @@ -149,8 +151,13 @@ void spindle_stop() 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; + #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; @@ -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 { diff --git a/grbl/system.c b/grbl/system.c index d1665fff..275c7540 100644 --- a/grbl/system.c +++ b/grbl/system.c @@ -342,7 +342,11 @@ uint8_t system_check_travel_limits(float *target) } #else // NOTE: max_travel is stored as negative - if (target[idx] > 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);