Merge branch 'master' of https://github.com/cprezzi/grbl-LPC
This commit is contained in:
		
							
								
								
									
										22
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								README.md
									
									
									
									
									
								
							@@ -1,7 +1,8 @@
 | 
			
		||||

 | 
			
		||||
 | 
			
		||||
***
 | 
			
		||||
_Click the `Release` tab to download pre-compiled `.bin` files or just [click here](https://github.com/cprezzi/grbl-LPC/releases)_
 | 
			
		||||
Old releases are in the `Release` tab. See [cprezzi's branch](https://github.com/cprezzi/grbl-LPC) for more recent releases.
 | 
			
		||||
Note: cprezzi's branch disables current control and has defaults more suitable for other boards.
 | 
			
		||||
***
 | 
			
		||||
This is GRBL 1.1 ported to the LPC1769. It can run on Smoothieboard.
 | 
			
		||||
 | 
			
		||||
@@ -10,25 +11,22 @@ Usage notes:
 | 
			
		||||
  If it doesn't, try installing VCOM_lib/usbser.inf.
 | 
			
		||||
* This doesn't pass the sdcard to the host. Once installed you need to use a micro sdcard adaptor to replace or change it.
 | 
			
		||||
* Only tested with lasers with PWM. Non-PWM spindle control not ported.
 | 
			
		||||
* This special version supports setting PWM frequency by $33. Default is 5000 Hz. Pin can only be changes in config.h.
 | 
			
		||||
  * Pin 2.5
 | 
			
		||||
  * 5 kHz
 | 
			
		||||
  * PWM off value: 0%
 | 
			
		||||
  * Mimimum PWM value: 0%
 | 
			
		||||
  * Maximum PWM value: 100%
 | 
			
		||||
* These are defaults for easy-to-change config values.
 | 
			
		||||
  * Maximum S value: 1000.0 ($30)
 | 
			
		||||
  * WPos enabled for LaserWeb compatability ($10=0)
 | 
			
		||||
  * Laser mode: ON ($32)
 | 
			
		||||
  * Minimum S value: 0.0 ($31)
 | 
			
		||||
  * Laser mode: 1 ($32)
 | 
			
		||||
  * Laser PWM frequency: 5000 ($33)
 | 
			
		||||
  * Maximum S value: 1.0 ($30)
 | 
			
		||||
* Hard limits not yet ported
 | 
			
		||||
* Control inputs not yet ported (e.g. Cycle Start and Safety Door switches)
 | 
			
		||||
 | 
			
		||||
New configuration settings
 | 
			
		||||
* $33 is PWM frequency in Hz
 | 
			
		||||
* $34 is PWM off value in %
 | 
			
		||||
* $35 is PWM min value in %
 | 
			
		||||
* $36 is PWM max value in %
 | 
			
		||||
* $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!
 | 
			
		||||
  * Default to 0.0 A to avoid burning out your motors
 | 
			
		||||
  * Your motors will likely stall if you don't set these!
 | 
			
		||||
 | 
			
		||||
Build notes:
 | 
			
		||||
* You should use virtual machines, if you use multiple toolchains on the same PC.
 | 
			
		||||
 
 | 
			
		||||
@@ -129,6 +129,9 @@
 | 
			
		||||
// define to force Grbl to always set the machine origin at the homed location despite switch orientation.
 | 
			
		||||
// #define HOMING_FORCE_SET_ORIGIN // Uncomment to enable.
 | 
			
		||||
 | 
			
		||||
// Uncomment this define to force Grbl to always set the machine origin at bottom left.
 | 
			
		||||
#define HOMING_FORCE_POSITIVE_SPACE // Uncomment to enable.
 | 
			
		||||
 | 
			
		||||
// Number of blocks Grbl executes upon startup. These blocks are stored in EEPROM, where the size
 | 
			
		||||
// and addresses are defined in settings.h. With the current settings, up to 2 startup blocks may
 | 
			
		||||
// be stored and executed in order. These startup blocks would typically be used to set the g-code
 | 
			
		||||
@@ -359,11 +362,6 @@
 | 
			
		||||
//      pwm = scaled value. settings.rpm_min scales to SPINDLE_PWM_MIN_VALUE. settings.rpm_max
 | 
			
		||||
//            scales to SPINDLE_PWM_MAX_VALUE.
 | 
			
		||||
 | 
			
		||||
//#define SPINDLE_PWM_PERIOD        (SystemCoreClock / 40000)         // SystemCoreClock / frequency
 | 
			
		||||
#define SPINDLE_PWM_OFF_VALUE     0.0    // SPINDLE_PWM_PERIOD * fraction
 | 
			
		||||
//#define SPINDLE_PWM_MIN_VALUE     (SPINDLE_PWM_PERIOD * 0.0)    // SPINDLE_PWM_PERIOD * fraction
 | 
			
		||||
//#define SPINDLE_PWM_MAX_VALUE     (SPINDLE_PWM_PERIOD * 1.0)  // SPINDLE_PWM_PERIOD * fraction
 | 
			
		||||
 | 
			
		||||
// 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
 | 
			
		||||
@@ -717,10 +715,10 @@
 | 
			
		||||
#define CONTROL_INVERT_MASK   CONTROL_MASK // May be re-defined to only invert certain control pins.
 | 
			
		||||
 | 
			
		||||
// Define probe switch input pin.
 | 
			
		||||
#define PROBE_DDR       NotUsed
 | 
			
		||||
#define PROBE_PIN       NotUsed
 | 
			
		||||
#define PROBE_PORT      NotUsed
 | 
			
		||||
#define PROBE_BIT       5  // Uno Analog Pin 5
 | 
			
		||||
#define PROBE_DDR       NotUsed // LPC_GPIO1->FIODIR
 | 
			
		||||
#define PROBE_PIN       NotUsed // LPC_GPIO1->FIOPIN
 | 
			
		||||
#define PROBE_PORT      NotUsed // LPC_GPIO1->FIOPIN
 | 
			
		||||
#define PROBE_BIT       5
 | 
			
		||||
#define PROBE_MASK      (1<<PROBE_BIT)
 | 
			
		||||
 | 
			
		||||
// The LPC17xx has 6 PWM channels. Each channel has 2 pins. It can drive both pins simultaneously to the same value.
 | 
			
		||||
@@ -744,18 +742,21 @@
 | 
			
		||||
#define DEFAULT_Z_STEPS_PER_MM 160.0
 | 
			
		||||
#define DEFAULT_X_MAX_RATE 24000 // mm/min
 | 
			
		||||
#define DEFAULT_Y_MAX_RATE 24000 // mm/min
 | 
			
		||||
#define DEFAULT_Z_MAX_RATE 24000 // mm/min
 | 
			
		||||
#define DEFAULT_Z_MAX_RATE 500.0 // mm/min
 | 
			
		||||
#define DEFAULT_X_ACCELERATION (2500.0*60*60) // 5000*60*60 mm/min^2 = 5000 mm/sec^2
 | 
			
		||||
#define DEFAULT_Y_ACCELERATION (2500.0*60*60) // 5000*60*60 mm/min^2 = 5000 mm/sec^2
 | 
			
		||||
#define DEFAULT_Z_ACCELERATION (2500.0*60*60) // 5000*60*60 mm/min^2 = 5000 mm/sec^2
 | 
			
		||||
#define DEFAULT_X_CURRENT 0.0 // amps
 | 
			
		||||
#define DEFAULT_Y_CURRENT 0.0 // amps
 | 
			
		||||
#define DEFAULT_X_CURRENT 0.4 // amps
 | 
			
		||||
#define DEFAULT_Y_CURRENT 0.6 // amps
 | 
			
		||||
#define DEFAULT_Z_CURRENT 0.0 // amps
 | 
			
		||||
#define DEFAULT_A_CURRENT 0.0  // amps
 | 
			
		||||
#define DEFAULT_X_MAX_TRAVEL 300.0 // mm
 | 
			
		||||
#define DEFAULT_Y_MAX_TRAVEL 200.0 // mm
 | 
			
		||||
#define DEFAULT_Z_MAX_TRAVEL 50.0 // mm
 | 
			
		||||
#define DEFAULT_SPINDLE_PWM_FREQ 5000 // Hz
 | 
			
		||||
#define DEFAULT_SPINDLE_PWM_FREQ          5000        // Hz
 | 
			
		||||
#define DEFAULT_SPINDLE_PWM_OFF_VALUE     0.0         // Percent
 | 
			
		||||
#define DEFAULT_SPINDLE_PWM_MIN_VALUE     0.0         // Percent
 | 
			
		||||
#define DEFAULT_SPINDLE_PWM_MAX_VALUE     100.0       // Percent
 | 
			
		||||
#define DEFAULT_SPINDLE_RPM_MAX 1000.0 // rpm
 | 
			
		||||
#define DEFAULT_SPINDLE_RPM_MIN 0.0 // rpm
 | 
			
		||||
#define DEFAULT_STEP_PULSE_MICROSECONDS 10
 | 
			
		||||
@@ -768,15 +769,15 @@
 | 
			
		||||
#define DEFAULT_REPORT_INCHES 0 // false
 | 
			
		||||
#define DEFAULT_INVERT_ST_ENABLE 0 // false
 | 
			
		||||
#define DEFAULT_INVERT_LIMIT_PINS 1 // false
 | 
			
		||||
#define DEFAULT_SOFT_LIMIT_ENABLE 0 // false
 | 
			
		||||
#define DEFAULT_SOFT_LIMIT_ENABLE 1 // false
 | 
			
		||||
#define DEFAULT_HARD_LIMIT_ENABLE 0  // false
 | 
			
		||||
#define DEFAULT_INVERT_PROBE_PIN 0 // false
 | 
			
		||||
#define DEFAULT_LASER_MODE 1 // true
 | 
			
		||||
#define DEFAULT_HOMING_ENABLE 0  // false
 | 
			
		||||
#define DEFAULT_HOMING_DIR_MASK 0 // move positive dir
 | 
			
		||||
#define DEFAULT_HOMING_ENABLE 1  // false
 | 
			
		||||
#define DEFAULT_HOMING_DIR_MASK 1 // move positive dir
 | 
			
		||||
#define DEFAULT_HOMING_FEED_RATE 50.0 // mm/min
 | 
			
		||||
#define DEFAULT_HOMING_SEEK_RATE 6000.0 // mm/min
 | 
			
		||||
#define DEFAULT_HOMING_DEBOUNCE_DELAY 250 // msec (0-65k)
 | 
			
		||||
#define DEFAULT_HOMING_PULLOFF 1.0 // mm
 | 
			
		||||
#define DEFAULT_HOMING_PULLOFF 2.0 // mm
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 
 | 
			
		||||
@@ -41,7 +41,6 @@
 | 
			
		||||
  #define DEFAULT_X_MAX_TRAVEL 200.0 // mm NOTE: Must be a positive value.
 | 
			
		||||
  #define DEFAULT_Y_MAX_TRAVEL 200.0 // mm NOTE: Must be a positive value.
 | 
			
		||||
  #define DEFAULT_Z_MAX_TRAVEL 200.0 // mm NOTE: Must be a positive value.
 | 
			
		||||
  #define DEFAULT_SPINDLE_PWM_FREQ 5000 // Hz
 | 
			
		||||
  #define DEFAULT_SPINDLE_RPM_MAX 1000.0 // rpm
 | 
			
		||||
  #define DEFAULT_SPINDLE_RPM_MIN 0.0 // rpm
 | 
			
		||||
  #define DEFAULT_STEP_PULSE_MICROSECONDS 10
 | 
			
		||||
@@ -66,49 +65,6 @@
 | 
			
		||||
  #define DEFAULT_HOMING_PULLOFF 1.0 // mm
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef DEFAULTS_K40
 | 
			
		||||
  // Description: K40 Lasercutter (typical chinese 40W CO2 laser cutter/engraver)
 | 
			
		||||
  #define DEFAULT_X_STEPS_PER_MM 160.0
 | 
			
		||||
  #define DEFAULT_Y_STEPS_PER_MM 160.0
 | 
			
		||||
  #define DEFAULT_Z_STEPS_PER_MM 160.0
 | 
			
		||||
  #define DEFAULT_X_MAX_RATE 24000.0 // mm/min
 | 
			
		||||
  #define DEFAULT_Y_MAX_RATE 24000.0 // mm/min
 | 
			
		||||
  #define DEFAULT_Z_MAX_RATE 24000.0 // mm/min
 | 
			
		||||
  #define DEFAULT_X_ACCELERATION (2500.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2
 | 
			
		||||
  #define DEFAULT_Y_ACCELERATION (2500.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2
 | 
			
		||||
  #define DEFAULT_Z_ACCELERATION (2500.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2
 | 
			
		||||
  #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 300.0 // mm NOTE: Must be a positive value.
 | 
			
		||||
  #define DEFAULT_Y_MAX_TRAVEL 200.0 // mm NOTE: Must be a positive value.
 | 
			
		||||
  #define DEFAULT_Z_MAX_TRAVEL 50.0 // mm NOTE: Must be a positive value.
 | 
			
		||||
  #define DEFAULT_SPINDLE_PWM_FREQ 5000 // Hz
 | 
			
		||||
  #define DEFAULT_SPINDLE_RPM_MAX 1000.0 // rpm
 | 
			
		||||
  #define DEFAULT_SPINDLE_RPM_MIN 0.0 // rpm
 | 
			
		||||
  #define DEFAULT_STEP_PULSE_MICROSECONDS 10
 | 
			
		||||
  #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_STATUS_REPORT_MASK 0 // WPos enabled
 | 
			
		||||
  #define DEFAULT_JUNCTION_DEVIATION 0.01 // mm
 | 
			
		||||
  #define DEFAULT_ARC_TOLERANCE 0.002 // mm
 | 
			
		||||
  #define DEFAULT_REPORT_INCHES 0 // false
 | 
			
		||||
  #define DEFAULT_INVERT_ST_ENABLE 0 // false
 | 
			
		||||
  #define DEFAULT_INVERT_LIMIT_PINS 1 // false
 | 
			
		||||
  #define DEFAULT_SOFT_LIMIT_ENABLE 0 // false
 | 
			
		||||
  #define DEFAULT_HARD_LIMIT_ENABLE 0  // false
 | 
			
		||||
  #define DEFAULT_INVERT_PROBE_PIN 0 // false
 | 
			
		||||
  #define DEFAULT_LASER_MODE 1 // false
 | 
			
		||||
  #define DEFAULT_HOMING_ENABLE 0  // false
 | 
			
		||||
  #define DEFAULT_HOMING_DIR_MASK 0 // move positive dir
 | 
			
		||||
  #define DEFAULT_HOMING_FEED_RATE 50.0 // mm/min
 | 
			
		||||
  #define DEFAULT_HOMING_SEEK_RATE 6000.0 // mm/min
 | 
			
		||||
  #define DEFAULT_HOMING_DEBOUNCE_DELAY 250 // msec (0-65k)
 | 
			
		||||
  #define DEFAULT_HOMING_PULLOFF 1.0 // mm
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef DEFAULTS_SHERLINE_5400
 | 
			
		||||
  // Description: Sherline 5400 mill with three NEMA 23 Keling  KL23H256-21-8B 185 oz-in stepper motors,
 | 
			
		||||
  // driven by three Pololu A4988 stepper drivers with a 30V, 6A power supply at 1.5A per winding.
 | 
			
		||||
 
 | 
			
		||||
@@ -307,9 +307,17 @@ void limits_go_home(uint8_t cycle_mask)
 | 
			
		||||
        set_axis_position = 0;
 | 
			
		||||
      #else
 | 
			
		||||
        if ( bit_istrue(settings.homing_dir_mask,bit(idx)) ) {
 | 
			
		||||
          set_axis_position = lround((settings.max_travel[idx]+settings.homing_pulloff)*settings.steps_per_mm[idx]);
 | 
			
		||||
          #ifdef HOMING_FORCE_POSITIVE_SPACE
 | 
			
		||||
            set_axis_position = 0; //lround(settings.homing_pulloff*settings.steps_per_mm[idx]);
 | 
			
		||||
          #else
 | 
			
		||||
            set_axis_position = lround((settings.max_travel[idx]-settings.homing_pulloff)*settings.steps_per_mm[idx]);
 | 
			
		||||
          #endif
 | 
			
		||||
        } else {
 | 
			
		||||
          set_axis_position = lround(-settings.homing_pulloff*settings.steps_per_mm[idx]);
 | 
			
		||||
          #ifdef HOMING_FORCE_POSITIVE_SPACE
 | 
			
		||||
            set_axis_position = lround(-settings.max_travel[idx]*settings.steps_per_mm[idx]);
 | 
			
		||||
          #else
 | 
			
		||||
            set_axis_position = lround(-settings.homing_pulloff*settings.steps_per_mm[idx]);
 | 
			
		||||
          #endif
 | 
			
		||||
        }
 | 
			
		||||
      #endif
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -71,7 +71,6 @@ static void report_util_setting_string(uint8_t n) {
 | 
			
		||||
    case 30: printPgmString(PSTR("rpm max")); break;
 | 
			
		||||
    case 31: printPgmString(PSTR("rpm min")); break;
 | 
			
		||||
    case 32: printPgmString(PSTR("laser")); break;
 | 
			
		||||
    case 33: printPgmString(PSTR("spindle_pwm_freq")); break;
 | 
			
		||||
    default:
 | 
			
		||||
      n -= AXIS_SETTINGS_START_VAL;
 | 
			
		||||
      uint8_t idx = 0;
 | 
			
		||||
@@ -97,11 +96,6 @@ static void report_util_uint8_setting(uint8_t n, int val) {
 | 
			
		||||
  print_uint8_base10(val); 
 | 
			
		||||
  report_util_line_feed(); // report_util_setting_string(n); 
 | 
			
		||||
}
 | 
			
		||||
static void report_util_uint32_setting(uint8_t n, int val) { 
 | 
			
		||||
  report_util_setting_prefix(n); 
 | 
			
		||||
  print_uint32_base10(val); 
 | 
			
		||||
  report_util_line_feed(); // report_util_setting_string(n); 
 | 
			
		||||
}
 | 
			
		||||
static void report_util_float_setting(uint8_t n, float val, uint8_t n_decimal) { 
 | 
			
		||||
  report_util_setting_prefix(n); 
 | 
			
		||||
  printFloat(val,n_decimal);
 | 
			
		||||
@@ -214,7 +208,10 @@ void report_grbl_settings() {
 | 
			
		||||
  #else
 | 
			
		||||
    report_util_uint8_setting(32,0);
 | 
			
		||||
  #endif
 | 
			
		||||
  report_util_uint32_setting(33,settings.spindle_pwm_freq);
 | 
			
		||||
  report_util_float_setting(33,settings.spindle_pwm_freq,N_DECIMAL_SETTINGVALUE);
 | 
			
		||||
  report_util_float_setting(34,settings.spindle_pwm_off_value,N_DECIMAL_SETTINGVALUE);
 | 
			
		||||
  report_util_float_setting(35,settings.spindle_pwm_min_value,N_DECIMAL_SETTINGVALUE);
 | 
			
		||||
  report_util_float_setting(36,settings.spindle_pwm_max_value,N_DECIMAL_SETTINGVALUE);
 | 
			
		||||
  // Print axis settings
 | 
			
		||||
  uint8_t idx, set_idx;
 | 
			
		||||
  uint8_t val = AXIS_SETTINGS_START_VAL;
 | 
			
		||||
 
 | 
			
		||||
@@ -87,6 +87,9 @@ void settings_restore(uint8_t restore_flag) {
 | 
			
		||||
    settings.arc_tolerance = DEFAULT_ARC_TOLERANCE;
 | 
			
		||||
 | 
			
		||||
    settings.spindle_pwm_freq = DEFAULT_SPINDLE_PWM_FREQ;
 | 
			
		||||
    settings.spindle_pwm_off_value = DEFAULT_SPINDLE_PWM_OFF_VALUE;
 | 
			
		||||
    settings.spindle_pwm_min_value = DEFAULT_SPINDLE_PWM_MIN_VALUE;
 | 
			
		||||
    settings.spindle_pwm_max_value = DEFAULT_SPINDLE_PWM_MAX_VALUE;
 | 
			
		||||
    settings.rpm_max = DEFAULT_SPINDLE_RPM_MAX;
 | 
			
		||||
    settings.rpm_min = DEFAULT_SPINDLE_RPM_MIN;
 | 
			
		||||
 | 
			
		||||
@@ -319,6 +322,9 @@ uint8_t settings_store_global_setting(uint8_t parameter, float value) {
 | 
			
		||||
        #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);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -92,7 +92,10 @@ typedef struct {
 | 
			
		||||
  float junction_deviation;
 | 
			
		||||
  float arc_tolerance;
 | 
			
		||||
 | 
			
		||||
  uint16_t spindle_pwm_freq;
 | 
			
		||||
  float spindle_pwm_freq;      // Hz
 | 
			
		||||
  float spindle_pwm_off_value; // Percent
 | 
			
		||||
  float spindle_pwm_min_value; // Percent
 | 
			
		||||
  float spindle_pwm_max_value; // Percent
 | 
			
		||||
  float rpm_max;
 | 
			
		||||
  float rpm_min;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -25,10 +25,10 @@
 | 
			
		||||
 | 
			
		||||
#ifdef VARIABLE_SPINDLE
 | 
			
		||||
  static float pwm_gradient; // Precalulated value to speed up rpm to PWM conversions.
 | 
			
		||||
  static float spindle_pwm_period;
 | 
			
		||||
  static float spindle_pwm_off_value;
 | 
			
		||||
  static float spindle_pwm_min_value;
 | 
			
		||||
  static float spindle_pwm_max_value;
 | 
			
		||||
  float spindle_pwm_period;
 | 
			
		||||
  float spindle_pwm_off_value;
 | 
			
		||||
  float spindle_pwm_min_value;
 | 
			
		||||
  float spindle_pwm_max_value;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -36,12 +36,10 @@ void spindle_init()
 | 
			
		||||
{
 | 
			
		||||
  #ifdef VARIABLE_SPINDLE
 | 
			
		||||
    spindle_pwm_period = (SystemCoreClock / settings.spindle_pwm_freq);
 | 
			
		||||
    spindle_pwm_off_value = (spindle_pwm_period * 0.0);    // SPINDLE_PWM_PERIOD * fraction
 | 
			
		||||
    spindle_pwm_min_value = (spindle_pwm_period * 0.0);    // SPINDLE_PWM_PERIOD * fraction
 | 
			
		||||
    spindle_pwm_max_value = (spindle_pwm_period * 1.0);    // SPINDLE_PWM_PERIOD * fraction
 | 
			
		||||
 | 
			
		||||
    //pwm_init(&SPINDLE_PWM_CHANNEL, SPINDLE_PWM_USE_PRIMARY_PIN, SPINDLE_PWM_USE_SECONDARY_PIN, SPINDLE_PWM_PERIOD, 0);
 | 
			
		||||
    pwm_init(&SPINDLE_PWM_CHANNEL, SPINDLE_PWM_USE_PRIMARY_PIN, SPINDLE_PWM_USE_SECONDARY_PIN, spindle_pwm_period, 0); //SPINDLE_PWM_PERIOD
 | 
			
		||||
    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_init(&SPINDLE_PWM_CHANNEL, SPINDLE_PWM_USE_PRIMARY_PIN, SPINDLE_PWM_USE_SECONDARY_PIN, spindle_pwm_period, 0);
 | 
			
		||||
    pwm_enable(&SPINDLE_PWM_CHANNEL);
 | 
			
		||||
 | 
			
		||||
    /* not ported
 | 
			
		||||
@@ -54,7 +52,6 @@ void spindle_init()
 | 
			
		||||
    #endif
 | 
			
		||||
    */
 | 
			
		||||
 | 
			
		||||
    //pwm_gradient = (SPINDLE_PWM_MAX_VALUE-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);
 | 
			
		||||
 | 
			
		||||
  #else
 | 
			
		||||
@@ -145,21 +142,21 @@ void spindle_stop()
 | 
			
		||||
    rpm *= (0.010*sys.spindle_speed_ovr); // Scale by spindle speed override value.
 | 
			
		||||
    if (rpm <= 0) {
 | 
			
		||||
      sys.spindle_speed = 0;
 | 
			
		||||
      pwm_value = spindle_pwm_off_value;    //SPINDLE_PWM_OFF_VALUE
 | 
			
		||||
      pwm_value = spindle_pwm_off_value;
 | 
			
		||||
    }
 | 
			
		||||
    else if (rpm <= settings.rpm_min) {
 | 
			
		||||
      sys.spindle_speed = settings.rpm_min;
 | 
			
		||||
      pwm_value = spindle_pwm_min_value;    //SPINDLE_PWM_MIN_VALUE
 | 
			
		||||
      pwm_value = spindle_pwm_min_value;
 | 
			
		||||
    }
 | 
			
		||||
    else if (rpm >= settings.rpm_max) {
 | 
			
		||||
      sys.spindle_speed = settings.rpm_max;
 | 
			
		||||
      pwm_value = spindle_pwm_max_value - 1;    //SPINDLE_PWM_MAX_VALUE
 | 
			
		||||
      pwm_value = spindle_pwm_max_value - 1;
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
      sys.spindle_speed = rpm;
 | 
			
		||||
      pwm_value = floor((rpm - settings.rpm_min) * pwm_gradient) + spindle_pwm_min_value;   //SPINDLE_PWM_MIN_VALUE
 | 
			
		||||
      if(pwm_value >= spindle_pwm_max_value)    //SPINDLE_PWM_MAX_VALUE
 | 
			
		||||
        pwm_value = spindle_pwm_max_value - 1;  //SPINDLE_PWM_MAX_VALUE
 | 
			
		||||
      pwm_value = floor((rpm - settings.rpm_min) * pwm_gradient) + spindle_pwm_min_value;
 | 
			
		||||
      if(pwm_value >= spindle_pwm_max_value)
 | 
			
		||||
        pwm_value = spindle_pwm_max_value - 1;
 | 
			
		||||
    }
 | 
			
		||||
    return(pwm_value);
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -40,6 +40,10 @@ uint8_t spindle_get_state();
 | 
			
		||||
// Immediately sets spindle running state with direction and spindle rpm via PWM, if enabled.
 | 
			
		||||
// Called by spindle_sync() after sync and parking motion/spindle stop override during restore.
 | 
			
		||||
#ifdef VARIABLE_SPINDLE
 | 
			
		||||
  extern float spindle_pwm_period;
 | 
			
		||||
  extern float spindle_pwm_off_value;
 | 
			
		||||
  extern float spindle_pwm_min_value;
 | 
			
		||||
  extern float spindle_pwm_max_value;
 | 
			
		||||
 | 
			
		||||
  // Called by g-code parser when setting spindle state and requires a buffer sync.
 | 
			
		||||
  void spindle_sync(uint8_t state, float rpm);
 | 
			
		||||
 
 | 
			
		||||
@@ -385,7 +385,7 @@ extern "C" void TIMER1_IRQHandler()
 | 
			
		||||
      st_go_idle();
 | 
			
		||||
      #ifdef VARIABLE_SPINDLE
 | 
			
		||||
        // Ensure pwm is set properly upon completion of rate-controlled motion.
 | 
			
		||||
        if (st.exec_block->is_pwm_rate_adjusted) { spindle_set_speed(SPINDLE_PWM_OFF_VALUE); }
 | 
			
		||||
        if (st.exec_block->is_pwm_rate_adjusted) { spindle_set_speed(spindle_pwm_off_value); }
 | 
			
		||||
      #endif
 | 
			
		||||
      system_set_exec_state_flag(EXEC_CYCLE_STOP); // Flag main program for cycle end
 | 
			
		||||
      return; // Nothing to do but exit.
 | 
			
		||||
@@ -907,7 +907,7 @@ void st_prep_buffer()
 | 
			
		||||
          prep.current_spindle_pwm = spindle_compute_pwm_value(rpm);
 | 
			
		||||
        } else { 
 | 
			
		||||
          sys.spindle_speed = 0.0;
 | 
			
		||||
          prep.current_spindle_pwm = SPINDLE_PWM_OFF_VALUE;
 | 
			
		||||
          prep.current_spindle_pwm = spindle_pwm_off_value;
 | 
			
		||||
        }
 | 
			
		||||
        bit_false(sys.step_control,STEP_CONTROL_UPDATE_SPINDLE_PWM);
 | 
			
		||||
      }
 | 
			
		||||
 
 | 
			
		||||
@@ -342,7 +342,11 @@ uint8_t system_check_travel_limits(float *target)
 | 
			
		||||
      }
 | 
			
		||||
    #else
 | 
			
		||||
      // NOTE: max_travel is stored as negative
 | 
			
		||||
      if (target[idx] > 0 || target[idx] < settings.max_travel[idx]) { return(true); }
 | 
			
		||||
      #ifdef HOMING_FORCE_POSITIVE_SPACE
 | 
			
		||||
        if (target[idx] < 0 || target[idx] > -settings.max_travel[idx]) { return(true); }
 | 
			
		||||
      #else
 | 
			
		||||
        if (target[idx] > 0 || target[idx] < settings.max_travel[idx]) { return(true); }
 | 
			
		||||
      #endif
 | 
			
		||||
    #endif
 | 
			
		||||
  }
 | 
			
		||||
  return(false);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user