kopia lustrzana https://github.com/gnea/grbl
Merge 2165218f13
into bfb67f0c79
commit
4f1b3fbcb1
|
@ -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
|
||||
|
|
|
@ -141,10 +141,15 @@
|
|||
|
||||
// Prescaled, 8-bit Fast PWM mode.
|
||||
#define SPINDLE_TCCRA_INIT_MASK ((1<<WGM20) | (1<<WGM21)) // Configures fast PWM mode.
|
||||
|
||||
#ifdef SPINDLE_IS_SERVO
|
||||
#define SPINDLE_TCCRB_INIT_MASK ((1<<CS22) | (1<<CS21) | (1<<CS20)) // 1/1024 prescaler -> 61Hz (for Servo)
|
||||
#else
|
||||
// #define SPINDLE_TCCRB_INIT_MASK (1<<CS20) // Disable prescaler -> 62.5kHz
|
||||
// #define SPINDLE_TCCRB_INIT_MASK (1<<CS21) // 1/8 prescaler -> 7.8kHz (Used in v0.9)
|
||||
// #define SPINDLE_TCCRB_INIT_MASK ((1<<CS21) | (1<<CS20)) // 1/32 prescaler -> 1.96kHz
|
||||
#define SPINDLE_TCCRB_INIT_MASK (1<<CS22) // 1/64 prescaler -> 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
|
||||
|
|
|
@ -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<<SPINDLE_ENABLE_BIT); // Set pin to low
|
||||
#endif
|
||||
#endif
|
||||
if (!(settings.flags & BITFLAG_LASER_MODE)) {
|
||||
#ifdef SPINDLE_IS_SERVO
|
||||
SPINDLE_TCCRA_REGISTER |= (1<<SPINDLE_COMB_BIT); // Ensure PWM output is enabled.
|
||||
#ifdef SERVO_INVERT
|
||||
SPINDLE_OCR_REGISTER = SERVO_LONG;
|
||||
#else
|
||||
SPINDLE_OCR_REGISTER = SERVO_SHORT;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -135,7 +144,15 @@ void spindle_stop()
|
|||
}
|
||||
#else
|
||||
if (pwm_value == SPINDLE_PWM_OFF_VALUE) {
|
||||
if (!(settings.flags & BITFLAG_LASER_MODE)) {
|
||||
#ifndef SPINDLE_IS_SERVO
|
||||
SPINDLE_TCCRA_REGISTER &= ~(1<<SPINDLE_COMB_BIT); // Disable PWM. Output voltage is zero.
|
||||
#else
|
||||
spindle_stop();
|
||||
#endif
|
||||
} else {
|
||||
SPINDLE_TCCRA_REGISTER &= ~(1<<SPINDLE_COMB_BIT); // Disable PWM. Output voltage is zero.
|
||||
}
|
||||
} else {
|
||||
SPINDLE_TCCRA_REGISTER |= (1<<SPINDLE_COMB_BIT); // Ensure PWM output is enabled.
|
||||
}
|
||||
|
@ -212,6 +229,17 @@ void spindle_stop()
|
|||
sys.spindle_speed = rpm;
|
||||
pwm_value = floor((rpm-settings.rpm_min)*pwm_gradient) + SPINDLE_PWM_MIN_VALUE;
|
||||
}
|
||||
|
||||
if (!(settings.flags & BITFLAG_LASER_MODE)) {
|
||||
#ifdef SPINDLE_IS_SERVO
|
||||
#ifdef SERVO_INVERT
|
||||
pwm_value = floor(SERVO_LONG - rpm*(SERVO_RANGE/(settings.rpm_max-settings.rpm_min)));
|
||||
#else
|
||||
pwm_value = floor(rpm*(SERVO_RANGE/(settings.rpm_max-settings.rpm_min))+SERVO_SHORT);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
return(pwm_value);
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue