diff --git a/Grbl_Esp32/src/Grbl.cpp b/Grbl_Esp32/src/Grbl.cpp index 8aaeebdc..737bb63e 100644 --- a/Grbl_Esp32/src/Grbl.cpp +++ b/Grbl_Esp32/src/Grbl.cpp @@ -86,6 +86,7 @@ static void reset_variables() { memset(sys_probe_position, 0, sizeof(sys_probe_position)); // Clear probe position. sys_probe_state = 0; sys_rt_exec_state = 0; + cycle_stop = false; sys_rt_exec_motion_override = 0; sys_rt_exec_accessory_override = 0; system_clear_exec_alarm(); diff --git a/Grbl_Esp32/src/Limits.cpp b/Grbl_Esp32/src/Limits.cpp index 5d1bdb4e..8c5e252c 100644 --- a/Grbl_Esp32/src/Limits.cpp +++ b/Grbl_Esp32/src/Limits.cpp @@ -202,7 +202,7 @@ void limits_go_home(uint8_t cycle_mask) { } st_prep_buffer(); // Check and prep segment buffer. NOTE: Should take no longer than 200us. // Exit routines: No time to run protocol_execute_realtime() in this loop. - if (sys_rt_exec_state & (EXEC_SAFETY_DOOR | EXEC_RESET | EXEC_CYCLE_STOP)) { + if ((sys_rt_exec_state & (EXEC_SAFETY_DOOR | EXEC_RESET)) || cycle_stop) { uint8_t rt_exec = sys_rt_exec_state; // Homing failure condition: Reset issued during cycle. if (rt_exec & EXEC_RESET) { @@ -217,7 +217,7 @@ void limits_go_home(uint8_t cycle_mask) { system_set_exec_alarm(ExecAlarm::HomingFailPulloff); } // Homing failure condition: Limit switch not found during approach. - if (approach && (rt_exec & EXEC_CYCLE_STOP)) { + if (approach && cycle_stop) { system_set_exec_alarm(ExecAlarm::HomingFailApproach); } @@ -228,7 +228,7 @@ void limits_go_home(uint8_t cycle_mask) { return; } else { // Pull-off motion complete. Disable CYCLE_STOP from executing. - system_clear_exec_state_flag(EXEC_CYCLE_STOP); + cycle_stop = false; break; } } @@ -371,7 +371,7 @@ void limits_disable() { // number in bit position, i.e. Z_AXIS is bit(2), and Y_AXIS is bit(1). uint8_t limits_get_state() { uint8_t pinMask = 0; - auto n_axis = number_axis->get(); + auto n_axis = number_axis->get(); for (int axis = 0; axis < n_axis; axis++) { for (int gang_index = 0; gang_index < 2; gang_index++) { uint8_t pin = limit_pins[axis][gang_index]; diff --git a/Grbl_Esp32/src/Machines/6_pack_stepstick_XYZ_v1.h b/Grbl_Esp32/src/Machines/6_pack_stepstick_XYZ_v1.h index f18e3ec4..b8b70c3f 100644 --- a/Grbl_Esp32/src/Machines/6_pack_stepstick_XYZ_v1.h +++ b/Grbl_Esp32/src/Machines/6_pack_stepstick_XYZ_v1.h @@ -110,11 +110,27 @@ Socket #5 */ - // 4x Input Module in Socket #1 +/* +// 4x Input Module in Socket #1 // https://github.com/bdring/6-Pack_CNC_Controller/wiki/4x-Switch-Input-module #define X_LIMIT_PIN GPIO_NUM_33 #define Y_LIMIT_PIN GPIO_NUM_32 #define Z_LIMIT_PIN GPIO_NUM_35 +*/ + +// 4x Input Module in Socket #2 +// https://github.com/bdring/6-Pack_CNC_Controller/wiki/4x-Switch-Input-module +#define X_LIMIT_PIN GPIO_NUM_2 +#define Y_LIMIT_PIN GPIO_NUM_25 +#define Z_LIMIT_PIN GPIO_NUM_39 + +// 4x Input Module in Socket #3 +// https://github.com/bdring/6-Pack_CNC_Controller/wiki/4x-Switch-Input-module +#define CONTROL_CYCLE_START_PIN GPIO_NUM_26 +#define CONTROL_FEED_HOLD_PIN GPIO_NUM_4 +#define CONTROL_RESET_PIN GPIO_NUM_16 +#define CONTROL_SAFETY_DOOR_PIN GPIO_NUM_27 +//#define INVERT_CONTROL_PIN_MASK B0000 // ================= Setting Defaults ========================== diff --git a/Grbl_Esp32/src/Protocol.cpp b/Grbl_Esp32/src/Protocol.cpp index 106d90a5..d2d3d0cb 100644 --- a/Grbl_Esp32/src/Protocol.cpp +++ b/Grbl_Esp32/src/Protocol.cpp @@ -271,7 +271,7 @@ void protocol_exec_rt_system() { system_clear_exec_alarm(); // Clear alarm } uint8_t rt_exec = sys_rt_exec_state; // Copy volatile sys_rt_exec_state. - if (rt_exec) { + if (rt_exec || cycle_stop) { // Execute system abort. if (rt_exec & EXEC_RESET) { sys.abort = true; // Only place this is set true. @@ -399,12 +399,12 @@ void protocol_exec_rt_system() { } system_clear_exec_state_flag(EXEC_CYCLE_START); } - if (rt_exec & EXEC_CYCLE_STOP) { + if (cycle_stop) { // Reinitializes the cycle plan and stepper system after a feed hold for a resume. Called by // realtime command execution in the main program, ensuring that the planner re-plans safely. // NOTE: Bresenham algorithm variables are still maintained through both the planner and stepper // cycle reinitializations. The stepper path should continue exactly as if nothing has happened. - // NOTE: EXEC_CYCLE_STOP is set by the stepper subsystem when a cycle or feed hold completes. + // NOTE: cycle_stop is set by the stepper subsystem when a cycle or feed hold completes. if ((sys.state == State::Hold || sys.state == State::SafetyDoor || sys.state == State::Sleep) && !(sys.soft_limit) && !(sys.suspend & SUSPEND_JOG_CANCEL)) { // Hold complete. Set to indicate ready to resume. Remain in HOLD or DOOR states until user @@ -433,7 +433,7 @@ void protocol_exec_rt_system() { sys.state = State::Idle; } } - system_clear_exec_state_flag(EXEC_CYCLE_STOP); + cycle_stop = false; } } // Execute overrides. diff --git a/Grbl_Esp32/src/Stepper.cpp b/Grbl_Esp32/src/Stepper.cpp index 639abc06..858e15c2 100644 --- a/Grbl_Esp32/src/Stepper.cpp +++ b/Grbl_Esp32/src/Stepper.cpp @@ -296,9 +296,8 @@ static void stepper_pulse_func() { spindle->set_rpm(0); } } - - system_set_exec_state_flag(EXEC_CYCLE_STOP); // Flag main program for cycle end - return; // Nothing to do but exit. + cycle_stop = true; + return; // Nothing to do but exit. } } // Check probing state. @@ -362,8 +361,7 @@ static void stepper_pulse_func() { st.counter_a -= st.exec_block->step_event_count; if (st.exec_block->direction_bits & bit(A_AXIS)) { sys_position[A_AXIS]--; - } - else { + } else { sys_position[A_AXIS]++; } } @@ -379,8 +377,7 @@ static void stepper_pulse_func() { st.counter_b -= st.exec_block->step_event_count; if (st.exec_block->direction_bits & bit(B_AXIS)) { sys_position[B_AXIS]--; - } - else { + } else { sys_position[B_AXIS]++; } } @@ -396,8 +393,7 @@ static void stepper_pulse_func() { st.counter_c -= st.exec_block->step_event_count; if (st.exec_block->direction_bits & bit(C_AXIS)) { sys_position[C_AXIS]--; - } - else { + } else { sys_position[C_AXIS]++; } } @@ -1229,8 +1225,10 @@ float st_get_realtime_rate() { case State::Homing: case State::Hold: case State::Jog: - case State::SafetyDoor: return prep.current_speed; - default: return 0.0f; + case State::SafetyDoor: + return prep.current_speed; + default: + return 0.0f; } } diff --git a/Grbl_Esp32/src/System.cpp b/Grbl_Esp32/src/System.cpp index 2aa6ad67..7c434ec3 100644 --- a/Grbl_Esp32/src/System.cpp +++ b/Grbl_Esp32/src/System.cpp @@ -30,6 +30,7 @@ volatile uint8_t sys_rt_exec_state; // Global realtime executor volatile ExecAlarm sys_rt_exec_alarm; // Global realtime executor bitflag variable for setting various alarms. volatile uint8_t sys_rt_exec_motion_override; // Global realtime executor bitflag variable for motion-based overrides. volatile uint8_t sys_rt_exec_accessory_override; // Global realtime executor bitflag variable for spindle/coolant overrides. +volatile bool cycle_stop; // For state transitions, instead of bitflag #ifdef DEBUG volatile uint8_t sys_rt_exec_debug; #endif diff --git a/Grbl_Esp32/src/System.h b/Grbl_Esp32/src/System.h index 361bb804..4568980d 100644 --- a/Grbl_Esp32/src/System.h +++ b/Grbl_Esp32/src/System.h @@ -39,7 +39,7 @@ enum class State : uint8_t { // Define global system variables typedef struct { - State state; // Tracks the current system state of Grbl. + volatile State state; // Tracks the current system state of Grbl. uint8_t abort; // System abort flag. Forces exit back to main loop for reset. uint8_t suspend; // System suspend bitflag variable that manages holds, cancels, and safety door. uint8_t soft_limit; // Tracks soft limit errors for the state machine. (boolean) @@ -68,7 +68,7 @@ extern system_t sys; // know when there is a realtime command to execute. #define EXEC_STATUS_REPORT bit(0) // bitmask 00000001 #define EXEC_CYCLE_START bit(1) // bitmask 00000010 -#define EXEC_CYCLE_STOP bit(2) // bitmask 00000100 +// #define EXEC_CYCLE_STOP bit(2) // bitmask 00000100 moved to cycle_stop #define EXEC_FEED_HOLD bit(3) // bitmask 00001000 #define EXEC_RESET bit(4) // bitmask 00010000 #define EXEC_SAFETY_DOOR bit(5) // bitmask 00100000 @@ -163,6 +163,7 @@ extern volatile uint8_t sys_rt_exec_state; // Global realtime executor bitfla extern volatile ExecAlarm sys_rt_exec_alarm; // Global realtime executor bitflag variable for setting various alarms. extern volatile uint8_t sys_rt_exec_motion_override; // Global realtime executor bitflag variable for motion-based overrides. extern volatile uint8_t sys_rt_exec_accessory_override; // Global realtime executor bitflag variable for spindle/coolant overrides. +extern volatile bool cycle_stop; #ifdef DEBUG # define EXEC_DEBUG_REPORT bit(0) @@ -228,5 +229,5 @@ bool sys_pwm_control(uint8_t io_num_mask, float duty, bool synchronized); int8_t sys_get_next_RMT_chan_num(); -int8_t sys_get_next_PWM_chan_num(); +int8_t sys_get_next_PWM_chan_num(); uint8_t sys_calc_pwm_precision(uint32_t freq); diff --git a/README.md b/README.md index 65a8eab0..7ee0651d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # Grbl (CNC Controller) For ESP32 - + ### Project Overview