Spindle speed close to minimum fix.

- When spindle speed is close to the minimum rpm, the PWM value would
be zero or lower than allowed. The computation error was caused by
setting the minimum PWM value to zero, when it should have been 1.

- Added a compiler check for minimum PWM to be greater than zero.

- Moved some of the spindle PWM macros to a more appropriate place in
the cpu_map.h.
pull/800/head
Sonny Jeon 2016-10-23 13:55:50 -06:00
rodzic 8e638f0054
commit 498dd62572
6 zmienionych plików z 72 dodań i 18 usunięć

Wyświetl plik

@ -1,3 +1,47 @@
----------------
Date: 2016-10-22
Author: Will Winder
Subject: Minor VARIABLE_SPINDLE feature toggle refactoring (#16)
* Modify code CSV format.
- Wrap value in quotes to avoid issue with embedded commas. This occurs
in one of the alarm codes.
- Change header row format to allow same parsing code as data rows.
* VARIABLE_SPINDLE feature flag experiment.
- Use a macro for 'spindle_set_speed' and 'spindle_sync' to reduce the
number of required VARIABLE_SPINDLE checks.
----------------
Date: 2016-10-18
Author: Sonny Jeon
Subject: Improved option for v0.9 GUI compatibility.
- Addressed an issue with backward compatibility with Grbl v0.9-style
GUIs.
- It still may not work due to new data and states coming back from
Grbl v1.1. Regardless, DO NOT TRY TO USE THE COMPATIBILITY MODE UNTIL
THERE IS A REALLY GOOD REASON TO.
- v0.9 GUI compatibility mode will be removed in future versions.
Youve been warned. Its highly recommended for GUIs to update to the
new v1.1 interface.
- Compability mode will only fit on an Arduino Uno due to size
increases.
- Removed the REPORT_GUI_MODE compile option since its part of the
v1.1 interface standard.
- Updated the documentation to better describe the compatibility mode
build option.
----------------
Date: 2016-10-17
Author: Sonny Jeon

Wyświetl plik

@ -360,7 +360,8 @@
// setting, like rpm max to max PWM. So the variable spindle pin will not output the voltage range between
// 0V for disabled and the voltage set by the minimum PWM for minimum rpm.
// NOTE: Compute duty cycle at the minimum PWM by this equation: (% duty cycle)=(SPINDLE_MINIMUM_PWM/256)*100
// #define SPINDLE_MINIMUM_PWM 5 // Default disabled. Uncomment to enable. Integer (0-255)
// Value must be greater than zero.
// #define SPINDLE_MINIMUM_PWM 5 // Default disabled. Uncomment to enable. Integer (1-255)
// By default on a 328p(Uno), Grbl combines the variable spindle PWM and the enable into one pin to help
// preserve I/O pins. For certain setups, these may need to be separate pins. This configure option uses
@ -580,6 +581,12 @@
#endif
#endif
#if defined(SPINDLE_MINIMUM_PWM)
#if !(SPINDLE_MINIMUM_PWM > 0)
#error "SPINDLE_MINIMUM_PWM must be greater than zero."
#endif
#endif
/* ---------------------------------------------------------------------------------------
OEM Single File Configuration Option

Wyświetl plik

@ -125,7 +125,13 @@
// 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.
#ifdef SPINDLE_MINIMUM_PWM
#define SPINDLE_PWM_MIN_VALUE SPINDLE_MINIMUM_PWM
#else
#define SPINDLE_PWM_MIN_VALUE 1 // Must be greater than zero.
#endif
#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
#define SPINDLE_OCR_REGISTER OCR2A

Wyświetl plik

@ -23,7 +23,7 @@
// Grbl versioning system
#define GRBL_VERSION "1.1d"
#define GRBL_VERSION_BUILD "20161018"
#define GRBL_VERSION_BUILD "20161023"
// Define standard libraries used by Grbl.
#include <avr/io.h>

Wyświetl plik

@ -734,7 +734,7 @@ void report_realtime_status()
uint8_t sp_state = spindle_get_state();
uint8_t cl_state = coolant_get_state();
if (sp_state || cl_state) {
if (sp_state | cl_state) {
printPgmString(PSTR(",A:"));
if (sp_state) { // != SPINDLE_STATE_DISABLE
#ifdef VARIABLE_SPINDLE

Wyświetl plik

@ -22,13 +22,6 @@
#include "grbl.h"
#ifdef SPINDLE_MINIMUM_PWM
#define SPINDLE_PWM_MIN_VALUE SPINDLE_MINIMUM_PWM
#else
#define SPINDLE_PWM_MIN_VALUE 0.0
#endif
#define SPINDLE_PWM_RANGE (SPINDLE_PWM_MAX_VALUE-SPINDLE_PWM_MIN_VALUE)
#ifdef VARIABLE_SPINDLE
static float pwm_gradient; // Precalulated value to speed up rpm to PWM conversions.
#endif
@ -142,24 +135,28 @@ void spindle_stop()
// Called by spindle_set_state() and step segment generator. Keep routine small and efficient.
uint8_t spindle_compute_pwm_value(float rpm) // 328p PWM register is 8-bit.
{
uint8_t pwm_value;
rpm *= (0.01*sys.spindle_speed_ovr); // Scale by spindle speed override value.
// 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;
return(SPINDLE_PWM_MAX_VALUE);
} else if (rpm < settings.rpm_min) {
if (rpm == 0.0) {
pwm_value = SPINDLE_PWM_MAX_VALUE;
} else if (rpm <= settings.rpm_min) {
if (rpm == 0.0) { // S0 disables spindle
sys.spindle_speed = 0.0;
return(SPINDLE_PWM_OFF_VALUE); }
else {
pwm_value = SPINDLE_PWM_OFF_VALUE;
} else { // Set minimum PWM output
sys.spindle_speed = settings.rpm_min;
return(SPINDLE_PWM_MIN_VALUE);
pwm_value = SPINDLE_PWM_MIN_VALUE;
}
} else {
} else {
// Compute intermediate PWM value with linear spindle speed model.
// NOTE: A nonlinear model could be installed here, if required, but keep it light-weight.
sys.spindle_speed = rpm;
return(floor( (rpm-settings.rpm_min)*pwm_gradient + (SPINDLE_PWM_MIN_VALUE+0.5)));
pwm_value = floor( (rpm-settings.rpm_min)*pwm_gradient + (SPINDLE_PWM_MIN_VALUE+0.5));
}
return(pwm_value);
}
#endif