v1.0 Beta Release.
- Tons of new stuff in this release, which is fairly stable and well tested. However, much more is coming soon! - Real-time parking motion with safety door. When this compile option is enabled, an opened safety door will cause Grbl to automatically feed hold, retract, de-energize the spindle/coolant, and parks near Z max. After the door is closed and resume is commanded, this reverses and the program continues as if nothing happened. This is also highly configurable. See config.h for details. - New spindle max and min rpm ‘$’ settings! This has been requested often. Grbl will output 5V when commanded to turn on the spindle at its max rpm, and 0.02V with min rpm. The voltage and the rpm range are linear to each other. This should help users tweak their settings to get close to true rpm’s. - If the new max rpm ‘$’ setting is set = 0 or less than min rpm, the spindle speed PWM pin will act like a regular on/off spindle enable pin. On pin D11. - BEWARE: Your old EEPROM settings will be wiped! The new spindle rpm settings require a new settings version, so Grbl will automatically wipe and restore the EEPROM with the new defaults. - Control pin can now be inverted individually with a CONTROL_INVERT_MASK in the cpu_map header file. Not typical for users to need this, but handy to have. - Fixed bug when Grbl receive too many characters in a line and overflows. Previously it would respond with an error per overflow character and another acknowledge upon an EOL character. This broke the streaming protocol. Now fixed to only respond with an error after an EOL character. - Fixed a bug with the safety door during an ALARM mode. You now can’t home or unlock the axes until the safety door has been closed. This is for safety reasons (obviously.) - Tweaked some the Mega2560 cpu_map settings . Increased segment buffer size and fixed the spindle PWM settings to output at a higher PWM frequency. - Generalized the delay function used by G4 delay for use by parking motion. Allows non-blocking status reports and real-time control during re-energizing of the spindle and coolant. - Added spindle rpm max and min defaults to default.h files. - Added a new print float for rpm values.
This commit is contained in:
@ -24,21 +24,33 @@
|
||||
|
||||
void spindle_init()
|
||||
{
|
||||
// Configure variable spindle PWM and enable pin, if requried. On the Uno, PWM and enable are
|
||||
// combined unless configured otherwise.
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
|
||||
// Configure variable spindle PWM and enable pin, if requried. On the Uno, PWM and enable are
|
||||
// combined unless configured otherwise.
|
||||
SPINDLE_PWM_DDR |= (1<<SPINDLE_PWM_BIT); // Configure as PWM output pin.
|
||||
#if defined(CPU_MAP_ATMEGA2560) || defined(USE_SPINDLE_DIR_AS_ENABLE_PIN)
|
||||
TCCRA_REGISTER = TCCRA_INIT_MASK; // Configure PWM output compare timer
|
||||
TCCRB_REGISTER = TCCRB_INIT_MASK;
|
||||
#ifdef CPU_MAP_ATMEGA2560
|
||||
OCRA_REGISTER = OCRA_TOP_VALUE; // Set the top value for 16-bit fast PWM mode
|
||||
SPINDLE_ENABLE_DDR |= (1<<SPINDLE_ENABLE_BIT); // Configure as output pin.
|
||||
SPINDLE_DIRECTION_DDR |= (1<<SPINDLE_DIRECTION_BIT); // Configure as output pin.
|
||||
#else // Otherwise 328p
|
||||
#ifdef USE_SPINDLE_DIR_AS_ENABLE_PIN
|
||||
SPINDLE_ENABLE_DDR |= (1<<SPINDLE_ENABLE_BIT); // Configure as output pin.
|
||||
#else
|
||||
SPINDLE_DIRECTION_DDR |= (1<<SPINDLE_DIRECTION_BIT); // Configure as output pin.
|
||||
#endif
|
||||
#endif
|
||||
// Configure no variable spindle and only enable pin.
|
||||
#else
|
||||
SPINDLE_ENABLE_DDR |= (1<<SPINDLE_ENABLE_BIT); // Configure as output pin.
|
||||
#endif
|
||||
|
||||
#ifndef USE_SPINDLE_DIR_AS_ENABLE_PIN
|
||||
#else
|
||||
|
||||
// Configure no variable spindle and only enable pin.
|
||||
SPINDLE_ENABLE_DDR |= (1<<SPINDLE_ENABLE_BIT); // Configure as output pin.
|
||||
SPINDLE_DIRECTION_DDR |= (1<<SPINDLE_DIRECTION_BIT); // Configure as output pin.
|
||||
|
||||
#endif
|
||||
|
||||
spindle_stop();
|
||||
}
|
||||
|
||||
@ -50,23 +62,25 @@ void spindle_stop()
|
||||
TCCRA_REGISTER &= ~(1<<COMB_BIT); // Disable PWM. Output voltage is zero.
|
||||
#if defined(CPU_MAP_ATMEGA2560) || defined(USE_SPINDLE_DIR_AS_ENABLE_PIN)
|
||||
#ifdef INVERT_SPINDLE_ENABLE_PIN
|
||||
SPINDLE_ENABLE_PORT |= (1<<SPINDLE_ENABLE_BIT); // Set pin to high
|
||||
#else
|
||||
SPINDLE_ENABLE_PORT &= ~(1<<SPINDLE_ENABLE_BIT); // Set pin to low
|
||||
#endif
|
||||
SPINDLE_ENABLE_PORT |= (1<<SPINDLE_ENABLE_BIT); // Set pin to high
|
||||
#else
|
||||
SPINDLE_ENABLE_PORT &= ~(1<<SPINDLE_ENABLE_BIT); // Set pin to low
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#ifdef INVERT_SPINDLE_ENABLE_PIN
|
||||
SPINDLE_ENABLE_PORT |= (1<<SPINDLE_ENABLE_BIT); // Set pin to high
|
||||
#else
|
||||
SPINDLE_ENABLE_PORT &= ~(1<<SPINDLE_ENABLE_BIT); // Set pin to low
|
||||
#endif
|
||||
SPINDLE_ENABLE_PORT |= (1<<SPINDLE_ENABLE_BIT); // Set pin to high
|
||||
#else
|
||||
SPINDLE_ENABLE_PORT &= ~(1<<SPINDLE_ENABLE_BIT); // Set pin to low
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void spindle_set_state(uint8_t state, float rpm)
|
||||
{
|
||||
if (sys.abort) { return; } // Block during abort.
|
||||
|
||||
// Halt or set spindle direction and rpm.
|
||||
if (state == SPINDLE_DISABLE) {
|
||||
|
||||
@ -83,29 +97,32 @@ void spindle_set_state(uint8_t state, float rpm)
|
||||
#endif
|
||||
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
|
||||
// TODO: Install the optional capability for frequency-based output for servos.
|
||||
#ifdef CPU_MAP_ATMEGA2560
|
||||
TCCRA_REGISTER = (1<<COMB_BIT) | (1<<WAVE1_REGISTER) | (1<<WAVE0_REGISTER);
|
||||
TCCRB_REGISTER = (TCCRB_REGISTER & 0b11111000) | 0x02 | (1<<WAVE2_REGISTER) | (1<<WAVE3_REGISTER); // set to 1/8 Prescaler
|
||||
OCR4A = 0xFFFF; // set the top 16bit value
|
||||
uint16_t current_pwm;
|
||||
uint16_t current_pwm; // 2560 PWM register is 16-bit.
|
||||
#else
|
||||
TCCRA_REGISTER = (1<<COMB_BIT) | (1<<WAVE1_REGISTER) | (1<<WAVE0_REGISTER);
|
||||
TCCRB_REGISTER = (TCCRB_REGISTER & 0b11111000) | 0x02; // set to 1/8 Prescaler
|
||||
uint8_t current_pwm;
|
||||
uint8_t current_pwm; // 328p PWM register is 8-bit.
|
||||
#endif
|
||||
|
||||
#define SPINDLE_RPM_RANGE (SPINDLE_MAX_RPM-SPINDLE_MIN_RPM)
|
||||
if ( rpm < SPINDLE_MIN_RPM ) { rpm = 0; }
|
||||
else {
|
||||
rpm -= SPINDLE_MIN_RPM;
|
||||
if ( rpm > SPINDLE_RPM_RANGE ) { rpm = SPINDLE_RPM_RANGE; } // Prevent integer overflow
|
||||
// Calculate PWM register value based on rpm max/min settings and programmed rpm.
|
||||
if (settings.rpm_max <= settings.rpm_min) {
|
||||
// No PWM range possible. Set simple on/off spindle control pin state.
|
||||
current_pwm = PWM_MAX_VALUE;
|
||||
} else {
|
||||
if (rpm > settings.rpm_max) { rpm = settings.rpm_max; }
|
||||
if (rpm < settings.rpm_min) { rpm = settings.rpm_min; }
|
||||
#ifdef SPINDLE_MINIMUM_PWM
|
||||
float pwm_gradient = (PWM_MAX_VALUE-SPINDLE_MINIMUM_PWM)/(settings.rpm_max-settings.rpm_min);
|
||||
current_pwm = floor( (rpm-settings.rpm_min)*pwm_gradient + (SPINDLE_MINIMUM_PWM+0.5));
|
||||
#else
|
||||
float pwm_gradient = (PWM_MAX_VALUE)/(settings.rpm_max-settings.rpm_min);
|
||||
current_pwm = floor( (rpm-settings.rpm_min)*pwm_gradient + 0.5);
|
||||
#endif
|
||||
}
|
||||
current_pwm = floor( rpm*(PWM_MAX_VALUE/SPINDLE_RPM_RANGE) + 0.5);
|
||||
#ifdef MINIMUM_SPINDLE_PWM
|
||||
if (current_pwm < MINIMUM_SPINDLE_PWM) { current_pwm = MINIMUM_SPINDLE_PWM; }
|
||||
#endif
|
||||
OCR_REGISTER = current_pwm; // Set PWM pin output
|
||||
|
||||
OCR_REGISTER = current_pwm; // Set PWM output level.
|
||||
TCCRA_REGISTER |= (1<<COMB_BIT); // Ensure PWM output is enabled.
|
||||
|
||||
// On the Uno, spindle enable and PWM are shared, unless otherwise specified.
|
||||
#if defined(CPU_MAP_ATMEGA2560) || defined(USE_SPINDLE_DIR_AS_ENABLE_PIN)
|
||||
@ -116,12 +133,14 @@ void spindle_set_state(uint8_t state, float rpm)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#else
|
||||
#else
|
||||
|
||||
#ifdef INVERT_SPINDLE_ENABLE_PIN
|
||||
SPINDLE_ENABLE_PORT &= ~(1<<SPINDLE_ENABLE_BIT);
|
||||
#else
|
||||
SPINDLE_ENABLE_PORT |= (1<<SPINDLE_ENABLE_BIT);
|
||||
#endif
|
||||
SPINDLE_ENABLE_PORT &= ~(1<<SPINDLE_ENABLE_BIT);
|
||||
#else
|
||||
SPINDLE_ENABLE_PORT |= (1<<SPINDLE_ENABLE_BIT);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user