Reply To: Spindle power control

#13874

Mike Cunningham
Participant

For speed control, I went redneck.

http://www.thingiverse.com/thing:1635710

vacuum and spindle are powered by a ….. less than NEC-approved gang box, behind the router. 2x 20A relays, wired to digital outputs, each relay feeds one of the plugs.

With my servo solution, you have to add M280 P0 S0 (max speed) or M280 P0 S180 (min speed) with the stock firmware, and M42 P57/58 S0/1 (A3/A4 on AUX-1) to control the relays.

As an electronics engineer, I’ve significantly modified Marlin on my ramps, adding the appropriate M3/M5 and M10/M11 commands. in Marlin_main.cpp, around line 6500, add the appropriate case blocks for the commands you want to add, then add them higher in the file… here is my M3/M5, for example:

  inline void gcode_M3() {
    OUT_WRITE(SPINDLE_ENABLE, HIGH);
    int servo_index = code_seen('P') ? code_value_short() : 0;
    int servo_position = 0;
    if (code_seen('S')) {
      servo_position = code_value_short();
      if (servo_index >= 0 && servo_index < NUM_SERVOS)
        servo[servo_index].move(servo_position);
      else {
        SERIAL_ERROR_START;
        SERIAL_ERROR("Servo ");
        SERIAL_ERROR(servo_index);
        SERIAL_ERRORLN(" out of range");
      }
    }
  }
  
  inline void gcode_M5() {
    OUT_WRITE(SPINDLE_ENABLE, LOW);
  }

EDIT 1: and the code lower, in the switch (I put it right after M81):

      case 3: // M3: Turn on SPINDLE_ENABLE relay, P=servo number (defaults 0), S=servo setting (180-0)
        gcode_M3();
        break;

      case 5: // M5: Turn off SPINDLE_ENABLE relay
        gcode_M5();
        break;

edit 2- don’t forget to define SPINDLE_ENABLE somewhere (like your pins.h file), to identify which pin the relay is on

edit 3- most SSR relays can not switch fast enough, and will BBQ if you hook them up to PWM. The highest reasonable rate to cycle a SSR is about 10Hz (10 times per second), and even that will burn it up quickly (within a few months)

V/r,
Mike