diff --git a/README.md b/README.md index 3041b5d..d84e588 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,11 @@ Usage notes: * Hard limits not yet ported * Control inputs not yet ported (e.g. Cycle Start and Safety Door switches) +New configuration settings +* $140, $141, $142 are X, Y, Z current (amps) +* Default to 0.0 A to avoid burning out your motors +* Your motors will likely stall if you don't set these! + Build notes: * Include ```make``` and the ```arm-none-eabi-*``` tools in your path. * Make produces 2 files: diff --git a/grbl-lpc/current_control.cpp b/grbl-lpc/current_control.cpp index 61c58b3..ab8f0de 100644 --- a/grbl-lpc/current_control.cpp +++ b/grbl-lpc/current_control.cpp @@ -24,6 +24,10 @@ #include "grbl.h" #include "Driver_I2C.h" +#undef min +#undef max +#include + #ifdef CURRENT_I2C extern ARM_DRIVER_I2C CURRENT_I2C; static const uint8_t wiperRegs[] = CURRENT_WIPERS; @@ -48,9 +52,9 @@ void current_init() ; #endif - set_current(0, DEFAULT_X_CURRENT); - set_current(1, DEFAULT_Y_CURRENT); - set_current(2, DEFAULT_Z_CURRENT); + set_current(0, settings.current[0]); + set_current(1, settings.current[1]); + set_current(2, settings.current[2]); set_current(3, DEFAULT_A_CURRENT); #endif } @@ -60,7 +64,7 @@ void set_current(uint8_t motor, float amps) #if defined(CURRENT_I2C) && defined(CURRENT_MCP44XX_ADDR) uint8_t command[] = { uint8_t(wiperRegs[motor] << 4), - uint8_t(std::round(amps * CURRENT_FACTOR)), + uint8_t(std::min(255.0, std::max(0.0, std::round(amps * CURRENT_FACTOR)))), }; CURRENT_I2C.MasterTransmit(CURRENT_MCP44XX_ADDR, command, sizeof(command), false); while (CURRENT_I2C.GetStatus().busy) diff --git a/grbl/config.h b/grbl/config.h index 25f4874..3396771 100644 --- a/grbl/config.h +++ b/grbl/config.h @@ -731,8 +731,8 @@ #define DEFAULT_X_ACCELERATION (5000.0*60*60) // 5000*60*60 mm/min^2 = 5000 mm/sec^2 #define DEFAULT_Y_ACCELERATION (5000.0*60*60) // 5000*60*60 mm/min^2 = 5000 mm/sec^2 #define DEFAULT_Z_ACCELERATION (5000.0*60*60) // 5000*60*60 mm/min^2 = 5000 mm/sec^2 -#define DEFAULT_X_CURRENT 0.4 // amps -#define DEFAULT_Y_CURRENT 1.5 // amps +#define DEFAULT_X_CURRENT 0.0 // amps +#define DEFAULT_Y_CURRENT 0.0 // amps #define DEFAULT_Z_CURRENT 0.0 // amps #define DEFAULT_A_CURRENT 0.0 // amps #define DEFAULT_X_MAX_TRAVEL 200.0 // mm diff --git a/grbl/grbl.h b/grbl/grbl.h index 56b72e3..f839107 100644 --- a/grbl/grbl.h +++ b/grbl/grbl.h @@ -62,6 +62,7 @@ #include "spindle_control.h" #include "stepper.h" #include "jog.h" +#include "current_control.h" // --------------------------------------------------------------------------------------- // COMPILE-TIME ERROR CHECKING OF DEFINE VALUES: diff --git a/grbl/main.c b/grbl/main.c index 5b6feee..8d5ec93 100644 --- a/grbl/main.c +++ b/grbl/main.c @@ -20,7 +20,6 @@ */ #include "grbl.h" -#include "current_control.h" void isr_init(); diff --git a/grbl/report.c b/grbl/report.c index 4fbe457..c05be42 100644 --- a/grbl/report.c +++ b/grbl/report.c @@ -218,6 +218,7 @@ void report_grbl_settings() { case 1: report_util_float_setting(val+idx,settings.max_rate[idx],N_DECIMAL_SETTINGVALUE); break; case 2: report_util_float_setting(val+idx,settings.acceleration[idx]/(60*60),N_DECIMAL_SETTINGVALUE); break; case 3: report_util_float_setting(val+idx,-settings.max_travel[idx],N_DECIMAL_SETTINGVALUE); break; + case 4: report_util_float_setting(val+idx,settings.current[idx],N_DECIMAL_SETTINGVALUE); break; } } val += AXIS_SETTINGS_INCREMENT; diff --git a/grbl/settings.c b/grbl/settings.c index 9f1e05f..53ca2dc 100644 --- a/grbl/settings.c +++ b/grbl/settings.c @@ -117,6 +117,9 @@ void settings_restore(uint8_t restore_flag) { settings.max_travel[X_AXIS] = (-DEFAULT_X_MAX_TRAVEL); settings.max_travel[Y_AXIS] = (-DEFAULT_Y_MAX_TRAVEL); settings.max_travel[Z_AXIS] = (-DEFAULT_Z_MAX_TRAVEL); + settings.current[X_AXIS] = DEFAULT_X_CURRENT; + settings.current[Y_AXIS] = DEFAULT_Y_CURRENT; + settings.current[Z_AXIS] = DEFAULT_Z_CURRENT; write_global_settings(false); } @@ -231,6 +234,10 @@ uint8_t settings_store_global_setting(uint8_t parameter, float value) { break; case 2: settings.acceleration[parameter] = value*60*60; break; // Convert to mm/min^2 for grbl internal use. case 3: settings.max_travel[parameter] = -value; break; // Store as negative for grbl internal use. + case 4: + settings.current[parameter] = value; + set_current(parameter, settings.current[parameter]); + break; } break; // Exit while-loop after setting has been configured and proceed to the EEPROM write call. } else { diff --git a/grbl/settings.h b/grbl/settings.h index e04de26..3e2d8ad 100644 --- a/grbl/settings.h +++ b/grbl/settings.h @@ -70,7 +70,7 @@ // #define SETTING_INDEX_G92 N_COORDINATE_SYSTEM+2 // Coordinate offset (G92.2,G92.3 not supported) // Define Grbl axis settings numbering scheme. Starts at START_VAL, every INCREMENT, over N_SETTINGS. -#define AXIS_N_SETTINGS 4 +#define AXIS_N_SETTINGS 5 #define AXIS_SETTINGS_START_VAL 100 // NOTE: Reserving settings values >= 100 for axis settings. Up to 255. #define AXIS_SETTINGS_INCREMENT 10 // Must be greater than the number of axis settings @@ -81,6 +81,7 @@ typedef struct { float max_rate[N_AXIS]; float acceleration[N_AXIS]; float max_travel[N_AXIS]; + float current[N_AXIS]; // Remaining Grbl settings uint8_t pulse_microseconds;