diff --git a/Grbl_Esp32/config.h b/Grbl_Esp32/config.h index 35a3ebb4..4c23839a 100644 --- a/Grbl_Esp32/config.h +++ b/Grbl_Esp32/config.h @@ -46,7 +46,6 @@ Some features should not be changed. See notes below. // NOTE: OEMs can avoid the need to maintain/update the defaults.h and cpu_map.h files and use only // one configuration file by placing their specific defaults and pin map at the bottom of this file. // If doing so, simply comment out these two defines and see instructions below. -#define DEFAULTS_GENERIC #define CPU_MAP_TEST_DRIVE // these are defined in cpu_map.h #define VERBOSE_HELP // adds addition help info, but could confuse some senders @@ -284,7 +283,7 @@ Some features should not be changed. See notes below. // problems if not externally pulled up. Ignoring will always return not activated when read. #define IGNORE_CONTROL_PINS -//#define ENABLE_CONTROL_SW_DEBOUNCE // Default disabled. Uncomment to enable. +#define ENABLE_CONTROL_SW_DEBOUNCE // Default disabled. Uncomment to enable. #define CONTROL_SW_DEBOUNCE_PERIOD 32 // in milliseconds default 32 microseconds @@ -431,16 +430,7 @@ Some features should not be changed. See notes below. // The hardware PWM output on pin D11 is required for variable spindle output voltages. #define VARIABLE_SPINDLE // Default enabled. Comment to disable. -// Used by variable spindle output only. This forces the PWM output to a minimum duty cycle when enabled. -// The PWM pin will still read 0V when the spindle is disabled. Most users will not need this option, but -// it may be useful in certain scenarios. This minimum PWM settings coincides with the spindle rpm minimum -// setting, like rpm max to max PWM. This is handy if you need a larger voltage difference between 0V disabled -// and the voltage set by the minimum PWM for minimum rpm. This difference is 0.02V per PWM value. So, when -// minimum PWM is at 1, only 0.02 volts separate enabled and disabled. At PWM 5, this would be 0.1V. Keep -// in mind that you will begin to lose PWM resolution with increased minimum PWM values, since you have less -// and less range over the total 255 PWM levels to signal different spindle speeds. -// NOTE: Compute duty cycle at the minimum PWM by this equation: (% duty cycle)=(SPINDLE_PWM_MIN_VALUE/255)*100 -// #define SPINDLE_PWM_MIN_VALUE 5 // Default disabled. Uncomment to enable. Must be greater than zero. Integer (1-255). + // By default on a 328p(Uno), Grbl combines the variable spindle PWM and the enable into one pin to help // preserve I/O pins. For certain setups, these may need to be separate pins. This configure option uses @@ -458,7 +448,7 @@ Some features should not be changed. See notes below. // input. However, in some use cases, user may want the enable pin to disable with a zero spindle speed and // re-enable when spindle speed is greater than zero. This option does that. // NOTE: Requires USE_SPINDLE_DIR_AS_ENABLE_PIN to be enabled. -// #define SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED // Default disabled. Uncomment to enable. +#define SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED // Default disabled. Uncomment to enable. // With this enabled, Grbl sends back an echo of the line it has received, which has been pre-parsed (spaces // removed, capitalized letters, no comments) and is to be immediately executed by Grbl. Echoes will not be @@ -611,6 +601,12 @@ Some features should not be changed. See notes below. // NOTE: Uncomment to override defaults in settings.h // #define SETTINGS_RESTORE_ALL (SETTINGS_RESTORE_DEFAULTS | SETTINGS_RESTORE_PARAMETERS | SETTINGS_RESTORE_STARTUP_LINES | SETTINGS_RESTORE_BUILD_INFO) +// Additional settings have been added to the original set that you see with the $$ command +// Some senders may not be able to parse anything different from the original set +// You can still set these like $33=5000, but you cannot read them back. +// Default is off to limit support issues...you can enable here or in your cpu_map +// #define SHOW_EXTENDED_SETTINGS + // Enable the '$I=(string)' build info write command. If disabled, any existing build info data must // be placed into EEPROM via external means with a valid checksum value. This macro option is useful // to prevent this data from being over-written by a user, when used to store OEM product data. diff --git a/Grbl_Esp32/cpu_map.h b/Grbl_Esp32/cpu_map.h index db5c6c50..3aa74631 100644 --- a/Grbl_Esp32/cpu_map.h +++ b/Grbl_Esp32/cpu_map.h @@ -59,9 +59,6 @@ */ #define CPU_MAP_NAME "CPU_MAP_DEFAULT - Demo Only No I/O!" - // the following items currently need to be defined, but no i/o needs to be mapped - // fixing soon - #define LIMIT_MASK 0 // no limit pins #endif @@ -71,8 +68,8 @@ // https://www.tindie.com/products/33366583/grbl_esp32-cnc-development-board-v35/ // Select the version (uncomment one of them) - #define CPU_MAP_V3p5 // version 3.5 and earlier - //#define CPU_MAP_V4 // version 4 or higher (in developement) + //#define CPU_MAP_V3p5 // version 3.5 and earlier + #define CPU_MAP_V4 // version 4 or higher (in developement) #define USE_RMT_STEPS @@ -120,26 +117,8 @@ #define SPINDLE_PWM_CHANNEL 0 - // PWM Generator is based on 80,000,000 Hz counter - // Therefor the freq determines the resolution - // 80,000,000 / freq = max resolution - // For 5000 that is 80,000,000 / 5000 = 16000 - // round down to nearest bit count for SPINDLE_PWM_MAX_VALUE = 13bits (8192) - - - - #define SPINDLE_PWM_BASE_FREQ 5000 // Hz - #define SPINDLE_PWM_BIT_PRECISION 8 - #define SPINDLE_PWM_OFF_VALUE 0 - #define SPINDLE_PWM_MAX_VALUE 255 - //#define INVERT_SPINDLE_PWM - - #ifndef SPINDLE_PWM_MIN_VALUE - #undef SPINDLE_PWM_MIN_VALUE - #endif - #define SPINDLE_PWM_MIN_VALUE 1 // Must be greater than zero. - - #define SPINDLE_ENABLE_PIN GPIO_NUM_22 + #define SPINDLE_PWM_BIT_PRECISION 8 + #define SPINDLE_ENABLE_PIN GPIO_NUM_22 // see versions for X and Z #define Y_LIMIT_PIN GPIO_NUM_4 @@ -177,22 +156,8 @@ #define STEPPERS_DISABLE_PIN GPIO_NUM_12 // Uno D8 #define SPINDLE_PWM_PIN GPIO_NUM_19 // Uno D11 - #define SPINDLE_PWM_CHANNEL 0 - // PWM Generator is based on 80,000,000 Hz counter - // Therefor the freq determines the resolution - // 80,000,000 / freq = max resolution - // For 5000 that is 80,000,000 / 5000 = 16000 - // round down to nearest bit count for SPINDLE_PWM_MAX_VALUE = 13bits (8192) - #define SPINDLE_PWM_BASE_FREQ 5000 // Hz - #define SPINDLE_PWM_BIT_PRECISION 8 // be sure to match this with SPINDLE_PWM_MAX_VALUE - #define SPINDLE_PWM_OFF_VALUE 0 - #define SPINDLE_PWM_MAX_VALUE 255 // (2^SPINDLE_PWM_BIT_PRECISION) - - #ifndef SPINDLE_PWM_MIN_VALUE - #define SPINDLE_PWM_MIN_VALUE 1 // Must be greater than zero. - #endif - - + #define SPINDLE_PWM_CHANNEL 0 + #define SPINDLE_PWM_BIT_PRECISION 8 // be sure to match this with SPINDLE_PWM_MAX_VALUE #define SPINDLE_DIR_PIN GPIO_NUM_18 // Uno D13 #define COOLANT_FLOOD_PIN GPIO_NUM_34 // Uno A3 @@ -234,29 +199,34 @@ #define Z_RMT_CHANNEL 2 // OK to comment out to use pin for other features - #define STEPPERS_DISABLE_PIN GPIO_NUM_13 + #define STEPPERS_DISABLE_PIN GPIO_NUM_13 #define SPINDLE_PWM_PIN GPIO_NUM_2 + #define SPINDLE_ENABLE_PIN GPIO_NUM_22 #define SPINDLE_PWM_CHANNEL 0 - // Begin RC ESC Based Spindle #defines ====================== - #define SPINDLE_PWM_BASE_FREQ 50 // Hz for ESC - #define SPINDLE_PWM_BIT_PRECISION 16 // 16 bit required for ESC - #define SPINDLE_PULSE_RES_COUNT 65535 - - #define ESC_MIN_PULSE_SEC 0.0007 // min pulse in seconds (OK to tune this one) - #define ESC_MAX_PULSE_SEC 0.0022 // max pulse in seconds (OK to tune this one) - #define ESC_TIME_PER_BIT ((1.0 / (float)SPINDLE_PWM_BASE_FREQ) / ((float)SPINDLE_PULSE_RES_COUNT) ) // seconds + // Begin RC ESC Based Spindle Information ====================== + #define SPINDLE_PWM_BIT_PRECISION 16 // 16 bit recommended for ESC (don't change) + /* + Important ESC Settings + $33=50 // Hz this is the typical good frequency for an ESC + + Determine the typical min and max pulse length of your ESC + min_pulse is typically 1ms (0.001 sec) or less + max_pulse is typically 2ms (0.002 sec) or more + + determine PWM_period. It is (1/freq) if freq = 50...period = 0.02 + + determine pulse length for min_pulse and max_pulse in percent. + + (pulse / PWM_period) + + min_pulse = (0.001 / 0.02) = 0.035 = 3.5% so ... $33 and $34 = 3.5 + max_pulse = (0.002 / .02) = 0.1 = 10% so ... $36=10 - #define SPINDLE_PWM_OFF_VALUE (uint16_t)(ESC_MIN_PULSE_SEC / ESC_TIME_PER_BIT) // in timer counts - #define SPINDLE_PWM_MAX_VALUE (uint16_t)(ESC_MAX_PULSE_SEC / ESC_TIME_PER_BIT) // in timer counts + */ - #ifndef SPINDLE_PWM_MIN_VALUE - #undef SPINDLE_PWM_MIN_VALUE - #endif - #define SPINDLE_PWM_MIN_VALUE SPINDLE_PWM_OFF_VALUE // Must be greater than zero. - #define SPINDLE_ENABLE_PIN GPIO_NUM_22 // End RC ESC Based Spindle #defines =========================== #define X_LIMIT_PIN GPIO_NUM_17 @@ -310,20 +280,9 @@ // If SPINDLE_PWM_PIN is commented out, this frees up the pin, but Grbl will still // use a virtual spindle. Do not comment out the other parameters for the spindle. #define SPINDLE_PWM_PIN GPIO_NUM_17 // Laser PWM - #define SPINDLE_PWM_CHANNEL 0 - // PWM Generator is based on 80,000,000 Hz counter - // Therefor the freq determines the resolution - // 80,000,000 / freq = max resolution - // For 5000 that is 80,000,000 / 5000 = 16000 - // round down to nearest bit count for SPINDLE_PWM_MAX_VALUE = 13bits (8192) - #define SPINDLE_PWM_BASE_FREQ 5000 // Hz + #define SPINDLE_PWM_CHANNEL 0 #define SPINDLE_PWM_BIT_PRECISION 8 // be sure to match this with SPINDLE_PWM_MAX_VALUE - #define SPINDLE_PWM_OFF_VALUE 0 - #define SPINDLE_PWM_MAX_VALUE 255 // (2^SPINDLE_PWM_BIT_PRECISION) - - #ifndef SPINDLE_PWM_MIN_VALUE - #define SPINDLE_PWM_MIN_VALUE 1 // Must be greater than zero. - #endif + #define USING_SERVO // uncomment to use this feature //#define USING_SOLENOID // uncomment to use this feature @@ -342,12 +301,7 @@ #define SOLENOID_CHANNEL_NUM 6 #endif - - - #ifdef DEFAULTS_GENERIC - #undef DEFAULTS_GENERIC // undefine generic then define each default below - #endif - + // defaults #define DEFAULT_STEP_PULSE_MICROSECONDS 3 #define DEFAULT_STEPPER_IDLE_LOCK_TIME 250 // stay on @@ -437,28 +391,8 @@ #ifndef IGNORE_CONTROL_PINS // maybe set in config.h #define IGNORE_CONTROL_PINS #endif - //#define CONTROL_SAFETY_DOOR_PIN GPIO_NUM_35 // needs external pullup - //#define CONTROL_RESET_PIN GPIO_NUM_34 // needs external pullup - //#define CONTROL_FEED_HOLD_PIN GPIO_NUM_36 // needs external pullup - //#define CONTROL_CYCLE_START_PIN GPIO_NUM_39 // needs external pullup - // If SPINDLE_PWM_PIN is commented out, this frees up the pin, but Grbl will still - // use a virtual spindle. Do not comment out the other parameters for the spindle. - //#define SPINDLE_PWM_PIN GPIO_NUM_17 // Laser PWM - #define SPINDLE_PWM_CHANNEL 0 - // PWM Generator is based on 80,000,000 Hz counter - // Therefor the freq determines the resolution - // 80,000,000 / freq = max resolution - // For 5000 that is 80,000,000 / 5000 = 16000 - // round down to nearest bit count for SPINDLE_PWM_MAX_VALUE = 13bits (8192) - #define SPINDLE_PWM_BASE_FREQ 5000 // Hz - #define SPINDLE_PWM_BIT_PRECISION 8 // be sure to match this with SPINDLE_PWM_MAX_VALUE - #define SPINDLE_PWM_OFF_VALUE 0 - #define SPINDLE_PWM_MAX_VALUE 255 // (2^SPINDLE_PWM_BIT_PRECISION) - - #ifndef SPINDLE_PWM_MIN_VALUE - #define SPINDLE_PWM_MIN_VALUE 1 // Must be greater than zero. - #endif + // redefine some stuff from config.h #ifdef HOMING_CYCLE_0 @@ -472,18 +406,10 @@ #ifdef HOMING_CYCLE_2 #undef HOMING_CYCLE_2 #endif - - // redefine the defaults - #ifdef DEFAULTS_GENERIC - #undef DEFAULTS_GENERIC - #endif - #define DEFAULTS_MIDTBOT - + #define SERVO_PEN_PIN GPIO_NUM_27 - #ifdef DEFAULTS_GENERIC - #undef DEFAULTS_GENERIC // undefine generic then define each default below - #endif + // defaults #define DEFAULT_STEP_PULSE_MICROSECONDS 3 @@ -590,7 +516,7 @@ // 80,000,000 / freq = max resolution // For 5000 that is 80,000,000 / 5000 = 16000 // round down to nearest bit count for SPINDLE_PWM_MAX_VALUE = 13bits (8192) - #define SPINDLE_PWM_BASE_FREQ 5000 // Hz + //#define SPINDLE_PWM_BASE_FREQ 5000 // Hz #define SPINDLE_PWM_BIT_PRECISION 8 // be sure to match this with SPINDLE_PWM_MAX_VALUE #define SPINDLE_PWM_OFF_VALUE 0 #define SPINDLE_PWM_MAX_VALUE 255 // (2^SPINDLE_PWM_BIT_PRECISION) @@ -615,9 +541,7 @@ #undef HOMING_CYCLE_2 #endif - #ifdef DEFAULTS_GENERIC - #undef DEFAULTS_GENERIC // undefine generic then define each default below - #endif + // defaults #define DEFAULT_STEP_PULSE_MICROSECONDS 3 @@ -706,7 +630,7 @@ // 80,000,000 / freq = max resolution // For 5000 that is 80,000,000 / 5000 = 16000 // round down to nearest bit count for SPINDLE_PWM_MAX_VALUE = 13bits (8192) - #define SPINDLE_PWM_BASE_FREQ 5000 // Hz + //#define SPINDLE_PWM_BASE_FREQ 5000 // Hz #define SPINDLE_PWM_BIT_PRECISION 8 // be sure to match this with SPINDLE_PWM_MAX_VALUE #define SPINDLE_PWM_OFF_VALUE 0 #define SPINDLE_PWM_MAX_VALUE 255 // (2^SPINDLE_PWM_BIT_PRECISION) @@ -726,9 +650,7 @@ #define SERVO_Z_RANGE_MAX 20.0 - #ifdef DEFAULTS_GENERIC - #undef DEFAULTS_GENERIC // undefine generic then define each default below - #endif + // defaults #define DEFAULT_STEP_PULSE_MICROSECONDS 3 @@ -778,128 +700,6 @@ #define DEFAULT_Z_MAX_TRAVEL 100.0 // default calibration value -#endif - -#ifdef CPU_MAP_SM // String art machine definition - #define CPU_MAP_NAME "CPU_MAP_SM" - - #define X_STEP_PIN GPIO_NUM_12 - #define X_DIRECTION_PIN GPIO_NUM_26 - - #define STEPPERS_DISABLE_PIN GPIO_NUM_13 - - #define X_LIMIT_PIN GPIO_NUM_15 - #define LIMIT_MASK B1 - - // If SPINDLE_PWM_PIN is commented out, this frees up the pin, but Grbl will still - // use a virtual spindle. Do not comment out the other parameters for the spindle. - #define SPINDLE_PWM_PIN GPIO_NUM_17 // Laser PWM - #define SPINDLE_PWM_CHANNEL 0 - // PWM Generator is based on 80,000,000 Hz counter - // Therefor the freq determines the resolution - // 80,000,000 / freq = max resolution - // For 5000 that is 80,000,000 / 5000 = 16000 - // round down to nearest bit count for SPINDLE_PWM_MAX_VALUE = 13bits (8192) - #define SPINDLE_PWM_BASE_FREQ 5000 // Hz - #define SPINDLE_PWM_BIT_PRECISION 8 // be sure to match this with SPINDLE_PWM_MAX_VALUE - #define SPINDLE_PWM_OFF_VALUE 0 - #define SPINDLE_PWM_MAX_VALUE 255 // (2^SPINDLE_PWM_BIT_PRECISION) - - #ifndef SPINDLE_PWM_MIN_VALUE - #define SPINDLE_PWM_MIN_VALUE 1 // Must be greater than zero. - #endif - - // define Y and Z as servos - #define USE_SERVO_AXES - #define SERVO_Y_PIN GPIO_NUM_27 - #define SERVO_Y_CHANNEL_NUM 6 - #define SERVO_Y_RANGE_MIN 0.0 - #define SERVO_Y_RANGE_MAX 20.0 - - #define SERVO_Z_PIN GPIO_NUM_14 - #define SERVO_Z_CHANNEL_NUM 5 - #define SERVO_Z_RANGE_MIN 0.0 - #define SERVO_Z_RANGE_MAX 28.0 - - // define the control pins - //#define CONTROL_RESET_PIN GPIO_NUM_36 // needs external pullup - #define CONTROL_FEED_HOLD_PIN GPIO_NUM_34 // needs external pullup - #define CONTROL_CYCLE_START_PIN GPIO_NUM_39 // needs external pullup - - // change some things that may have been defined in config.h - #ifndef IGNORE_CONTROL_PINS - #define IGNORE_CONTROL_PINS - #endif - #ifdef INVERT_CONTROL_PIN_MASK - #undef INVERT_CONTROL_PIN_MASK - #endif - #define INVERT_CONTROL_PIN_MASK B1100 - - - // clear any default homings and set X as the only one - #ifdef HOMING_CYCLE_0 - #undef HOMING_CYCLE_0 - #endif - #define HOMING_CYCLE_0 (1< - #ifdef DEFAULTS_GENERIC - #undef DEFAULTS_GENERIC // undefine generic then define each default below - #endif + #define DEFAULT_STEP_PULSE_MICROSECONDS 3 #define DEFAULT_STEPPER_IDLE_LOCK_TIME 200 // 200ms diff --git a/Grbl_Esp32/defaults.h b/Grbl_Esp32/defaults.h index b98bb645..f33447f3 100644 --- a/Grbl_Esp32/defaults.h +++ b/Grbl_Esp32/defaults.h @@ -30,128 +30,272 @@ #ifndef defaults_h +/* + All of these settings check to see if they have been defined already + before defining them. This allows to to easily set them eslewhere. + You only need to set ones that are important or unique to your + machine. The rest will be pulled from here. +*/ -#ifdef DEFAULTS_GENERIC // Grbl generic default settings. Should work across different machines. - #define DEFAULT_STEP_PULSE_MICROSECONDS 3 - #define DEFAULT_STEPPER_IDLE_LOCK_TIME 250 // msec (0-254, 255 keeps steppers enabled) +#ifndef DEFAULT_STEP_PULSE_MICROSECONDS + #define DEFAULT_STEP_PULSE_MICROSECONDS 3 // $0 +#endif - #define DEFAULT_STEPPING_INVERT_MASK 0 // uint8_t - #define DEFAULT_DIRECTION_INVERT_MASK 0 // uint8_t - #define DEFAULT_INVERT_ST_ENABLE 0 // boolean - #define DEFAULT_INVERT_LIMIT_PINS 1 // boolean - #define DEFAULT_INVERT_PROBE_PIN 0 // boolean - - #define DEFAULT_STATUS_REPORT_MASK 1 - - #define DEFAULT_JUNCTION_DEVIATION 0.01 // mm - #define DEFAULT_ARC_TOLERANCE 0.002 // mm - #define DEFAULT_REPORT_INCHES 0 // false - - #define DEFAULT_SOFT_LIMIT_ENABLE 0 // false - #define DEFAULT_HARD_LIMIT_ENABLE 0 // false - - #define DEFAULT_HOMING_ENABLE 0 // false - #define DEFAULT_HOMING_DIR_MASK 3 // move positive dir Z, negative X,Y - #define DEFAULT_HOMING_FEED_RATE 200.0 // mm/min - #define DEFAULT_HOMING_SEEK_RATE 2000.0 // mm/min - #define DEFAULT_HOMING_DEBOUNCE_DELAY 250 // msec (0-65k) - #define DEFAULT_HOMING_PULLOFF 1.0 // mm - - #define DEFAULT_SPINDLE_RPM_MAX 1000.0 // rpm - #define DEFAULT_SPINDLE_RPM_MIN 0.0 // rpm - - #define DEFAULT_LASER_MODE 0 // false - - #define DEFAULT_X_STEPS_PER_MM 800.0 - #define DEFAULT_Y_STEPS_PER_MM 800.0 - #define DEFAULT_Z_STEPS_PER_MM 800.0 - #define DEFAULT_A_STEPS_PER_MM 100.0 - #define DEFAULT_B_STEPS_PER_MM 100.0 - #define DEFAULT_C_STEPS_PER_MM 100.0 - - #define DEFAULT_X_MAX_RATE 5000.0 // mm/min - #define DEFAULT_Y_MAX_RATE 4000.0 // mm/min - #define DEFAULT_Z_MAX_RATE 3000.0 // mm/min - #define DEFAULT_A_MAX_RATE 1000.0 // mm/min - #define DEFAULT_B_MAX_RATE 1000.0 // mm/min - #define DEFAULT_C_MAX_RATE 1000.0 // mm/min - - #define DEFAULT_X_ACCELERATION (200.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 - #define DEFAULT_Y_ACCELERATION (200.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 - #define DEFAULT_Z_ACCELERATION (200.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 - #define DEFAULT_A_ACCELERATION (100.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 - #define DEFAULT_B_ACCELERATION (100.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 - #define DEFAULT_C_ACCELERATION (100.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 - - - #define DEFAULT_X_MAX_TRAVEL 300.0 // mm NOTE: Must be a positive value. - #define DEFAULT_Y_MAX_TRAVEL 300.0 // mm NOTE: Must be a positive value. - #define DEFAULT_Z_MAX_TRAVEL 300.0 // mm NOTE: Must be a positive value. - #define DEFAULT_A_MAX_TRAVEL 100.0 // mm NOTE: Must be a positive value. - #define DEFAULT_B_MAX_TRAVEL 100.0 // mm NOTE: Must be a positive value. - #define DEFAULT_C_MAX_TRAVEL 100.0 // mm NOTE: Must be a positive value. - - +#ifndef DEFAULT_STEPPER_IDLE_LOCK_TIME + #define DEFAULT_STEPPER_IDLE_LOCK_TIME 250 // $1 msec (0-254, 255 keeps steppers enabled) +#endif + +#ifndef DEFAULT_STEPPING_INVERT_MASK + #define DEFAULT_STEPPING_INVERT_MASK 0 // $2 uint8_t #endif -#ifdef DEFAULTS_MPCNC - // Grbl generic default settings. Should work across different machines. - #define DEFAULT_STEP_PULSE_MICROSECONDS 3 - #define DEFAULT_STEPPER_IDLE_LOCK_TIME 255 // 255 = Keep steppers on +#ifndef DEFAULT_DIRECTION_INVERT_MASK + #define DEFAULT_DIRECTION_INVERT_MASK 0 // $3 uint8_ +#endif - #define DEFAULT_STEPPING_INVERT_MASK 0 // uint8_t - #define DEFAULT_DIRECTION_INVERT_MASK 0 // uint8_t - #define DEFAULT_INVERT_ST_ENABLE 0 // boolean - #define DEFAULT_INVERT_LIMIT_PINS 1 // boolean - #define DEFAULT_INVERT_PROBE_PIN 0 // boolean +#ifndef DEFAULT_INVERT_ST_ENABLE + #define DEFAULT_INVERT_ST_ENABLE 0 // $4 boolean +#endif + +#ifndef DEFAULT_INVERT_LIMIT_PINS + #define DEFAULT_INVERT_LIMIT_PINS 1 // $5 boolean +#endif - #define DEFAULT_STATUS_REPORT_MASK 1 +#ifndef DEFAULT_INVERT_PROBE_PIN +#define DEFAULT_INVERT_PROBE_PIN 0 // $6 boolean +#endif - #define DEFAULT_JUNCTION_DEVIATION 0.01 // mm - #define DEFAULT_ARC_TOLERANCE 0.002 // mm - #define DEFAULT_REPORT_INCHES 0 // false +#ifndef DEFAULT_STATUS_REPORT_MASK + #define DEFAULT_STATUS_REPORT_MASK 1 // $10 +#endif - #define DEFAULT_SOFT_LIMIT_ENABLE 0 // false - #define DEFAULT_HARD_LIMIT_ENABLE 0 // false +#ifndef DEFAULT_JUNCTION_DEVIATION + #define DEFAULT_JUNCTION_DEVIATION 0.01 // $11 mm +#endif - #define DEFAULT_HOMING_ENABLE 1 // false - #define DEFAULT_HOMING_DIR_MASK 3 // move positive dir Z,negative X,Y - #define DEFAULT_HOMING_FEED_RATE 600.0 // mm/min - #define DEFAULT_HOMING_SEEK_RATE 2000.0 // mm/min - #define DEFAULT_HOMING_DEBOUNCE_DELAY 250 // msec (0-65k) - #define DEFAULT_HOMING_PULLOFF 1.5 // mm +#ifndef DEFAULT_ARC_TOLERANCE + #define DEFAULT_ARC_TOLERANCE 0.002 // $12 mm +#endif - #ifdef USE_SPINDLE_RELAY - #define DEFAULT_SPINDLE_RPM_MAX 1.0 // must be 1 so PWM duty is alway 100% to prevent relay damage - #else - #define DEFAULT_SPINDLE_RPM_MAX 1000.0 // can be change to your spindle max - #endif - +#ifndef DEFAULT_REPORT_INCHES +#define DEFAULT_REPORT_INCHES 0 // $13 false +#endif + +#ifndef DEFAULT_SOFT_LIMIT_ENABLE + #define DEFAULT_SOFT_LIMIT_ENABLE 0 // $20 false +#endif + +#ifndef DEFAULT_HARD_LIMIT_ENABLE +#define DEFAULT_HARD_LIMIT_ENABLE 0 // $21 false +#endif + +#ifndef DEFAULT_HOMING_ENABLE + #define DEFAULT_HOMING_ENABLE 0 // $22 false +#endif + +#ifndef DEFAULT_HOMING_DIR_MASK +#define DEFAULT_HOMING_DIR_MASK 3 // $23 move positive dir Z, negative X,Y +#endif + +#ifndef DEFAULT_HOMING_FEED_RATE + #define DEFAULT_HOMING_FEED_RATE 200.0 // $24 mm/min +#endif + +#ifndef DEFAULT_HOMING_SEEK_RATE +#define DEFAULT_HOMING_SEEK_RATE 2000.0 // $25 mm/min +#endif + +#ifndef DEFAULT_HOMING_DEBOUNCE_DELAY + #define DEFAULT_HOMING_DEBOUNCE_DELAY 250 // $26 msec (0-65k) +#endif + +#ifndef DEFAULT_HOMING_PULLOFF + #define DEFAULT_HOMING_PULLOFF 1.0 // $27 mm +#endif + +// ======== sPINDLE STUFF ==================== + +#ifndef DEFAULT_SPINDLE_FREQ + #define DEFAULT_SPINDLE_FREQ 5000.0 // $33 Hz (extended set) +#endif + +#ifndef DEFAULT_SPINDLE_OFF_VALUE + #define DEFAULT_SPINDLE_OFF_VALUE 0.0 // $34 Percent (extended set) +#endif + +#ifndef DEFAULT_SPINDLE_MIN_VALUE + #define DEFAULT_SPINDLE_MIN_VALUE 0.0 // $35 Percent (extended set) +#endif + +#ifndef DEFAULT_SPINDLE_MAX_VALUE + #define DEFAULT_SPINDLE_MAX_VALUE 100.0 // $36 Percent (extended set) +#endif + +#ifndef DEFAULT_SPINDLE_RPM_MAX + #define DEFAULT_SPINDLE_RPM_MAX 1000.0 // rpm +#endif + + +#ifndef DEFAULT_SPINDLE_RPM_MIN #define DEFAULT_SPINDLE_RPM_MIN 0.0 // rpm +#endif +#ifndef DEFAULT_LASER_MODE #define DEFAULT_LASER_MODE 0 // false +#endif - #define DEFAULT_X_STEPS_PER_MM 200.0 - #define DEFAULT_Y_STEPS_PER_MM 200.0 + +// =========== AXIS RESOLUTION ====== + +#ifndef DEFAULT_X_STEPS_PER_MM + #define DEFAULT_X_STEPS_PER_MM 800.0 +#endif +#ifndef DEFAULT_Y_STEPS_PER_MM + #define DEFAULT_Y_STEPS_PER_MM 800.0 +#endif +#ifndef DEFAULT_Z_STEPS_PER_MM #define DEFAULT_Z_STEPS_PER_MM 800.0 +#endif +#ifndef DEFAULT_A_STEPS_PER_MM + #define DEFAULT_A_STEPS_PER_MM 800.0 +#endif +#ifndef DEFAULT_B_STEPS_PER_MM + #define DEFAULT_B_STEPS_PER_MM 800.0 +#endif +#ifndef DEFAULT_C_STEPS_PER_MM + #define DEFAULT_C_STEPS_PER_MM 800.0 +#endif - #define DEFAULT_X_MAX_RATE 8000.0 // mm/min - #define DEFAULT_Y_MAX_RATE 8000.0 // mm/min - #define DEFAULT_Z_MAX_RATE 3000.0 // mm/min +// ============ AXIS MAX SPPED ========= +#ifndef DEFAULT_X_MAX_RATE + #define DEFAULT_X_MAX_RATE 5000.0 // mm/min +#endif +#ifndef DEFAULT_Y_MAX_RATE + #define DEFAULT_Y_MAX_RATE 5000.0 // mm/min +#endif +#ifndef DEFAULT_Z_MAX_RATE + #define DEFAULT_Z_MAX_RATE 5000.0 // mm/min +#endif +#ifndef DEFAULT_A_MAX_RATE + #define DEFAULT_A_MAX_RATE 5000.0 // mm/min +#endif +#ifndef DEFAULT_B_MAX_RATE + #define DEFAULT_B_MAX_RATE 5000.0 // mm/min +#endif +#ifndef DEFAULT_C_MAX_RATE + #define DEFAULT_C_MAX_RATE 5000.0 // mm/min +#endif + +// ============== Axis Acceleration ========= + +#ifndef DEFAULT_X_ACCELERATION #define DEFAULT_X_ACCELERATION (200.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 +#endif +#ifndef DEFAULT_Y_ACCELERATION #define DEFAULT_Y_ACCELERATION (200.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 - #define DEFAULT_Z_ACCELERATION (100.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 +#endif +#ifndef DEFAULT_Z_ACCELERATION + #define DEFAULT_Z_ACCELERATION (200.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 +#endif +#ifndef DEFAULT_A_ACCELERATION + #define DEFAULT_A_ACCELERATION (200.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 +#endif +#ifndef DEFAULT_B_ACCELERATION + #define DEFAULT_B_ACCELERATION (200.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 +#endif +#ifndef DEFAULT_C_ACCELERATION + #define DEFAULT_C_ACCELERATION (200.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 +#endif - #define DEFAULT_X_MAX_TRAVEL 500.0 // mm NOTE: Must be a positive value. - #define DEFAULT_Y_MAX_TRAVEL 500.0 // mm NOTE: Must be a positive value. - #define DEFAULT_Z_MAX_TRAVEL 80.0 // mm NOTE: Must be a positive value. +// ========= AXIS MAX TRAVEL ============ +#ifndef DEFAULT_X_MAX_TRAVEL + #define DEFAULT_X_MAX_TRAVEL 300.0 // $130 mm NOTE: Must be a positive value. +#endif +#ifndef DEFAULT_Y_MAX_TRAVEL + #define DEFAULT_Y_MAX_TRAVEL 300.0 // mm NOTE: Must be a positive value. +#endif +#ifndef DEFAULT_Z_MAX_TRAVEL + #define DEFAULT_Z_MAX_TRAVEL 300.0 // mm NOTE: Must be a positive value. +#endif +#ifndef DEFAULT_A_TRAVEL + #define DEFAULT_A_MAX_TRAVEL 300.0 // mm NOTE: Must be a positive value. +#endif +#ifndef DEFAULT_B_MAX_TRAVEL + #define DEFAULT_B_MAX_TRAVEL 300.0 // mm NOTE: Must be a positive value. +#endif +#ifndef DEFAULT_C_MAX_TRAVEL + #define DEFAULT_C_MAX_TRAVEL 300.0 // mm NOTE: Must be a positive value. +#endif +// ========== Motor current (SPI Drivers ) ============= +#ifndef DEFAULT_X_CURRENT + #define DEFAULT_X_CURRENT 0.25 // $140 current in amps (extended set) +#endif +#ifndef DEFAULT_Y_CURRENT + #define DEFAULT_Y_CURRENT 0.25 // $141 current in amps (extended set) +#endif +#ifndef DEFAULT_Z_CURRENT + #define DEFAULT_Z_CURRENT 0.25 // $142 current in amps (extended set) +#endif +#ifndef DEFAULT_A_CURRENT + #define DEFAULT_A_CURRENT 0.25 // $143 current in amps (extended set) +#endif +#ifndef DEFAULT_B_CURRENT + #define DEFAULT_B_CURRENT 0.25 // $144 current in amps (extended set) +#endif +#ifndef DEFAULT_C_CURRENT + #define DEFAULT_C_CURRENT 0.25 // $145 current in amps (extended set) +#endif + +// ========== Motor hold current (SPI Drivers ) ============= + +#ifndef DEFAULT_X_HOLD_CURRENT + #define DEFAULT_X_HOLD_CURRENT 50 // $150 percent of run current (extended set) +#endif +#ifndef DEFAULT_Y_HOLD_CURRENT + #define DEFAULT_Y_HOLD_CURRENT 50 // $151 percent of run current (extended set) +#endif +#ifndef DEFAULT_Z_HOLD_CURRENT + #define DEFAULT_Z_HOLD_CURRENT 50 // $152 percent of run current (extended set) +#endif +#ifndef DEFAULT_A_HOLD_CURRENT + #define DEFAULT_A_HOLD_CURRENT 50 // $153 percent of run current (extended set) +#endif +#ifndef DEFAULT_B_HOLD_CURRENT + #define DEFAULT_B_HOLD_CURRENT 50 // $154 percent of run current (extended set) +#endif +#ifndef DEFAULT_C_HOLD_CURRENT + #define DEFAULT_C_HOLD_CURRENT 50 // $154 percent of run current (extended set) +#endif + +// ========== Microsteps (SPI Drivers ) ================ + +#ifndef DEFAULT_X_MICROSTEPS + #define DEFAULT_X_MICROSTEPS 16 // $160 micro steps (extended set) +#endif +#ifndef DEFAULT_Y_MICROSTEPS + #define DEFAULT_Y_MICROSTEPS 16 // $161 micro steps (extended set) +#endif +#ifndef DEFAULT_Z_MICROSTEPS + #define DEFAULT_Z_MICROSTEPS 16 // $162 micro steps (extended set) +#endif +#ifndef DEFAULT_A_MICROSTEPS + #define DEFAULT_A_MICROSTEPS 16 // $163 micro steps (extended set) +#endif +#ifndef DEFAULT_B_MICROSTEPS + #define DEFAULT_B_MICROSTEPS 16 // $164 micro steps (extended set) +#endif +#ifndef DEFAULT_C_MICROSTEPS + #define DEFAULT_C_MICROSTEPS 16 // $165 micro steps (extended set) #endif + + + #endif diff --git a/Grbl_Esp32/grbl.h b/Grbl_Esp32/grbl.h index 6e6f516c..e2387f94 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 "20191023" +#define GRBL_VERSION_BUILD "20191103" //#include #include diff --git a/Grbl_Esp32/grbl_trinamic.cpp b/Grbl_Esp32/grbl_trinamic.cpp index a431ca3e..70931b82 100644 --- a/Grbl_Esp32/grbl_trinamic.cpp +++ b/Grbl_Esp32/grbl_trinamic.cpp @@ -102,19 +102,15 @@ void Trinamic_Init() { - grbl_sendf(CLIENT_SERIAL, "[MSG:Using TMCStepper Library Ver 0x%06x]\r\n", TMCSTEPPER_VERSION); + grbl_sendf(CLIENT_SERIAL, "[MSG:TMCStepper Init using Library Ver 0x%06x]\r\n", TMCSTEPPER_VERSION); SPI.begin(); #ifdef X_TRINAMIC TRINAMIC_X.begin(); // Initiate pins and registries TRINAMIC_X.toff(5); - TRINAMIC_X.microsteps(X_MICROSTEPS); - #ifdef X_HOLD_CURRENT - TRINAMIC_X.rms_current(X_RMS_CURRENT, X_HOLD_CURRENT); - #else - TRINAMIC_X.rms_current(X_RMS_CURRENT); // default hold current is 0.5 or 50% - #endif + 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 TRINAMIC_X.pwm_autoscale(1); #endif @@ -122,12 +118,8 @@ void Trinamic_Init() #ifdef Y_TRINAMIC TRINAMIC_Y.begin(); // Initiate pins and registries TRINAMIC_Y.toff(5); - TRINAMIC_Y.microsteps(Y_MICROSTEPS); - #ifdef Y_HOLD_CURRENT - TRINAMIC_Y.rms_current(Y_RMS_CURRENT, Y_HOLD_CURRENT); - #else - TRINAMIC_Y.rms_current(Y_RMS_CURRENT); // default hold current is 0.5 or 50% - #endif + TRINAMIC_Y.microsteps(settings.microsteps[Y_AXIS]); + TRINAMIC_X.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 TRINAMIC_Y.pwm_autoscale(1); #endif @@ -135,8 +127,8 @@ void Trinamic_Init() #ifdef Z_TRINAMIC TRINAMIC_Z.begin(); // Initiate pins and registries TRINAMIC_Z.toff(5); - TRINAMIC_Z.microsteps(Z_MICROSTEPS); - TRINAMIC_Z.rms_current(Z_RMS_CURRENT); + TRINAMIC_Z.microsteps(settings.microsteps[Z_AXIS]); + TRINAMIC_X.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 TRINAMIC_Z.pwm_autoscale(1); #endif @@ -144,8 +136,8 @@ void Trinamic_Init() #ifdef A_TRINAMIC TRINAMIC_A.begin(); // Initiate pins and registries TRINAMIC_A.toff(5); - TRINAMIC_A.microsteps(A_MICROSTEPS); - TRINAMIC_A.rms_current(A_RMS_CURRENT); + TRINAMIC_A.microsteps(settings.microsteps[A_AXIS]); + TRINAMIC_X.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 TRINAMIC_A.pwm_autoscale(1); #endif @@ -153,8 +145,8 @@ void Trinamic_Init() #ifdef B_TRINAMIC TRINAMIC_B.begin(); // Initiate pins and registries TRINAMIC_B.toff(5); - TRINAMIC_B.microsteps(B_MICROSTEPS); - TRINAMIC_B.rms_current(B_RMS_CURRENT); + TRINAMIC_B.microsteps(settings.microsteps[B_AXIS]); + TTRINAMIC_X.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 TRINAMIC_B.pwm_autoscale(1); #endif @@ -162,13 +154,46 @@ void Trinamic_Init() #ifdef C_TRINAMIC TRINAMIC_C.begin(); // Initiate pins and registries TRINAMIC_C.toff(5); - TRINAMIC_C.microsteps(C_MICROSTEPS); - TRINAMIC_C.rms_current(C_RMS_CURRENT); + TRINAMIC_C.microsteps(settings.microsteps[C_AXIS]); + TRINAMIC_X.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 TRINAMIC_C.pwm_autoscale(1); #endif - // TODO ABC Axes + +} + +void trinamic_change_settings() +{ + #ifdef X_TRINAMIC + TRINAMIC_X.microsteps(settings.microsteps[X_AXIS]); + TRINAMIC_X.rms_current(settings.current[X_AXIS] * 1000.0, settings.hold_current[X_AXIS]/100.0); + #endif + + #ifdef Y_TRINAMIC + TRINAMIC_Y.microsteps(settings.microsteps[Y_AXIS]); + TRINAMIC_X.rms_current(settings.current[Y_AXIS] * 1000.0, settings.hold_current[Y_AXIS]/100.0); + #endif + + #ifdef Z_TRINAMIC + TRINAMIC_Z.microsteps(settings.microsteps[Z_AXIS]); + TRINAMIC_X.rms_current(settings.current[Z_AXIS] * 1000.0, settings.hold_current[Z_AXIS]/100.0); + #endif + + #ifdef A_TRINAMIC + TRINAMIC_A.microsteps(settings.microsteps[A_AXIS]); + TRINAMIC_X.rms_current(settings.current[A_AXIS] * 1000.0, settings.hold_current[A_AXIS]/100.0); + #endif + + #ifdef B_TRINAMIC + TRINAMIC_B.microsteps(settings.microsteps[B_AXIS]); + TTRINAMIC_X.rms_current(settings.current[B_AXIS] * 1000.0, settings.hold_current[B_AXIS]/100.0); + #endif + + #ifdef C_TRINAMIC + TRINAMIC_C.microsteps(settings.microsteps[C_AXIS]); + TRINAMIC_X.rms_current(settings.current[C_AXIS] * 1000.0, settings.hold_current[C_AXIS]/100.0); + #endif } #endif \ No newline at end of file diff --git a/Grbl_Esp32/grbl_trinamic.h b/Grbl_Esp32/grbl_trinamic.h index 92239f49..9723124a 100644 --- a/Grbl_Esp32/grbl_trinamic.h +++ b/Grbl_Esp32/grbl_trinamic.h @@ -26,6 +26,7 @@ #ifdef USE_TRINAMIC #include // https://github.com/teemuatlut/TMCStepper void Trinamic_Init(); + void trinamic_change_settings(); #endif #endif \ No newline at end of file diff --git a/Grbl_Esp32/report.cpp b/Grbl_Esp32/report.cpp index 34dbe274..033424bf 100644 --- a/Grbl_Esp32/report.cpp +++ b/Grbl_Esp32/report.cpp @@ -284,7 +284,7 @@ void report_grbl_help(uint8_t client) { void report_grbl_settings(uint8_t client) { // Print Grbl settings. char setting[20]; - char rpt[800]; + char rpt[1000]; rpt[0] = '\0'; @@ -300,7 +300,8 @@ void report_grbl_settings(uint8_t client) { sprintf(setting, "$11=%4.3f\r\n", settings.junction_deviation); strcat(rpt, setting); sprintf(setting, "$12=%4.3f\r\n", settings.arc_tolerance); strcat(rpt, setting); - sprintf(setting, "$13=%d\r\n", bit_istrue(settings.flags,BITFLAG_REPORT_INCHES)); strcat(rpt, setting); + + sprintf(setting, "$13=%d\r\n", bit_istrue(settings.flags,BITFLAG_REPORT_INCHES)); strcat(rpt, setting); sprintf(setting, "$20=%d\r\n", bit_istrue(settings.flags,BITFLAG_SOFT_LIMIT_ENABLE)); strcat(rpt, setting); sprintf(setting, "$21=%d\r\n", bit_istrue(settings.flags,BITFLAG_HARD_LIMIT_ENABLE)); strcat(rpt, setting); sprintf(setting, "$22=%d\r\n", bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)); strcat(rpt, setting); @@ -320,6 +321,13 @@ void report_grbl_settings(uint8_t client) { #else strcat(rpt, "$32=0\r\n"); #endif + + #ifdef SHOW_EXTENDED_SETTINGS + sprintf(setting, "$33=%5.3f\r\n", settings.spindle_pwm_freq); strcat(rpt, setting); + sprintf(setting, "$34=%3.3f\r\n", settings.spindle_pwm_off_value); strcat(rpt, setting); + sprintf(setting, "$35=%3.3f\r\n", settings.spindle_pwm_min_value); strcat(rpt, setting); + sprintf(setting, "$36=%3.3f\r\n", settings.spindle_pwm_max_value); strcat(rpt, setting); + #endif // Print axis settings uint8_t idx, set_idx; @@ -330,7 +338,12 @@ void report_grbl_settings(uint8_t client) { case 0: sprintf(setting, "$%d=%4.3f\r\n", val+idx, settings.steps_per_mm[idx]); strcat(rpt, setting); break; case 1: sprintf(setting, "$%d=%4.3f\r\n", val+idx, settings.max_rate[idx]); strcat(rpt, setting); break; case 2: sprintf(setting, "$%d=%4.3f\r\n", val+idx, settings.acceleration[idx]/(60*60)); strcat(rpt, setting); break; - case 3: sprintf(setting, "$%d=%4.3f\r\n", val+idx, -settings.max_travel[idx]); strcat(rpt, setting); break; + case 3: sprintf(setting, "$%d=%4.3f\r\n", val+idx, -settings.max_travel[idx]); strcat(rpt, setting); break; + #ifdef SHOW_EXTENDED_SETTINGS + case 4: sprintf(setting, "$%d=%4.3f\r\n", val+idx, settings.current[idx]); strcat(rpt, setting); break; + case 5: sprintf(setting, "$%d=%4.3f\r\n", val+idx, settings.hold_current[idx]); strcat(rpt, setting); break; + case 6: sprintf(setting, "$%d=%d\r\n", val+idx, settings.microsteps[idx]); strcat(rpt, setting); break; + #endif } } val += AXIS_SETTINGS_INCREMENT; @@ -494,7 +507,7 @@ void report_gcode_modes(uint8_t client) } strcat(modes_rpt, temp); - #ifdef VARIABLE_SPINDLE + #ifdef VARIABLE_SPINDLE sprintf(temp, " S%4.3f", gc_state.spindle_speed); strcat(modes_rpt, temp); #endif diff --git a/Grbl_Esp32/settings.cpp b/Grbl_Esp32/settings.cpp index bb7da925..5b228188 100644 --- a/Grbl_Esp32/settings.cpp +++ b/Grbl_Esp32/settings.cpp @@ -68,7 +68,12 @@ void settings_restore(uint8_t restore_flag) { settings.junction_deviation = DEFAULT_JUNCTION_DEVIATION; settings.arc_tolerance = DEFAULT_ARC_TOLERANCE; - + + settings.spindle_pwm_freq = DEFAULT_SPINDLE_FREQ; // $33 Hz (extended set) + settings.spindle_pwm_off_value = DEFAULT_SPINDLE_OFF_VALUE; // $34 Percent (extended set) + settings.spindle_pwm_min_value = DEFAULT_SPINDLE_MIN_VALUE; // $35 Percent (extended set) + settings.spindle_pwm_max_value = DEFAULT_SPINDLE_MAX_VALUE; // $36 Percent (extended set) + settings.rpm_max = DEFAULT_SPINDLE_RPM_MAX; settings.rpm_min = DEFAULT_SPINDLE_RPM_MIN; @@ -91,21 +96,41 @@ void settings_restore(uint8_t restore_flag) { settings.steps_per_mm[X_AXIS] = DEFAULT_X_STEPS_PER_MM; settings.steps_per_mm[Y_AXIS] = DEFAULT_Y_STEPS_PER_MM; settings.steps_per_mm[Z_AXIS] = DEFAULT_Z_STEPS_PER_MM; + settings.max_rate[X_AXIS] = DEFAULT_X_MAX_RATE; settings.max_rate[Y_AXIS] = DEFAULT_Y_MAX_RATE; settings.max_rate[Z_AXIS] = DEFAULT_Z_MAX_RATE; + settings.acceleration[X_AXIS] = DEFAULT_X_ACCELERATION; settings.acceleration[Y_AXIS] = DEFAULT_Y_ACCELERATION; settings.acceleration[Z_AXIS] = DEFAULT_Z_ACCELERATION; + 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; + + settings.hold_current[X_AXIS] = DEFAULT_X_HOLD_CURRENT; + settings.hold_current[Y_AXIS] = DEFAULT_Y_HOLD_CURRENT; + settings.hold_current[Z_AXIS] = DEFAULT_Z_HOLD_CURRENT; + + settings.microsteps[X_AXIS] = DEFAULT_X_MICROSTEPS; + settings.microsteps[Y_AXIS] = DEFAULT_Y_MICROSTEPS; + settings.microsteps[Z_AXIS] = DEFAULT_Z_MICROSTEPS; + + + #if (N_AXIS > A_AXIS) settings.steps_per_mm[A_AXIS] = DEFAULT_A_STEPS_PER_MM; settings.max_rate[A_AXIS] = DEFAULT_A_MAX_RATE; settings.acceleration[A_AXIS] = DEFAULT_A_ACCELERATION; settings.max_travel[A_AXIS] = (-DEFAULT_A_MAX_TRAVEL); + settings.current[A_AXIS] = DEFAULT_A_CURRENT; + settings.hold_current[A_AXIS] = DEFAULT_A_HOLD_CURRENT; + settings.microsteps[A_AXIS] = DEFAULT_A_MICROSTEPS; #endif #if (N_AXIS > B_AXIS) @@ -113,6 +138,9 @@ void settings_restore(uint8_t restore_flag) { settings.max_rate[B_AXIS] = DEFAULT_B_MAX_RATE; settings.acceleration[B_AXIS] = DEFAULT_B_ACCELERATION; settings.max_travel[B_AXIS] = (-DEFAULT_B_MAX_TRAVEL); + settings.current[B_AXIS] = DEFAULT_B_CURRENT; + settings.hold_current[B_AXIS] = DEFAULT_B_HOLD_CURRENT; + settings.microsteps[B_AXIS] = DEFAULT_B_MICROSTEPS; #endif #if (N_AXIS > C_AXIS) @@ -120,6 +148,9 @@ void settings_restore(uint8_t restore_flag) { settings.max_rate[C_AXIS] = DEFAULT_C_MAX_RATE; settings.acceleration[C_AXIS] = DEFAULT_C_ACCELERATION; settings.max_travel[C_AXIS] = (-DEFAULT_C_MAX_TRAVEL); + settings.current[C_AXIS] = DEFAULT_C_CURRENT; + settings.hold_current[C_AXIS] = DEFAULT_C_HOLD_CURRENT; + settings.microsteps[C_AXIS] = DEFAULT_C_MICROSTEPS; #endif @@ -241,6 +272,7 @@ uint8_t settings_read_startup_line(uint8_t n, char *line) // A helper method to set settings from command line uint8_t settings_store_global_setting(uint8_t parameter, float value) { if (value < 0.0) { return(STATUS_NEGATIVE_VALUE); } + uint8_t int_value = trunc(value); // integer version if (parameter >= AXIS_SETTINGS_START_VAL) { // Store axis configuration. Axis numbering sequence set by AXIS_SETTING defines. // NOTE: Ensure the setting index corresponds to the report.c settings printout. @@ -264,6 +296,18 @@ 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: // run current + settings.current[parameter] = value; + settings_spi_driver_init(); + break; + case 5: // hold current + settings.hold_current[parameter] = value; + settings_spi_driver_init(); + break; + case 6: // microstepping + settings.microsteps[parameter] = int_value; + settings_spi_driver_init(); + break; } break; // Exit while-loop after setting has been configured and proceed to the EEPROM write call. } else { @@ -275,7 +319,7 @@ uint8_t settings_store_global_setting(uint8_t parameter, float value) { } } else { // Store non-axis Grbl settings - uint8_t int_value = trunc(value); + switch(parameter) { case 0: if (int_value < 3) { return(STATUS_SETTING_STEP_PULSE_MIN); } @@ -343,6 +387,10 @@ uint8_t settings_store_global_setting(uint8_t parameter, float value) { return(STATUS_SETTING_DISABLED_LASER); #endif break; + case 33: settings.spindle_pwm_freq = value; spindle_init(); break; // Re-initialize spindle pwm calibration + case 34: settings.spindle_pwm_off_value = value; spindle_init(); break; // Re-initialize spindle pwm calibration + case 35: settings.spindle_pwm_min_value = value; spindle_init(); break; // Re-initialize spindle pwm calibration + case 36: settings.spindle_pwm_max_value = value; spindle_init(); break; // Re-initialize spindle pwm calibration default: return(STATUS_INVALID_STATEMENT); } @@ -351,9 +399,6 @@ uint8_t settings_store_global_setting(uint8_t parameter, float value) { return(STATUS_OK); } - - - // Returns step pin mask according to Grbl internal axis indexing. uint8_t get_step_pin_mask(uint8_t axis_idx) { @@ -361,10 +406,18 @@ uint8_t get_step_pin_mask(uint8_t axis_idx) return(1<= 100 for axis settings. Up to 255. #define AXIS_SETTINGS_INCREMENT 10 // Must be greater than the number of axis settings @@ -86,6 +90,9 @@ typedef struct { float max_rate[N_AXIS]; float acceleration[N_AXIS]; float max_travel[N_AXIS]; + float current[N_AXIS]; // $140... run current (extended set) + float hold_current[N_AXIS]; // $150 percent of run current (extended set) + uint16_t microsteps[N_AXIS]; // $160... (extended set) // Remaining Grbl settings uint8_t pulse_microseconds; @@ -95,7 +102,12 @@ typedef struct { uint8_t status_report_mask; // Mask to indicate desired report data. float junction_deviation; float arc_tolerance; - + + float spindle_pwm_freq; // $33 Hz (extended set) + float spindle_pwm_off_value; // $34 Percent (extended set) + float spindle_pwm_min_value; // $35 Percent (extended set) + float spindle_pwm_max_value; // $36 Percent (extended set) + float rpm_max; float rpm_min; @@ -135,7 +147,7 @@ uint8_t get_step_pin_mask(uint8_t i); // Returns the direction pin mask according to Grbl's internal axis numbering uint8_t get_direction_pin_mask(uint8_t i); - +void settings_spi_driver_init(); #endif diff --git a/Grbl_Esp32/spindle_control.cpp b/Grbl_Esp32/spindle_control.cpp index a85ba092..b7064506 100644 --- a/Grbl_Esp32/spindle_control.cpp +++ b/Grbl_Esp32/spindle_control.cpp @@ -22,10 +22,15 @@ #ifdef SPINDLE_PWM_PIN static float pwm_gradient; // Precalulated value to speed up rpm to PWM conversions. +float spindle_pwm_period; +float spindle_pwm_off_value; +float spindle_pwm_min_value; +float spindle_pwm_max_value; #endif void spindle_init() { + #ifdef SPINDLE_PWM_PIN #ifdef INVERT_SPINDLE_PWM @@ -35,9 +40,27 @@ void spindle_init() #ifdef INVERT_SPINDLE_ENABLE_PIN grbl_send(CLIENT_SERIAL, "[MSG: INVERT_SPINDLE_ENABLE_PIN]\r\n"); #endif - - pwm_gradient = SPINDLE_PWM_RANGE/(settings.rpm_max-settings.rpm_min); - //grbl_sendf(CLIENT_SERIAL, "[MSG:pwm_gradient %4.4f SPINDLE_PWM_RANGE %d]\r\n", pwm_gradient, SPINDLE_PWM_RANGE); + + spindle_pwm_period = SPINDLE_PULSE_RES_COUNT; + + + spindle_pwm_off_value = (spindle_pwm_period * settings.spindle_pwm_off_value / 100); + spindle_pwm_min_value = (spindle_pwm_period * settings.spindle_pwm_min_value / 100); + spindle_pwm_max_value = (spindle_pwm_period * settings.spindle_pwm_max_value / 100); + + //pwm_gradient = (settings.spindle_pwm_max_value - settings.spindle_pwm_min_value)/(settings.rpm_max-settings.rpm_min); + pwm_gradient = (spindle_pwm_max_value-spindle_pwm_min_value)/(settings.rpm_max-settings.rpm_min); + + + if ( (F_TIMERS / (uint32_t)settings.spindle_pwm_freq) < spindle_pwm_max_value) { + /* + PWM Generator is based on 80,000,000 Hz counter + Therefor the freq determines the resolution 80,000,000 / freq = max resolution + For 5000 that is 80,000,000 / 5000 = 16000 + Round down to nearest bit count for SPINDLE_PWM_MAX_VALUE = 13bits (8192) + */ + grbl_sendf(CLIENT_SERIAL, "[MSG: Warning! Spindle freq %5.0f too high for requested PWM max %5.2f%% (%5.0f)]\r\n", settings.spindle_pwm_freq, settings.spindle_pwm_max_value, spindle_pwm_max_value); + } // Use DIR and Enable if pins are defined #ifdef SPINDLE_ENABLE_PIN @@ -46,13 +69,11 @@ void spindle_init() #ifdef SPINDLE_DIR_PIN pinMode(SPINDLE_DIR_PIN, OUTPUT); - #endif - + #endif // use the LED control feature to setup PWM https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/ledc.html - ledcSetup(SPINDLE_PWM_CHANNEL, SPINDLE_PWM_BASE_FREQ, SPINDLE_PWM_BIT_PRECISION); // setup the channel - ledcAttachPin(SPINDLE_PWM_PIN, SPINDLE_PWM_CHANNEL); // attach the PWM to the pin - + ledcSetup(SPINDLE_PWM_CHANNEL, (double)settings.spindle_pwm_freq, SPINDLE_PWM_BIT_PRECISION); // setup the channel + ledcAttachPin(SPINDLE_PWM_PIN, SPINDLE_PWM_CHANNEL); // attach the PWM to the pin // Start with spindle off off spindle_stop(); @@ -61,12 +82,13 @@ void spindle_init() void spindle_stop() { - spindle_set_enable(false); + spindle_set_enable(false); + #ifdef SPINDLE_PWM_PIN #ifndef INVERT_SPINDLE_PWM - grbl_analogWrite(SPINDLE_PWM_CHANNEL, SPINDLE_PWM_OFF_VALUE); + grbl_analogWrite(SPINDLE_PWM_CHANNEL, spindle_pwm_off_value); #else - grbl_analogWrite(SPINDLE_PWM_CHANNEL, (1<= settings.rpm_max) || (rpm >= settings.rpm_max)) { // No PWM range possible. Set simple on/off spindle control pin state. sys.spindle_speed = settings.rpm_max; - pwm_value = SPINDLE_PWM_MAX_VALUE; + pwm_value = spindle_pwm_max_value; } else if (rpm <= settings.rpm_min) { if (rpm == 0.0) { // S0 disables spindle sys.spindle_speed = 0.0; - pwm_value = SPINDLE_PWM_OFF_VALUE; + pwm_value = spindle_pwm_off_value; } else { // Set minimum PWM output sys.spindle_speed = settings.rpm_min; - pwm_value = SPINDLE_PWM_MIN_VALUE; + pwm_value = spindle_pwm_min_value; } } else { // Compute intermediate PWM value with linear spindle speed model. @@ -139,10 +160,9 @@ uint32_t spindle_compute_pwm_value(float rpm){ #ifdef ENABLE_PIECEWISE_LINEAR_SPINDLE pwm_value = piecewise_linear_fit(rpm); #else - pwm_value = floor((rpm-settings.rpm_min)*pwm_gradient) + SPINDLE_PWM_MIN_VALUE; + pwm_value = floor((rpm - settings.rpm_min)*pwm_gradient) + settings.spindle_pwm_min_value; #endif } - //grbl_sendf(CLIENT_SERIAL, "[MSG:Rpm %4.1f PWM %d]\r\n", rpm, pwm_value); return(pwm_value); #else return(0); // no SPINDLE_PWM_PIN @@ -151,9 +171,6 @@ uint32_t spindle_compute_pwm_value(float rpm){ // Called by spindle_set_state() and step segment generator. Keep routine small and efficient. - - - void spindle_set_state(uint8_t state, float rpm) { #ifdef SPINDLE_PWM_PIN @@ -165,7 +182,7 @@ void spindle_set_state(uint8_t state, float rpm) // TODO ESP32 Enable and direction control #ifdef SPINDLE_DIR_PIN - digitalWrite(SPINDLE_DIR_PIN, state == SPINDLE_ENABLE_CW); + digitalWrite(SPINDLE_DIR_PIN, state == SPINDLE_ENABLE_CW); #endif // NOTE: Assumes all calls to this function is when Grbl is not moving or must remain off. @@ -195,7 +212,7 @@ void grbl_analogWrite(uint8_t chan, uint32_t duty) { if (ledcRead(chan) != duty) // reduce unnecessary calls to ledcWrite() { - + grbl_sendf(CLIENT_SERIAL, "[MSG: grbl_analogWrite %d]\r\n", duty); ledcWrite(chan, duty); } } diff --git a/Grbl_Esp32/spindle_control.h b/Grbl_Esp32/spindle_control.h index 91f060c9..fd4147d4 100644 --- a/Grbl_Esp32/spindle_control.h +++ b/Grbl_Esp32/spindle_control.h @@ -23,7 +23,6 @@ #include "grbl.h" -#define SPINDLE_PWM_RANGE (SPINDLE_PWM_MAX_VALUE-SPINDLE_PWM_MIN_VALUE) #define SPINDLE_NO_SYNC false #define SPINDLE_FORCE_SYNC true @@ -31,6 +30,8 @@ #define SPINDLE_STATE_DISABLE 0 // Must be zero. #define SPINDLE_STATE_CW bit(0) #define SPINDLE_STATE_CCW bit(1) + +#define SPINDLE_PULSE_RES_COUNT ((1<is_pwm_rate_adjusted) { - spindle_set_speed(SPINDLE_PWM_OFF_VALUE); + spindle_set_speed(settings.spindle_pwm_off_value); } } @@ -1325,7 +1325,7 @@ void st_prep_buffer() } else { sys.spindle_speed = 0.0; #if ( (defined VARIABLE_SPINDLE) && (defined SPINDLE_PWM_PIN) ) - prep.current_spindle_pwm = SPINDLE_PWM_OFF_VALUE; + prep.current_spindle_pwm = settings.spindle_pwm_off_value; #endif } diff --git a/Grbl_Esp32/system.cpp b/Grbl_Esp32/system.cpp index 41aa4ea9..fbfd2264 100644 --- a/Grbl_Esp32/system.cpp +++ b/Grbl_Esp32/system.cpp @@ -30,19 +30,19 @@ void system_ini() // Renamed from system_init() due to conflict with esp32 files #ifndef IGNORE_CONTROL_PINS #ifdef CONTROL_SAFETY_DOOR_PIN - pinMode(CONTROL_SAFETY_DOOR_PIN, INPUT); + pinMode(CONTROL_SAFETY_DOOR_PIN, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(CONTROL_SAFETY_DOOR_PIN), isr_control_inputs, CHANGE); #endif #ifdef CONTROL_RESET_PIN - pinMode(CONTROL_RESET_PIN, INPUT); + pinMode(CONTROL_RESET_PIN, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(CONTROL_RESET_PIN), isr_control_inputs, CHANGE); #endif #ifdef CONTROL_FEED_HOLD_PIN - pinMode(CONTROL_FEED_HOLD_PIN, INPUT); + pinMode(CONTROL_FEED_HOLD_PIN, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(CONTROL_FEED_HOLD_PIN), isr_control_inputs, CHANGE); #endif #ifdef CONTROL_CYCLE_START_PIN - pinMode(CONTROL_CYCLE_START_PIN, INPUT); + pinMode(CONTROL_CYCLE_START_PIN, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(CONTROL_CYCLE_START_PIN), isr_control_inputs, CHANGE); #endif @@ -611,5 +611,4 @@ void sys_io_control(uint8_t io_num_mask, bool turnOn) { return; } #endif - grbl_sendf(CLIENT_SERIAL, "[MSG:Undefined IO pin...%d]\r\n", io_num_mask); } \ No newline at end of file diff --git a/doc/csv/setting_codes_en_US.csv b/doc/csv/setting_codes_en_US.csv index fb97a3f3..2fdcb7d5 100644 --- a/doc/csv/setting_codes_en_US.csv +++ b/doc/csv/setting_codes_en_US.csv @@ -33,3 +33,6 @@ "130","X-axis maximum travel","millimeters","Maximum X-axis travel distance from homing switch. Determines valid machine space for soft-limits and homing search distances." "131","Y-axis maximum travel","millimeters","Maximum Y-axis travel distance from homing switch. Determines valid machine space for soft-limits and homing search distances." "132","Z-axis maximum travel","millimeters","Maximum Z-axis travel distance from homing switch. Determines valid machine space for soft-limits and homing search distances." +"140-145","Motor run current","Amps","Motor run current for SPI (Trinamic) type motors" +"150-155","Motor hold current","Percent","Hold current in percent of run current for SPI (Trinamic) type motors" +"160-165","Motor microstepping","micros/step","Number of microsteps per step for SPI (Trinamic) type motors"