diff --git a/Grbl_Esp32/cpu_map.h b/Grbl_Esp32/cpu_map.h index 7644d254..3a188f60 100644 --- a/Grbl_Esp32/cpu_map.h +++ b/Grbl_Esp32/cpu_map.h @@ -817,7 +817,7 @@ #define USE_RMT_STEPS - #define USE_TRINAMIC // Using at least 1 trinamic driver + #define USE_TRINAMIC // Using at least 1 trinamic driver #define X_STEP_PIN GPIO_NUM_12 #define X_DIRECTION_PIN GPIO_NUM_26 @@ -1011,56 +1011,74 @@ #ifdef N_AXIS #undef N_AXIS #endif - #define N_AXIS 4 + #define N_AXIS 4 // can be 3 or 4. (if 3 install bypass jumper next to the A driver) #define USE_TRINAMIC #define TRINAMIC_DAISY_CHAIN + + // Use SPI enable instead of the enable pin + // The hardware enable pin is tied to ground + #define USE_TRINAMIC_ENABLE #define USE_RMT_STEPS + #define X_DRIVER_TMC2130 // Which Driver Type? + #define X_RSENSE 0.11f // .11 Ohm...typical of 2130 type 0.075 typical for TMC5160 #define X_STEP_PIN GPIO_NUM_12 #define X_DIRECTION_PIN GPIO_NUM_14 #define X_TRINAMIC // using SPI control - #define X_DRIVER_TMC2130 // Which Driver Type? #define X_CS_PIN GPIO_NUM_17 // Daisy Chain, all share same CS pin - #define X_RSENSE 0.11f // .11 Ohm + #define Y_DRIVER_TMC2130 // Which Driver Type? + #define Y_RSENSE 0.11f // .11 Ohm...typical of 2130 type 0.075 typical for TMC5160 #define Y_STEP_PIN GPIO_NUM_27 #define Y_DIRECTION_PIN GPIO_NUM_26 #define Y_TRINAMIC // using SPI control - #define Y_DRIVER_TMC2130 // Which Driver Type? #define Y_CS_PIN X_CS_PIN // Daisy Chain, all share same CS pin - #define Y_RSENSE 0.11f // .11 Ohm + #define Z_DRIVER_TMC2130 // Which Driver Type? + #define Z_RSENSE 0.11f // .11 Ohm...typical of 2130 type 0.075 typical for TMC5160 #define Z_STEP_PIN GPIO_NUM_15 #define Z_DIRECTION_PIN GPIO_NUM_2 #define Z_TRINAMIC // using SPI control - #define Z_DRIVER_TMC2130 // Which Driver Type? #define Z_CS_PIN X_CS_PIN // Daisy Chain, all share same CS pin - #define Z_RSENSE 0.11f // .11 Ohm - #define A_STEP_PIN GPIO_NUM_33 - #define A_DIRECTION_PIN GPIO_NUM_32 - #define A_TRINAMIC // using SPI control - #define A_DRIVER_TMC2130 // Which Driver Type? - #define A_CS_PIN X_CS_PIN // Daisy Chain, all share same CS pin - #define A_RSENSE 0.11f // .11 Ohm - - #define STEPPERS_DISABLE_PIN GPIO_NUM_13 + #if (N_AXIS == 4) + #define A_DRIVER_TMC2130 // Which Driver Type? + #define A_RSENSE 0.11f // .11 Ohm...typical of 2130 type 0.075 typical for TMC5160 + #define A_STEP_PIN GPIO_NUM_33 + #define A_DIRECTION_PIN GPIO_NUM_32 + #define A_TRINAMIC // using SPI control + #define A_CS_PIN X_CS_PIN // Daisy Chain, all share same CS pin + #endif + // Mist is a 3.3V output + // Turn on with M7 and off with M9 #define COOLANT_MIST_PIN GPIO_NUM_21 #define SPINDLE_PWM_PIN GPIO_NUM_25 #define SPINDLE_ENABLE_PIN GPIO_NUM_4 #define SPINDLE_PWM_CHANNEL 0 - #define SPINDLE_PWM_BIT_PRECISION 8 + #define SPINDLE_PWM_BIT_PRECISION 8 + + // Relay operation + // Install Jumper near relay + // For spindle Use max RPM of 1 + // For PWM remove jumper and set MAX RPM to something higher ($30 setting) + // Interlock jumper along top edge needs to be installed for both versions + #define DEFAULT_SPINDLE_RPM_MAX 1 // Should be 1 for relay operation #define PROBE_PIN GPIO_NUM_22 #define X_LIMIT_PIN GPIO_NUM_36 #define Y_LIMIT_PIN GPIO_NUM_39 #define Z_LIMIT_PIN GPIO_NUM_34 - #define A_LIMIT_PIN GPIO_NUM_35 - #define LIMIT_MASK B1111 + + #if (N_AXIS == 4) + #define A_LIMIT_PIN GPIO_NUM_35 + #define LIMIT_MASK B1111 + #else + #define LIMIT_MASK B0111 + #endif #endif diff --git a/Grbl_Esp32/defaults.h b/Grbl_Esp32/defaults.h index 5a89c9a1..706e3852 100644 --- a/Grbl_Esp32/defaults.h +++ b/Grbl_Esp32/defaults.h @@ -190,43 +190,43 @@ // =========== AXIS RESOLUTION ====== #ifndef DEFAULT_X_STEPS_PER_MM - #define DEFAULT_X_STEPS_PER_MM 800.0 + #define DEFAULT_X_STEPS_PER_MM 100.0 #endif #ifndef DEFAULT_Y_STEPS_PER_MM - #define DEFAULT_Y_STEPS_PER_MM 800.0 + #define DEFAULT_Y_STEPS_PER_MM 100.0 #endif #ifndef DEFAULT_Z_STEPS_PER_MM - #define DEFAULT_Z_STEPS_PER_MM 800.0 + #define DEFAULT_Z_STEPS_PER_MM 100.0 #endif #ifndef DEFAULT_A_STEPS_PER_MM - #define DEFAULT_A_STEPS_PER_MM 800.0 + #define DEFAULT_A_STEPS_PER_MM 100.0 #endif #ifndef DEFAULT_B_STEPS_PER_MM - #define DEFAULT_B_STEPS_PER_MM 800.0 + #define DEFAULT_B_STEPS_PER_MM 100.0 #endif #ifndef DEFAULT_C_STEPS_PER_MM - #define DEFAULT_C_STEPS_PER_MM 800.0 + #define DEFAULT_C_STEPS_PER_MM 100.0 #endif // ============ AXIS MAX SPPED ========= #ifndef DEFAULT_X_MAX_RATE - #define DEFAULT_X_MAX_RATE 5000.0 // mm/min + #define DEFAULT_X_MAX_RATE 1000.0 // mm/min #endif #ifndef DEFAULT_Y_MAX_RATE - #define DEFAULT_Y_MAX_RATE 5000.0 // mm/min + #define DEFAULT_Y_MAX_RATE 1000.0 // mm/min #endif #ifndef DEFAULT_Z_MAX_RATE - #define DEFAULT_Z_MAX_RATE 5000.0 // mm/min + #define DEFAULT_Z_MAX_RATE 1000.0 // mm/min #endif #ifndef DEFAULT_A_MAX_RATE - #define DEFAULT_A_MAX_RATE 5000.0 // mm/min + #define DEFAULT_A_MAX_RATE 1000.0 // mm/min #endif #ifndef DEFAULT_B_MAX_RATE - #define DEFAULT_B_MAX_RATE 5000.0 // mm/min + #define DEFAULT_B_MAX_RATE 1000.0 // mm/min #endif #ifndef DEFAULT_C_MAX_RATE - #define DEFAULT_C_MAX_RATE 5000.0 // mm/min + #define DEFAULT_C_MAX_RATE 1000.0 // mm/min #endif // ============== Axis Acceleration ========= diff --git a/Grbl_Esp32/grbl.h b/Grbl_Esp32/grbl.h index 4ba4c2b8..1d23575c 100644 --- a/Grbl_Esp32/grbl.h +++ b/Grbl_Esp32/grbl.h @@ -20,7 +20,7 @@ // Grbl versioning system #define GRBL_VERSION "1.1f" -#define GRBL_VERSION_BUILD "20200216" +#define GRBL_VERSION_BUILD "20200219" //#include #include diff --git a/Grbl_Esp32/grbl_limits.cpp b/Grbl_Esp32/grbl_limits.cpp index 2128ef84..530e3a93 100644 --- a/Grbl_Esp32/grbl_limits.cpp +++ b/Grbl_Esp32/grbl_limits.cpp @@ -51,7 +51,7 @@ void IRAM_ATTR isr_limit_switches() #ifdef ENABLE_SOFTWARE_DEBOUNCE // we will start a task that will recheck the switches after a small delay int evt; - xQueueSendFromISR(limit_sw_queue, &evt, NULL); + xQueueSendFromISR(limit_sw_queue, &evt, NULL); #else #ifdef HARD_LIMIT_FORCE_STATE_CHECK // Check limit pin state. @@ -450,11 +450,16 @@ void limitCheckTask(void *pvParameters) { while(true) { int evt; - xQueueReceive(limit_sw_queue, &evt, portMAX_DELAY); // block until receive queue + xQueueReceive(limit_sw_queue, &evt, portMAX_DELAY); // block until receive queue vTaskDelay( DEBOUNCE_PERIOD / portTICK_PERIOD_MS ); // delay a while - if (limits_get_state()) { - mc_reset(); // Initiate system kill. + uint8_t switch_state; + + switch_state = limits_get_state(); + + if (switch_state) { + grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Limit Switch State %08d", switch_state); + mc_reset(); // Initiate system kill. system_set_exec_alarm(EXEC_ALARM_HARD_LIMIT); // Indicate hard limit critical event } } diff --git a/Grbl_Esp32/grbl_trinamic.cpp b/Grbl_Esp32/grbl_trinamic.cpp index d5327843..285cb88e 100644 --- a/Grbl_Esp32/grbl_trinamic.cpp +++ b/Grbl_Esp32/grbl_trinamic.cpp @@ -133,9 +133,7 @@ // TODO ABC Axes void Trinamic_Init() -{ - uint8_t testResult; - +{ grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "TMCStepper Init using Library Ver 0x%06x", TMCSTEPPER_VERSION); SPI.begin(); @@ -147,9 +145,8 @@ void Trinamic_Init() #ifdef X_TRINAMIC TRINAMIC_X.begin(); // Initiate pins and registries - testResult = TRINAMIC_X.test_connection(); - trinamic_test_response(testResult, "X"); - TRINAMIC_X.toff(5); + trinamic_test_response(TRINAMIC_X.test_connection(), "X"); + TRINAMIC_X.toff(TRINAMIC_DEFAULT_TOFF); TRINAMIC_X.microsteps(settings.microsteps[X_AXIS]); TRINAMIC_X.rms_current(settings.current[X_AXIS] * 1000.0, settings.hold_current[X_AXIS]/100.0); TRINAMIC_X.en_pwm_mode(1); // Enable extremely quiet stepping @@ -158,9 +155,8 @@ void Trinamic_Init() #ifdef Y_TRINAMIC TRINAMIC_Y.begin(); // Initiate pins and registries - testResult = TRINAMIC_Y.test_connection(); - trinamic_test_response(testResult, "Y"); - TRINAMIC_Y.toff(5); + trinamic_test_response(TRINAMIC_Y.test_connection(), "Y"); + TRINAMIC_Y.toff(TRINAMIC_DEFAULT_TOFF); TRINAMIC_Y.microsteps(settings.microsteps[Y_AXIS]); TRINAMIC_Y.rms_current(settings.current[Y_AXIS] * 1000.0, settings.hold_current[Y_AXIS]/100.0); TRINAMIC_Y.en_pwm_mode(1); // Enable extremely quiet stepping @@ -169,9 +165,8 @@ void Trinamic_Init() #ifdef Z_TRINAMIC TRINAMIC_Z.begin(); // Initiate pins and registries - testResult = TRINAMIC_Z.test_connection(); - trinamic_test_response(testResult, "Z"); - TRINAMIC_Z.toff(5); + trinamic_test_response(TRINAMIC_Z.test_connection(), "Z"); + TRINAMIC_Z.toff(TRINAMIC_DEFAULT_TOFF); TRINAMIC_Z.microsteps(settings.microsteps[Z_AXIS]); TRINAMIC_Z.rms_current(settings.current[Z_AXIS] * 1000.0, settings.hold_current[Z_AXIS]/100.0); TRINAMIC_Z.en_pwm_mode(1); // Enable extremely quiet stepping @@ -180,9 +175,8 @@ void Trinamic_Init() #ifdef A_TRINAMIC TRINAMIC_A.begin(); // Initiate pins and registries - testResult = TRINAMIC_A.test_connection(); - trinamic_test_response(testResult, "A"); - TRINAMIC_A.toff(5); + trinamic_test_response(TRINAMIC_A.test_connection(), "A"); + TRINAMIC_A.toff(TRINAMIC_DEFAULT_TOFF); TRINAMIC_A.microsteps(settings.microsteps[A_AXIS]); TRINAMIC_A.rms_current(settings.current[A_AXIS] * 1000.0, settings.hold_current[A_AXIS]/100.0); TRINAMIC_A.en_pwm_mode(1); // Enable extremely quiet stepping @@ -191,9 +185,8 @@ void Trinamic_Init() #ifdef B_TRINAMIC TRINAMIC_B.begin(); // Initiate pins and registries - testResult = TRINAMIC_B.test_connection(); - trinamic_test_response(testResult, "B"); - TRINAMIC_B.toff(5); + trinamic_test_response(TRINAMIC_B.test_connection(), "B"); + TRINAMIC_B.toff(TRINAMIC_DEFAULT_TOFF); TRINAMIC_B.microsteps(settings.microsteps[B_AXIS]); TRINAMIC_B.rms_current(settings.current[B_AXIS] * 1000.0, settings.hold_current[B_AXIS]/100.0); TRINAMIC_B.en_pwm_mode(1); // Enable extremely quiet stepping @@ -202,9 +195,8 @@ void Trinamic_Init() #ifdef C_TRINAMIC TRINAMIC_C.begin(); // Initiate pins and registries - testResult = TRINAMIC_C.test_connection(); - trinamic_test_response(testResult, "C"); - TRINAMIC_C.toff(5); + trinamic_test_response(TRINAMIC_C.test_connection(), "C"); + TRINAMIC_C.toff(TRINAMIC_DEFAULT_TOFF); TRINAMIC_C.microsteps(settings.microsteps[C_AXIS]); TRINAMIC_C.rms_current(settings.current[C_AXIS] * 1000.0, settings.hold_current[C_AXIS]/100.0); TRINAMIC_C.en_pwm_mode(1); // Enable extremely quiet stepping @@ -266,4 +258,50 @@ void trinamic_test_response(uint8_t result, const char *axis) } } +void trinamic_stepper_enable(bool enable) { + + // Trinamic_Init() has already enabled the drivers in case #define USE_TRINAMIC_ENABLE is not used + // so the previous_state is set accordingly + static bool previous_state = true; + + uint8_t toff; + + if (enable == previous_state) + return; + + previous_state = enable; + + grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Trinamic Enable: %d", enable); + + if (enable) + toff = TRINAMIC_DEFAULT_TOFF; + else + toff = 0; // diables driver + + #ifdef X_TRINAMIC + TRINAMIC_X.toff(toff); + #endif + + #ifdef Y_TRINAMIC + TRINAMIC_Y.toff(toff); + #endif + + #ifdef Z_TRINAMIC + TRINAMIC_Z.toff(toff); + #endif + + #ifdef A_TRINAMIC + TRINAMIC_A.toff(toff); + #endif + + #ifdef B_TRINAMIC + TRINAMIC_B.toff(toff); + #endif + + #ifdef C_TRINAMIC + TRINAMIC_C.toff(toff); + #endif + +} + #endif \ No newline at end of file diff --git a/Grbl_Esp32/grbl_trinamic.h b/Grbl_Esp32/grbl_trinamic.h index 574430a3..871c77db 100644 --- a/Grbl_Esp32/grbl_trinamic.h +++ b/Grbl_Esp32/grbl_trinamic.h @@ -17,6 +17,8 @@ You should have received a copy of the GNU General Public License along with Grbl. If not, see . */ +#define TRINAMIC_DEFAULT_TOFF 5 + #ifndef GRBL_TRINAMIC_h #define GRBL_TRINAMIC_h @@ -28,6 +30,7 @@ void Trinamic_Init(); void trinamic_change_settings(); void trinamic_test_response(uint8_t result, const char *axis); + void trinamic_stepper_enable(bool enable); #endif #endif \ No newline at end of file diff --git a/Grbl_Esp32/report.cpp b/Grbl_Esp32/report.cpp index 8e4895ba..17aae685 100644 --- a/Grbl_Esp32/report.cpp +++ b/Grbl_Esp32/report.cpp @@ -202,6 +202,8 @@ void get_state(char *foo) } } + + // Handles the primary confirmation protocol response for streaming interfaces and human-feedback. // For every incoming line, this method responds with an 'ok' for a successful command or an // 'error:' to indicate some error event with the line or some critical system error during diff --git a/Grbl_Esp32/spindle_control.cpp b/Grbl_Esp32/spindle_control.cpp index c350edb7..0ad8f1d8 100644 --- a/Grbl_Esp32/spindle_control.cpp +++ b/Grbl_Esp32/spindle_control.cpp @@ -205,8 +205,14 @@ void spindle_sync(uint8_t state, float rpm) void grbl_analogWrite(uint8_t chan, uint32_t duty) { - if (ledcRead(chan) != duty) // reduce unnecessary calls to ledcWrite() + // Remember the old duty cycle in memory instead of reading + // it from the I/O peripheral because I/O reads are quite + // a bit slower than memory reads. + static uint32_t old_duty = 0; + + if (old_duty != duty) // reduce unnecessary calls to ledcWrite() { + old_duty = duty; ledcWrite(chan, duty); } } diff --git a/Grbl_Esp32/stepper.cpp b/Grbl_Esp32/stepper.cpp index 6c4ebd38..9c4ba830 100644 --- a/Grbl_Esp32/stepper.cpp +++ b/Grbl_Esp32/stepper.cpp @@ -1501,8 +1501,9 @@ void IRAM_ATTR Stepper_Timer_Stop() void set_stepper_disable(uint8_t isOn) // isOn = true // to disable { - #ifdef TRINAMIC - return; + + #ifdef USE_TRINAMIC_ENABLE + trinamic_stepper_enable(!isOn); #endif if (bit_istrue(settings.flags,BITFLAG_INVERT_ST_ENABLE)) {