Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto sleep stepper #1172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions grbl/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#define DEFAULT_STEPPING_INVERT_MASK 0
#define DEFAULT_DIRECTION_INVERT_MASK 0
#define DEFAULT_STEPPER_IDLE_LOCK_TIME 25 // msec (0-254, 255 keeps steppers enabled)
#define DEFAULT_AUTOSLEEP 10 // minutes
#define DEFAULT_STATUS_REPORT_MASK 1 // MPos enabled
#define DEFAULT_JUNCTION_DEVIATION 0.01 // mm
#define DEFAULT_ARC_TOLERANCE 0.002 // mm
Expand Down Expand Up @@ -89,6 +90,7 @@
#define DEFAULT_STEPPING_INVERT_MASK 0
#define DEFAULT_DIRECTION_INVERT_MASK ((1<<Y_AXIS)|(1<<Z_AXIS))
#define DEFAULT_STEPPER_IDLE_LOCK_TIME 25 // msec (0-254, 255 keeps steppers enabled)
#define DEFAULT_AUTOSLEEP 10 // minutes
#define DEFAULT_STATUS_REPORT_MASK 1 // MPos enabled
#define DEFAULT_JUNCTION_DEVIATION 0.01 // mm
#define DEFAULT_ARC_TOLERANCE 0.002 // mm
Expand Down Expand Up @@ -127,6 +129,7 @@
#define DEFAULT_STEPPING_INVERT_MASK 0
#define DEFAULT_DIRECTION_INVERT_MASK ((1<<Y_AXIS)|(1<<Z_AXIS))
#define DEFAULT_STEPPER_IDLE_LOCK_TIME 250 // msec (0-254, 255 keeps steppers enabled)
#define DEFAULT_AUTOSLEEP 10 // minutes
#define DEFAULT_STATUS_REPORT_MASK 3 // WPos enabled
#define DEFAULT_JUNCTION_DEVIATION 0.01 // mm
#define DEFAULT_ARC_TOLERANCE 0.002 // mm
Expand Down Expand Up @@ -172,6 +175,7 @@
#define DEFAULT_STEPPING_INVERT_MASK 0
#define DEFAULT_DIRECTION_INVERT_MASK ((1<<Y_AXIS)|(1<<Z_AXIS))
#define DEFAULT_STEPPER_IDLE_LOCK_TIME 255 // msec (0-254, 255 keeps steppers enabled)
#define DEFAULT_AUTOSLEEP 10 // minutes
#define DEFAULT_STATUS_REPORT_MASK 1 // MPos enabled
#define DEFAULT_JUNCTION_DEVIATION 0.02 // mm
#define DEFAULT_ARC_TOLERANCE 0.002 // mm
Expand Down Expand Up @@ -217,6 +221,7 @@
#define DEFAULT_STEPPING_INVERT_MASK 0
#define DEFAULT_DIRECTION_INVERT_MASK ((1<<X_AXIS)|(1<<Z_AXIS))
#define DEFAULT_STEPPER_IDLE_LOCK_TIME 255 // msec (0-254, 255 keeps steppers enabled)
#define DEFAULT_AUTOSLEEP 10 // minutes
#define DEFAULT_STATUS_REPORT_MASK 1 // MPos enabled
#define DEFAULT_JUNCTION_DEVIATION 0.02 // mm
#define DEFAULT_ARC_TOLERANCE 0.002 // mm
Expand Down Expand Up @@ -261,6 +266,7 @@
#define DEFAULT_STEPPING_INVERT_MASK 0
#define DEFAULT_DIRECTION_INVERT_MASK ((1<<X_AXIS)|(1<<Z_AXIS))
#define DEFAULT_STEPPER_IDLE_LOCK_TIME 255 // msec (0-254, 255 keeps steppers enabled)
#define DEFAULT_AUTOSLEEP 10 // minutes
#define DEFAULT_STATUS_REPORT_MASK 1 // MPos enabled
#define DEFAULT_JUNCTION_DEVIATION 0.02 // mm
#define DEFAULT_ARC_TOLERANCE 0.01 // mm
Expand Down Expand Up @@ -306,6 +312,7 @@
#define DEFAULT_STEPPING_INVERT_MASK 0
#define DEFAULT_DIRECTION_INVERT_MASK ((1<<X_AXIS)|(1<<Y_AXIS))
#define DEFAULT_STEPPER_IDLE_LOCK_TIME 255 // msec (0-254, 255 keeps steppers enabled)
#define DEFAULT_AUTOSLEEP 10 // minutes
#define DEFAULT_STATUS_REPORT_MASK 1 // MPos enabled
#define DEFAULT_JUNCTION_DEVIATION 0.02 // mm
#define DEFAULT_ARC_TOLERANCE 0.002 // mm
Expand Down Expand Up @@ -351,6 +358,7 @@
#define DEFAULT_STEPPING_INVERT_MASK 0
#define DEFAULT_DIRECTION_INVERT_MASK ((1<<X_AXIS)|(1<<Y_AXIS))
#define DEFAULT_STEPPER_IDLE_LOCK_TIME 255 // msec (0-254, 255 keeps steppers enabled)
#define DEFAULT_AUTOSLEEP 10 // minutes
#define DEFAULT_STATUS_REPORT_MASK 1 // MPos enabled
#define DEFAULT_JUNCTION_DEVIATION 0.02 // mm
#define DEFAULT_ARC_TOLERANCE 0.002 // mm
Expand Down Expand Up @@ -390,6 +398,7 @@
#define DEFAULT_STEPPING_INVERT_MASK 0
#define DEFAULT_DIRECTION_INVERT_MASK 0
#define DEFAULT_STEPPER_IDLE_LOCK_TIME 25 // msec (0-254, 255 keeps steppers enabled)
#define DEFAULT_AUTOSLEEP 10 // minutes
#define DEFAULT_STATUS_REPORT_MASK 1 // MPos enabled
#define DEFAULT_JUNCTION_DEVIATION 0.01 // mm
#define DEFAULT_ARC_TOLERANCE 0.002 // mm
Expand Down Expand Up @@ -429,6 +438,7 @@
#define DEFAULT_STEPPING_INVERT_MASK 0
#define DEFAULT_DIRECTION_INVERT_MASK 0
#define DEFAULT_STEPPER_IDLE_LOCK_TIME 25 // msec (0-254, 255 keeps steppers enabled)
#define DEFAULT_AUTOSLEEP 10 // minutes
#define DEFAULT_STATUS_REPORT_MASK 1 // MPos enabled
#define DEFAULT_JUNCTION_DEVIATION 0.01 // mm
#define DEFAULT_ARC_TOLERANCE 0.002 // mm
Expand Down Expand Up @@ -472,6 +482,7 @@
#define DEFAULT_STEPPING_INVERT_MASK 0
#define DEFAULT_DIRECTION_INVERT_MASK ((1<<Y_AXIS))
#define DEFAULT_STEPPER_IDLE_LOCK_TIME 25 // msec (0-254, 255 keeps steppers enabled)
#define DEFAULT_AUTOSLEEP 10 // minutes
#define DEFAULT_STATUS_REPORT_MASK 1 // MPos enabled
#define DEFAULT_JUNCTION_DEVIATION 0.02 // mm
#define DEFAULT_ARC_TOLERANCE 0.002 // mm
Expand Down Expand Up @@ -511,6 +522,7 @@
#define DEFAULT_STEPPING_INVERT_MASK 0
#define DEFAULT_DIRECTION_INVERT_MASK 0
#define DEFAULT_STEPPER_IDLE_LOCK_TIME 25 // msec (0-254, 255 keeps steppers enabled)
#define DEFAULT_AUTOSLEEP 10 // minutes
#define DEFAULT_STATUS_REPORT_MASK 1 // MPos enabled
#define DEFAULT_JUNCTION_DEVIATION 0.02 // mm
#define DEFAULT_ARC_TOLERANCE 0.002 // mm
Expand Down Expand Up @@ -550,6 +562,7 @@
#define DEFAULT_STEPPING_INVERT_MASK 0
#define DEFAULT_DIRECTION_INVERT_MASK 0
#define DEFAULT_STEPPER_IDLE_LOCK_TIME 25 // msec (0-254, 255 keeps steppers enabled)
#define DEFAULT_AUTOSLEEP 10 // minutes
#define DEFAULT_STATUS_REPORT_MASK 1 // MPos enabled
#define DEFAULT_JUNCTION_DEVIATION 0.01 // mm
#define DEFAULT_ARC_TOLERANCE 0.002 // mm
Expand Down
30 changes: 30 additions & 0 deletions grbl/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ void protocol_main_loop()
uint8_t line_flags = 0;
uint8_t char_counter = 0;
uint8_t c;

const uint_fast32_t stepper_sleep_counts = 60000 * settings.auto_sleep;
uint_fast32_t stepper_sleep = stepper_sleep_counts;

for (;;) {

// Process one line of incoming serial data, as the data becomes available. Performs an
Expand Down Expand Up @@ -100,6 +104,13 @@ void protocol_main_loop()
// Everything else is gcode. Block if in alarm or jog mode.
report_status_message(STATUS_SYSTEM_GC_LOCK);
} else {
// Wakeup stepper if IU have disabled before
if (stepper_sleep == 0) {
st_wake_up();
}
// Reset loop sleep
stepper_sleep = stepper_sleep_counts;

// Parse and execute g-code block.
report_status_message(gc_execute_line(line));
}
Expand Down Expand Up @@ -158,6 +169,25 @@ void protocol_main_loop()

protocol_execute_realtime(); // Runtime command check point.
if (sys.abort) { return; } // Bail to main() program loop to reset system.

// idle lock is off?
if (settings.stepper_idle_lock_time == 255) {
// Will I do a block in next loop?
if (sys.state == STATE_IDLE) {
// Last waiting loop. so disable stepper
if (stepper_sleep == 1) {
st_disable_set(true);
}
// I will sleep ...
if (stepper_sleep > 0) {
stepper_sleep--;
_delay_ms(1);
}
} else {
// I will do something, so don't sleep
stepper_sleep = stepper_sleep_counts;
}
}
}

return; /* Never reached */
Expand Down
1 change: 1 addition & 0 deletions grbl/report.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ void report_grbl_settings() {
#else
report_util_uint8_setting(32,0);
#endif
report_util_uint8_setting(33,settings.auto_sleep);
// Print axis settings
uint8_t idx, set_idx;
uint8_t val = AXIS_SETTINGS_START_VAL;
Expand Down
4 changes: 3 additions & 1 deletion grbl/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ const __flash settings_t defaults = {\
.acceleration[Z_AXIS] = DEFAULT_Z_ACCELERATION,
.max_travel[X_AXIS] = (-DEFAULT_X_MAX_TRAVEL),
.max_travel[Y_AXIS] = (-DEFAULT_Y_MAX_TRAVEL),
.max_travel[Z_AXIS] = (-DEFAULT_Z_MAX_TRAVEL)};
.max_travel[Z_AXIS] = (-DEFAULT_Z_MAX_TRAVEL),
.auto_sleep = DEFAULT_AUTOSLEEP };


// Method to store startup lines into EEPROM
Expand Down Expand Up @@ -286,6 +287,7 @@ uint8_t settings_store_global_setting(uint8_t parameter, float value) {
case 27: settings.homing_pulloff = value; break;
case 30: settings.rpm_max = value; spindle_init(); break; // Re-initialize spindle rpm calibration
case 31: settings.rpm_min = value; spindle_init(); break; // Re-initialize spindle rpm calibration
case 33: settings.auto_sleep = int_value; break; // autosleep sec
case 32:
#ifdef VARIABLE_SPINDLE
if (int_value) { settings.flags |= BITFLAG_LASER_MODE; }
Expand Down
3 changes: 2 additions & 1 deletion grbl/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

// Version of the EEPROM data. Will be used to migrate existing data from older versions of Grbl
// when firmware is upgraded. Always stored in byte 0 of eeprom
#define SETTINGS_VERSION 10 // NOTE: Check settings_reset() when moving to next version.
#define SETTINGS_VERSION 11 // NOTE: Check settings_reset() when moving to next version.

// Define bit flag masks for the boolean settings in settings.flag.
#define BIT_REPORT_INCHES 0
Expand Down Expand Up @@ -110,6 +110,7 @@ typedef struct {
float homing_seek_rate;
uint16_t homing_debounce_delay;
float homing_pulloff;
uint8_t auto_sleep;
} settings_t;
extern settings_t settings;

Expand Down
15 changes: 12 additions & 3 deletions grbl/stepper.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,20 @@ void st_go_idle()
delay_ms(settings.stepper_idle_lock_time);
pin_state = true; // Override. Disable steppers.
}
if (bit_istrue(settings.flags,BITFLAG_INVERT_ST_ENABLE)) { pin_state = !pin_state; } // Apply pin invert.
if (pin_state) { STEPPERS_DISABLE_PORT |= (1<<STEPPERS_DISABLE_BIT); }
else { STEPPERS_DISABLE_PORT &= ~(1<<STEPPERS_DISABLE_BIT); }
st_disable_set(pin_state);
}

void st_disable_set(bool a_state) {
bool pin_state = a_state; // Keep enabled.
if (bit_istrue(settings.flags, BITFLAG_INVERT_ST_ENABLE)) {
pin_state = !pin_state;
} // Apply pin invert.
if (pin_state) {
STEPPERS_DISABLE_PORT |= (1 << STEPPERS_DISABLE_BIT);
} else {
STEPPERS_DISABLE_PORT &= ~(1 << STEPPERS_DISABLE_BIT);
}
}

/* "The Stepper Driver Interrupt" - This timer interrupt is the workhorse of Grbl. Grbl employs
the venerable Bresenham line algorithm to manage and exactly synchronize multi-axis moves.
Expand Down
3 changes: 3 additions & 0 deletions grbl/stepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,7 @@ void st_update_plan_block_parameters();
// Called by realtime status reporting if realtime rate reporting is enabled in config.h.
float st_get_realtime_rate();

// Disable stepper
void st_disable_set(bool a_state) ;

#endif