Skip to content

Commit 111d28d

Browse files
committed
Applied master branch bug fixes.
- Planner was under-estimating maximum speeds through straight junctions in certain cases. The calculations have been updated to be more accurate. - Strange sizeof() bug in the most recent releases. Manifested as an alarm upon a power up even when homing was disabled. Fixed by declaring sizeof() with struct types, rather than variable names, even though they were validated to give the same value. - Spindle speed zero should disable the spindle. Now fixed. - New configuration option for inverting certain limit pins. Handy for mixed NO and NC switch machines. See config.h for details.
1 parent 5eee108 commit 111d28d

9 files changed

Lines changed: 79 additions & 36 deletions

File tree

doc/log/commit_log_v1.0c.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
----------------
2+
Date: 2015-11-09
3+
Author: Sonny Jeon
4+
Subject: Pin state reporting of all pins. Flash optimization.
5+
6+
- New pin state realtime reporting feature. Instead of `Lim:000` for
7+
limit state reports, the new feature shows `Pin:000|0|0000`, or
8+
something similar. The `|` delimited fields indicate xyz limits, probe,
9+
and control pin states, where 0 is always not triggered, and 1 is
10+
triggered. Invert masks ARE accounted for.
11+
Each field may be enabled or disabled via the `$10` status report
12+
setting. The probe and control pin flags are bits 5 and 6, respectively.
13+
14+
- Remove the now deprecated `REPORT_CONTROL_PIN_STATE` option in
15+
config.h
16+
17+
- The old limit pin reports `Lim:000` may be re-enabled by commenting
18+
out `REPORT_ALL_PIN_STATES` in config.h.
19+
20+
- Incremented the version letter (v1.0c) to indicate the change in
21+
reporting style.
22+
23+
- Replaced all bit_true_atomic and bit_false_atomic macros with
24+
function calls. This saved a couple hundred bytes of flash.
25+

grbl/config.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
#define MESSAGE_PROBE_COORDINATES // Enabled by default. Comment to disable.
128128

129129
// Enables a second coolant control pin via the mist coolant g-code command M7 on the Arduino Uno
130-
// analog pin 5. Only use this option if you require a second coolant control pin.
130+
// analog pin 4. Only use this option if you require a second coolant control pin.
131131
// NOTE: The M8 flood coolant control pin on analog pin 4 will still be functional regardless.
132132
// #define ENABLE_M7 // Disabled by default. Uncomment to enable.
133133

@@ -157,6 +157,15 @@
157157
// the CONTROL_INVERT_MASK definition in cpu_map.h files.
158158
// #define INVERT_ALL_CONTROL_PINS // Default disabled. Uncomment to enable.
159159

160+
// Inverts select limit pin states based on the following mask. This effects all limit pin functions,
161+
// such as hard limits and homing. However, this is different from overall invert limits setting.
162+
// This build option will invert only the limit pins defined here, and then the invert limits setting
163+
// will be applied to all of them. This is useful when a user has a mixed set of limit pins with both
164+
// normally-open(NO) and normally-closed(NC) switches installed on their machine.
165+
// NOTE: PLEASE DO NOT USE THIS, unless you have a situation that needs it.
166+
// #define INVERT_LIMIT_PIN_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)) // Default disabled. Uncomment to enable.
167+
168+
160169
// Inverts the spindle enable pin from low-disabled/high-enabled to low-enabled/high-disabled. Useful
161170
// for some pre-built electronic boards.
162171
// NOTE: If VARIABLE_SPINDLE is enabled(default), this option has no effect as the PWM output and

grbl/gcode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ parser_block_t gc_block;
4040

4141
void gc_init()
4242
{
43-
memset(&gc_state, 0, sizeof(gc_state));
43+
memset(&gc_state, 0, sizeof(parser_state_t));
4444

4545
// Load default G54 coordinate system.
4646
if (!(settings_read_coord_data(gc_state.modal.coord_select,gc_state.coord_system))) {
@@ -80,7 +80,7 @@ uint8_t gc_execute_line(char *line)
8080
values struct, word tracking variables, and a non-modal commands tracker for the new
8181
block. This struct contains all of the necessary information to execute the block. */
8282

83-
memset(&gc_block, 0, sizeof(gc_block)); // Initialize the parser block struct.
83+
memset(&gc_block, 0, sizeof(parser_block_t)); // Initialize the parser block struct.
8484
memcpy(&gc_block.modal,&gc_state.modal,sizeof(gc_modal_t)); // Copy current modes
8585
uint8_t axis_command = AXIS_COMMAND_NONE;
8686
uint8_t axis_0, axis_1, axis_linear;

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.0c"
26-
#define GRBL_VERSION_BUILD "20151109"
26+
#define GRBL_VERSION_BUILD "20160304"
2727

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

grbl/limits.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ uint8_t limits_get_state()
7070
{
7171
uint8_t limit_state = 0;
7272
uint8_t pin = (LIMIT_PIN & LIMIT_MASK);
73+
#ifdef INVERT_LIMIT_PIN_MASK
74+
pin ^= INVERT_LIMIT_PIN_MASK;
75+
#endif
7376
if (bit_isfalse(settings.flags,BITFLAG_INVERT_LIMIT_PINS)) { pin ^= LIMIT_MASK; }
7477
if (pin) {
7578
uint8_t idx;

grbl/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ int main(void)
3434
stepper_init(); // Configure stepper pins and interrupt timers
3535
system_init(); // Configure pinout pins and pin-change interrupt
3636

37-
memset(&sys, 0, sizeof(sys)); // Clear all system variables
37+
memset(&sys, 0, sizeof(system_t)); // Clear all system variables
3838
sys.abort = true; // Set abort to complete initialization
3939
sei(); // Enable interrupts
4040

grbl/planner.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ static void planner_recalculate()
200200

201201
void plan_reset()
202202
{
203-
memset(&pl, 0, sizeof(pl)); // Clear planner struct
203+
memset(&pl, 0, sizeof(planner_t)); // Clear planner struct
204204
block_buffer_tail = 0;
205205
block_buffer_head = 0; // Empty = tail
206206
next_buffer_head = 1; // plan_next_block_index(block_buffer_head)
@@ -394,11 +394,11 @@ uint8_t plan_check_full_buffer()
394394
change the overall maximum entry speed conditions of all blocks.
395395
*/
396396
// NOTE: Computed without any expensive trig, sin() or acos(), by trig half angle identity of cos(theta).
397-
if (junction_cos_theta > 0.99) {
397+
if (junction_cos_theta > 0.999999) {
398398
// For a 0 degree acute junction, just set minimum junction speed.
399399
block->max_junction_speed_sqr = MINIMUM_JUNCTION_SPEED*MINIMUM_JUNCTION_SPEED;
400400
} else {
401-
junction_cos_theta = max(junction_cos_theta,-0.99); // Check for numerical round-off to avoid divide by zero.
401+
junction_cos_theta = max(junction_cos_theta,-0.999999); // Check for numerical round-off to avoid divide by zero.
402402
float sin_theta_d2 = sqrt(0.5*(1.0-junction_cos_theta)); // Trig half angle identity. Always positive.
403403

404404
// TODO: Technically, the acceleration used in calculation needs to be limited by the minimum of the

grbl/spindle_control.c

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -106,41 +106,47 @@ void spindle_set_state(uint8_t state, float rpm)
106106
#endif
107107

108108
// Calculate PWM register value based on rpm max/min settings and programmed rpm.
109-
if (settings.rpm_max <= settings.rpm_min) {
110-
// No PWM range possible. Set simple on/off spindle control pin state.
111-
current_pwm = PWM_MAX_VALUE;
112-
} else {
113-
if (rpm > settings.rpm_max) { rpm = settings.rpm_max; }
114-
if (rpm < settings.rpm_min) { rpm = settings.rpm_min; }
115-
#ifdef SPINDLE_MINIMUM_PWM
116-
float pwm_gradient = (PWM_MAX_VALUE-SPINDLE_MINIMUM_PWM)/(settings.rpm_max-settings.rpm_min);
117-
current_pwm = floor( (rpm-settings.rpm_min)*pwm_gradient + (SPINDLE_MINIMUM_PWM+0.5));
118-
#else
119-
float pwm_gradient = (PWM_MAX_VALUE)/(settings.rpm_max-settings.rpm_min);
120-
current_pwm = floor( (rpm-settings.rpm_min)*pwm_gradient + 0.5);
109+
if (rpm <= 0.0) { spindle_stop(); } // RPM should never be negative, but check anyway.
110+
else {
111+
if (settings.rpm_max <= settings.rpm_min) {
112+
// No PWM range possible. Set simple on/off spindle control pin state.
113+
current_pwm = PWM_MAX_VALUE;
114+
} else {
115+
if (rpm > settings.rpm_max) { rpm = settings.rpm_max; }
116+
if (rpm < settings.rpm_min) { rpm = settings.rpm_min; }
117+
#ifdef SPINDLE_MINIMUM_PWM
118+
float pwm_gradient = (PWM_MAX_VALUE-SPINDLE_MINIMUM_PWM)/(settings.rpm_max-settings.rpm_min);
119+
current_pwm = floor( (rpm-settings.rpm_min)*pwm_gradient + (SPINDLE_MINIMUM_PWM+0.5));
120+
#else
121+
float pwm_gradient = (PWM_MAX_VALUE)/(settings.rpm_max-settings.rpm_min);
122+
current_pwm = floor( (rpm-settings.rpm_min)*pwm_gradient + 0.5);
123+
#endif
124+
}
125+
126+
OCR_REGISTER = current_pwm; // Set PWM output level.
127+
TCCRA_REGISTER |= (1<<COMB_BIT); // Ensure PWM output is enabled.
128+
129+
// On the Uno, spindle enable and PWM are shared, unless otherwise specified.
130+
#if defined(CPU_MAP_ATMEGA2560) || defined(USE_SPINDLE_DIR_AS_ENABLE_PIN)
131+
#ifdef INVERT_SPINDLE_ENABLE_PIN
132+
SPINDLE_ENABLE_PORT &= ~(1<<SPINDLE_ENABLE_BIT);
133+
#else
134+
SPINDLE_ENABLE_PORT |= (1<<SPINDLE_ENABLE_BIT);
135+
#endif
121136
#endif
122137
}
123138

124-
OCR_REGISTER = current_pwm; // Set PWM output level.
125-
TCCRA_REGISTER |= (1<<COMB_BIT); // Ensure PWM output is enabled.
126-
127-
// On the Uno, spindle enable and PWM are shared, unless otherwise specified.
128-
#if defined(CPU_MAP_ATMEGA2560) || defined(USE_SPINDLE_DIR_AS_ENABLE_PIN)
139+
#else
140+
141+
if (rpm <= 0.0) { spindle_stop(); } // RPM should never be negative, but check anyway.
142+
else {
129143
#ifdef INVERT_SPINDLE_ENABLE_PIN
130144
SPINDLE_ENABLE_PORT &= ~(1<<SPINDLE_ENABLE_BIT);
131145
#else
132146
SPINDLE_ENABLE_PORT |= (1<<SPINDLE_ENABLE_BIT);
133147
#endif
134-
#endif
148+
}
135149

136-
#else
137-
138-
#ifdef INVERT_SPINDLE_ENABLE_PIN
139-
SPINDLE_ENABLE_PORT &= ~(1<<SPINDLE_ENABLE_BIT);
140-
#else
141-
SPINDLE_ENABLE_PORT |= (1<<SPINDLE_ENABLE_BIT);
142-
#endif
143-
144150
#endif
145151

146152
}

grbl/stepper.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ void st_reset()
462462
st_go_idle();
463463

464464
// Initialize stepper algorithm variables.
465-
memset(&prep, 0, sizeof(prep));
466-
memset(&st, 0, sizeof(st));
465+
memset(&prep, 0, sizeof(st_prep_t));
466+
memset(&st, 0, sizeof(stepper_t));
467467
st.exec_segment = NULL;
468468
pl_block = NULL; // Planner block pointer used by segment buffer
469469
segment_buffer_tail = 0;

0 commit comments

Comments
 (0)