M3-M5 Spindle Control

Hi guys, I need your support because today I’m getting mad.
I’m trying to enable the spindle ON/OFF trough M3-M5 GCodes on my SKR 1.3 Board and a iot relay board.

I have configured marlin 2.0.3 in order to enable the function:
#define SPINDLE_FEATURE
and disabling the other features:
#define SPINDLE_LASER_PWM false -> to send target speed reference
#define SPINDLE_INVERT_DIR false -> to send speed inversion

then I have mapped the output pin:
#ifndef SPINDLE_LASER_ENA_PIN
#define SPINDLE_LASER_ENA_PIN P2_00 -> SKR 1.3 servo output
#endif

with this modification the servo pin is 0 V or 3.3 V following coherently M3 and M5 commands.

the next step was connecting the relay:
relay

wired:
Vcc to 5V (servo connector SKR 1.3)
Gnd to Gnd (servo connector SKR 1.3)
In1 to P2_00 (servo connector SKR 1.3)

swiched ON -> relay always active, no effect from M3-M5 commands

Then I connected the same relay board to an Arduino UNO, tested it with the Blink.ino sketch and I verified the correct behavior of the relay board that switches ON when In1 is connected to GND and OFF on other levels.

At this point I imagined that the SKR1.3 pin is not able to drive to Gnd the servo output and I found this resource:
https://electronics.stackexchange.com/questions/245976/control-5v-relay-through-3-3v-gpio-using-npn-transistor

found in my lab some components and I built this circuit:

This circuit inverts the command logic so I inverted command logic in the fw by #define SPINDLE_LASER_ACTIVE_HIGH true.

Tested again and everything seems to work:
M3 Command
M5 Command

But… when switch on the board supply for about 10 second the relay is switched ON
Start after SKR1.3 supply

I have verified that during this “BOOT” time the servo output is driven at 1.22 V causing the spurious relay activation.

That’s all, now I’m really stuck with my mechanical engineer background I don’t know how to proceed to remove this spurious relay activation at startup… maybe I have only bought the wrong relay board…

Thank you for your support

Gabriele

1 Like

Disclaimer - I’ve never used either the SKR board you’re using, or the relay board… But…

I would suspect the pin you’re using to drive that relay board is configured as an input during boot and only goes to output once your firmware is running. During that time the input to the base of Q2 is (effectively) unknown and I would guess is allowing your relay to be turned ON.

Try a 10K resistor from the (input) pin on R3 to GND. That should bias Q2 base to GND when the SKR isn’t driving the pin.

PS - don’t blame me if it blows up! (I know, very confidence inspiring) :man_shrugging:

4 Likes

My suggestion is drive the external relay from a different pin. Either a servo pin or one of the aux pins. I believe Zmin can be configured as a pwm output as well so you can just reassign Zmin to the zmax pin if you’re using it for a touch plate or whatever.

Hi All,
thank you very much for your support, at the end I have solved the problem using a Wemos Relay Shield for ESP8266 Lolin D1 mini boards.
This relay shield is equipped with a 10k pulldown resistor that keeps the Servo output to 0 level during board reset.

Now M3-M5 commands work fine with following Configuration_adv.h modifications:

#define SPINDLE_FEATURE // LOK Edit
//#define LASER_FEATURE
#if EITHER(SPINDLE_FEATURE, LASER_FEATURE)
#define SPINDLE_LASER_ACTIVE_HIGH     true  // Set to "true" if the on/off function is active HIGH
#define SPINDLE_LASER_PWM             false   // Set to "true" if your controller supports setting the speed/power
#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_POWERUP_DELAY   2500   // (ms) Delay to allow the spindle/laser to come up to speed/power
#define SPINDLE_LASER_POWERDOWN_DELAY 2500   // (ms) Delay to allow the spindle to stop

#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
2 Likes

Could you say me, which boards (RAMPS & Arduino…) did you used?

And which Output did you taked? Aux2 with D40?

And did you not changed the MOTHERBOARD to BOARD_RAMPS_14_SF e.g. in the configuration.h ?

Hi, I’m using bigtreetech skr1.3 board.
Servo output.

I just got the SKR 1.4 to work on one of the heater bed plugs, awesome…

1 Like

Maybe someone has faced this issue on Marlin 2.0.7.2. I have made all the same configurations as described above in configuration_adv.h and replaced the SERVO0_PIN on P2_00 with SPINDLE_LASER_ENA_PIN (although I tried also the same with the heater pins, as the SPINDLE_LASER_PWM is false anyhow), but the Auto Build Marlin constantly reports an error:

Marlin/src/feature/spindle_laser.cpp: In static member function ‘static void SpindleLaser::init()’:
Marlin/src/feature/spindle_laser.cpp:57:29: error: ‘SPINDLE_LASER_PWM_PIN’ was not declared in this scope; did you mean ‘SPINDLE_LASER_PWM_OFF’?
57 | set_pwm_frequency(pin_t(SPINDLE_LASER_PWM_PIN), SPINDLE_LASER_FREQUENCY);
| ^~~~~~~~~~~~~~~~~~~~~
| SPINDLE_LASER_PWM_OFF
*** [.pio/build/LPC1768/src/src/feature/spindle_laser.cpp.o] Error 1

Does anyone have any suggestions?

In Configuration_adv.h, you need to comment out #define SPINDLE_LASER_FREQUENCY, I have :
`#define SPINDLE_FEATURE
//#define LASER_FEATURE
#if EITHER(SPINDLE_FEATURE, LASER_FEATURE)
#define SPINDLE_LASER_ACTIVE_STATE HIGH // Set to “HIGH” if the on/off function is active HIGH
#define SPINDLE_LASER_PWM false // Set to “true” if your controller supports setting the speed/power
#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 2500 // (Hz) Spindle/laser frequency (only on supported HALs: AVR and LPC)

/**

  • 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
      */
      #define CUTTER_POWER_UNIT PWM255`

Hi,

Could a friend explain more clearly? I HAVE A SKR 1.4 CARD AND WANT TO RUN THE M03 COMMAND. BUT I GET A COMPILE ERROR WHEN I OPEN “#define SPINDLE_FEATURE”.

You might want to open this as a new topic rather than append it to an older topic. Also more information would be helpful:

  • What specific version of the firmware are you attempting to compile?
  • What specific error are you receiving? Note if you have a long list of errors, you should be able to attach a text file with all the errors. Usually only the first error matters.
  • What are you attempting to drive with the M3 - M5 commands? Laser or spindle or…

M3 (spindle Clockwise), M4 (spindle Counterclockwise), and M5 (spindle off) can used either as on/off commands with a simple relay, or can also control spindle RPM which then requires appropriate PWM controls, which may be a single enable/PWM pin or separate pins for Enable and PWM. We need to know what feature set you’re hoping to use in order to help.

Have you by any chance got -

#define SPINDLE_FEATURE”
and
#define LASER_FEATURE”

both un-commented?

As an aside… this is what happens when you try to make software do a multitude of different disciplines … A chaotic complicated mess.

Hi,
Skr 1.4 turbo
I have a card.
#define SPINDLE_FEATURE

//#define LASER_FEATURE

#if EITHER(SPINDLE_FEATURE, LASER_FEATURE)

#define SPINDLE_LASER_ACTIVE_STATE LOW // Set to “HIGH” if the on/off function is active HIGH

//#define SPINDLE_LASER_PWM true // Set to “true” if your controller supports setting the speed/power

#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 2500

When I did it that way, it did not give an error.
#define SPINDLE_LASER_PWM
gives an error when it happens.
pins_BTT SKR V1.4.h filechange
//#define SERVO0_PIN P2_00
#define SPINDLE_LASER_ENA_PIN P2_00

Hi,
I also have a card. can you post what you did or your marlin software? machinecadcam@gmail.com