Skip to content

Commit 498dd62

Browse files
committed
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.
1 parent 8e638f0 commit 498dd62

6 files changed

Lines changed: 72 additions & 18 deletions

File tree

doc/log/commit_log_v1.1.txt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1+
----------------
2+
Date: 2016-10-22
3+
Author: Will Winder
4+
Subject: Minor VARIABLE_SPINDLE feature toggle refactoring (#16)
5+
6+
* Modify code CSV format.
7+
8+
- Wrap value in quotes to avoid issue with embedded commas. This occurs
9+
in one of the alarm codes.
10+
11+
- Change header row format to allow same parsing code as data rows.
12+
13+
* VARIABLE_SPINDLE feature flag experiment.
14+
15+
- Use a macro for 'spindle_set_speed' and 'spindle_sync' to reduce the
16+
number of required VARIABLE_SPINDLE checks.
17+
18+
19+
----------------
20+
Date: 2016-10-18
21+
Author: Sonny Jeon
22+
Subject: Improved option for v0.9 GUI compatibility.
23+
24+
- Addressed an issue with backward compatibility with Grbl v0.9-style
25+
GUIs.
26+
27+
- It still may not work due to new data and states coming back from
28+
Grbl v1.1. Regardless, DO NOT TRY TO USE THE COMPATIBILITY MODE UNTIL
29+
THERE IS A REALLY GOOD REASON TO.
30+
31+
- v0.9 GUI compatibility mode will be removed in future versions.
32+
You’ve been warned. It’s highly recommended for GUIs to update to the
33+
new v1.1 interface.
34+
35+
- Compability mode will only fit on an Arduino Uno due to size
36+
increases.
37+
38+
- Removed the REPORT_GUI_MODE compile option since it’s part of the
39+
v1.1 interface standard.
40+
41+
- Updated the documentation to better describe the compatibility mode
42+
build option.
43+
44+
145
----------------
246
Date: 2016-10-17
347
Author: Sonny Jeon

grbl/config.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@
360360
// setting, like rpm max to max PWM. So the variable spindle pin will not output the voltage range between
361361
// 0V for disabled and the voltage set by the minimum PWM for minimum rpm.
362362
// NOTE: Compute duty cycle at the minimum PWM by this equation: (% duty cycle)=(SPINDLE_MINIMUM_PWM/256)*100
363-
// #define SPINDLE_MINIMUM_PWM 5 // Default disabled. Uncomment to enable. Integer (0-255)
363+
// Value must be greater than zero.
364+
// #define SPINDLE_MINIMUM_PWM 5 // Default disabled. Uncomment to enable. Integer (1-255)
364365

365366
// By default on a 328p(Uno), Grbl combines the variable spindle PWM and the enable into one pin to help
366367
// preserve I/O pins. For certain setups, these may need to be separate pins. This configure option uses
@@ -580,6 +581,12 @@
580581
#endif
581582
#endif
582583

584+
#if defined(SPINDLE_MINIMUM_PWM)
585+
#if !(SPINDLE_MINIMUM_PWM > 0)
586+
#error "SPINDLE_MINIMUM_PWM must be greater than zero."
587+
#endif
588+
#endif
589+
583590
/* ---------------------------------------------------------------------------------------
584591
OEM Single File Configuration Option
585592

grbl/cpu_map.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,13 @@
125125
// Variable spindle configuration below. Do not change unless you know what you are doing.
126126
// NOTE: Only used when variable spindle is enabled.
127127
#define SPINDLE_PWM_MAX_VALUE 255 // Don't change. 328p fast PWM mode fixes top value as 255.
128+
#ifdef SPINDLE_MINIMUM_PWM
129+
#define SPINDLE_PWM_MIN_VALUE SPINDLE_MINIMUM_PWM
130+
#else
131+
#define SPINDLE_PWM_MIN_VALUE 1 // Must be greater than zero.
132+
#endif
128133
#define SPINDLE_PWM_OFF_VALUE 0
134+
#define SPINDLE_PWM_RANGE (SPINDLE_PWM_MAX_VALUE-SPINDLE_PWM_MIN_VALUE)
129135
#define SPINDLE_TCCRA_REGISTER TCCR2A
130136
#define SPINDLE_TCCRB_REGISTER TCCR2B
131137
#define SPINDLE_OCR_REGISTER OCR2A

grbl/grbl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
// Grbl versioning system
2525
#define GRBL_VERSION "1.1d"
26-
#define GRBL_VERSION_BUILD "20161018"
26+
#define GRBL_VERSION_BUILD "20161023"
2727

2828
// Define standard libraries used by Grbl.
2929
#include <avr/io.h>

grbl/report.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ void report_realtime_status()
734734

735735
uint8_t sp_state = spindle_get_state();
736736
uint8_t cl_state = coolant_get_state();
737-
if (sp_state || cl_state) {
737+
if (sp_state | cl_state) {
738738
printPgmString(PSTR(",A:"));
739739
if (sp_state) { // != SPINDLE_STATE_DISABLE
740740
#ifdef VARIABLE_SPINDLE

grbl/spindle_control.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@
2222
#include "grbl.h"
2323

2424

25-
#ifdef SPINDLE_MINIMUM_PWM
26-
#define SPINDLE_PWM_MIN_VALUE SPINDLE_MINIMUM_PWM
27-
#else
28-
#define SPINDLE_PWM_MIN_VALUE 0.0
29-
#endif
30-
#define SPINDLE_PWM_RANGE (SPINDLE_PWM_MAX_VALUE-SPINDLE_PWM_MIN_VALUE)
31-
3225
#ifdef VARIABLE_SPINDLE
3326
static float pwm_gradient; // Precalulated value to speed up rpm to PWM conversions.
3427
#endif
@@ -142,24 +135,28 @@ void spindle_stop()
142135
// Called by spindle_set_state() and step segment generator. Keep routine small and efficient.
143136
uint8_t spindle_compute_pwm_value(float rpm) // 328p PWM register is 8-bit.
144137
{
138+
uint8_t pwm_value;
145139
rpm *= (0.01*sys.spindle_speed_ovr); // Scale by spindle speed override value.
146140
// Calculate PWM register value based on rpm max/min settings and programmed rpm.
147141
if ((settings.rpm_min >= settings.rpm_max) || (rpm >= settings.rpm_max)) {
148142
// No PWM range possible. Set simple on/off spindle control pin state.
149143
sys.spindle_speed = settings.rpm_max;
150-
return(SPINDLE_PWM_MAX_VALUE);
151-
} else if (rpm < settings.rpm_min) {
152-
if (rpm == 0.0) {
144+
pwm_value = SPINDLE_PWM_MAX_VALUE;
145+
} else if (rpm <= settings.rpm_min) {
146+
if (rpm == 0.0) { // S0 disables spindle
153147
sys.spindle_speed = 0.0;
154-
return(SPINDLE_PWM_OFF_VALUE); }
155-
else {
148+
pwm_value = SPINDLE_PWM_OFF_VALUE;
149+
} else { // Set minimum PWM output
156150
sys.spindle_speed = settings.rpm_min;
157-
return(SPINDLE_PWM_MIN_VALUE);
151+
pwm_value = SPINDLE_PWM_MIN_VALUE;
158152
}
159-
} else {
153+
} else {
154+
// Compute intermediate PWM value with linear spindle speed model.
155+
// NOTE: A nonlinear model could be installed here, if required, but keep it light-weight.
160156
sys.spindle_speed = rpm;
161-
return(floor( (rpm-settings.rpm_min)*pwm_gradient + (SPINDLE_PWM_MIN_VALUE+0.5)));
157+
pwm_value = floor( (rpm-settings.rpm_min)*pwm_gradient + (SPINDLE_PWM_MIN_VALUE+0.5));
162158
}
159+
return(pwm_value);
163160
}
164161
#endif
165162

0 commit comments

Comments
 (0)