MarlinFirmware / Marlin

Marlin is an optimized firmware for RepRap 3D printers based on the Arduino platform. Many commercial 3D printers come with Marlin installed. Check with your vendor if you need source code for your specific machine.
https://marlinfw.org
GNU General Public License v3.0
16.05k stars 19.14k forks source link

[FR] add or augment Spindle Laser function to use PWM driven external circuit #27226

Open rflulling opened 2 weeks ago

rflulling commented 2 weeks ago

Is your feature request related to a problem? Please describe.

I have an external Spindle Driver for standard brushed type DC motor I would like to use.

Are you looking for hardware support?

No. This is NOT a request support for a controller or LCD where in code will be installed. This is not a request for assistance with wires or any physical setup configuration issue. This request is for Marlin FW in general but specific to Spindle and Laser section. I humbly request those who previously worked on the code for the laser CNC sections to make these changes.

Describe the feature you want

To augment the existing code slightly to support connectivity of external circuits for use in Spindle Control. Long term changes applied may also benefit others who may want to use various stand alone external controllers for spindle or laser with Marlin.

Additional context

Suggested layout of the laser spindle section, for reference only. To draw attention to points suggested to be added within conf adv.

#define SPINDLE_FEATURE
//#define LASER_FEATURE
#if ANY(SPINDLE_FEATURE, LASER_FEATURE)
  //#define SPINDLE_LASER_ACTIVE_STATE HIGH    // Set to "HIGH" if SPINDLE_LASER_ENA_PIN is active HIGH
  //#define SPINDLE_LASER_ENA_PIN PC5          // Enable Pin. Not included by default
  //#define SPINDLE_DIR_PIN PE0                // Direction Pin. Not included by default

  #define SPINDLE_LASER_USE_PWM                // Enable if your controller supports setting the speed/power
  #if ENABLED(SPINDLE_LASER_USE_PWM)
    #define SPINDLE_LASER_PWM_PIN PE1          // Not included by default
    #define SPINDLE_LASER_PWM_INVERT false     // Set to "true" if the speed/power goes up when you want it to go slower
    //#define SPINDLE_LASER_FREQUENCY 30000    // (Hz) Spindle/laser frequency (only on supported HALs: AVR, ESP32, and LPC)
                                               // ESP32: If SPINDLE_LASER_PWM_PIN is onboard then <=78125Hz. For I2S expander
                                               //  the frequency determines the PWM resolution. 2500Hz = 0-100, 977Hz = 0-255, ...
                                               //  (250000 / SPINDLE_LASER_FREQUENCY) = max value.
  #endif

  //#define AIR_EVACUATION                     // Cutter Vacuum / Laser Blower motor control with G-codes M10-M11
  #if ENABLED(AIR_EVACUATION)
    #define AIR_EVACUATION_ACTIVE       LOW    // Set to "HIGH" if the on/off function is active HIGH
    //#define AIR_EVACUATION_PIN        42     // Override the default Cutter Vacuum or Laser Blower pin
  #endif

  //#define AIR_ASSIST                         // Air Assist control with G-codes M8-M9
  #if ENABLED(AIR_ASSIST)
    #define AIR_ASSIST_ACTIVE           LOW    // Active state on air assist pin
    //#define AIR_ASSIST_PIN            44     // Override the default Air Assist pin
  #endif

  //#define SPINDLE_SERVO                      // A servo converting an angle to spindle power
  #ifdef SPINDLE_SERVO
    #define SPINDLE_SERVO_NR   0               // Index of servo used for spindle control
    #define SPINDLE_SERVO_MIN 10               // Minimum angle for servo spindle
  #endif

  /**
   * Speed / Power can be set ('M3 S') and displayed in terms of:
   *  - PWM255  (S0 - S255)
   *  - PERCENT (S0 - S100)
   *  - RPM     (S0 - S50000)  Best for use with a spindle
   *  - SERVO   (S0 - S180)
   */
  #define CUTTER_POWER_UNIT RPM

  /**
   * Relative Cutter Power
   * Normally, 'M3 O<power>' sets
   * OCR power is relative to the range SPEED_POWER_MIN...SPEED_POWER_MAX.
   * so input powers of 0...255 correspond to SPEED_POWER_MIN...SPEED_POWER_MAX
   * instead of normal range (0 to SPEED_POWER_MAX).
   * Best used with (e.g.) SuperPID router controller: S0 = 5,000 RPM and S255 = 30,000 RPM
   */
  //#define CUTTER_POWER_RELATIVE              // Set speed proportional to [SPEED_POWER_MIN...SPEED_POWER_MAX]

  #if ENABLED(SPINDLE_FEATURE)
    //#define SPINDLE_CHANGE_DIR               // Enable if your spindle controller can change spindle direction
    #define SPINDLE_CHANGE_DIR_STOP            // Enable if the spindle should stop before changing spin direction
    #define SPINDLE_INVERT_DIR          false  // Set to "true" if the spin direction is reversed

    #define SPINDLE_LASER_POWERUP_DELAY   5000 // (ms) Delay to allow the spindle/laser to come up to speed/power
    #define SPINDLE_LASER_POWERDOWN_DELAY 5000 // (ms) Delay to allow the spindle to stop

    /**
     * M3/M4 Power Equation
     *
     * Each tool uses different value ranges for speed / power control.
     * These parameters are used to convert between tool power units and PWM.
     *
     * Speed/Power = (PWMDC / 255 * 100 - SPEED_POWER_INTERCEPT) / SPEED_POWER_SLOPE
     * PWMDC = (spdpwr - SPEED_POWER_MIN) / (SPEED_POWER_MAX - SPEED_POWER_MIN) / SPEED_POWER_SLOPE
     */
    #if ENABLED(SPINDLE_LASER_USE_PWM)
      #define SPEED_POWER_PWMDC        50    // -1 to disable, 50 default, high values are higher on time
      #define SPEED_POWER_INTERCEPT      0     // (%) 0-100 i.e., Minimum power percentage
      #define SPEED_POWER_MIN         1000     // (RPM)
      #define SPEED_POWER_MAX         3000     // (RPM) SuperPID router controller 0 - 30,000 RPM
      #define SPEED_POWER_STARTUP     1000     // (RPM) M3/M4 speed/power default (with no arguments)
    #endif

  #else
ellensp commented 2 weeks ago

"I see no reason they should be manually added to a board pins file." you don't need to do this.

Just because the pin define is not In the config files does not mean you cannot add it. It doesn't need to be there by default to enable it.... Just add the line to your Configuration file.

rflulling commented 2 weeks ago

Because with exception to the PWM pin that was referenced (in notes), -the others are not.

If we took away the reference to the fan pins that need to be defined (and others), would users figure out what line they needed to add?

I would love it if way more CNC/Laser users could chime in too. But I few we are too few, though this is a growing topic. Just gathering info was an uphill battle. Most CNC/DIY forums don't even know Marlin can run a CNC yet, and the very few out there that do, are Marlin Developers.

I will add that one that I found referenced in old conversations (#define SPEED_POWER_SLOPE) that seems to be relevant to my work. However when searching Marlin for any further references to the function, it was not found. So perhaps in 4 years, it was removed. Or my technique to search the code content of Marlin is flawed.