Welcome to Our Community

Some features disabled for guests. Register Today.

Using GRBL 0.9 to switch spindle on/off

Discussion in 'Control Software' started by drpeej, Mar 11, 2016.

  1. drpeej

    drpeej New
    Builder

    Joined:
    Feb 23, 2016
    Messages:
    20
    Likes Received:
    2
    I want to control the spindle on/off via a relay using the spindle enable pin with M3 and M5. (I am not controlling speed using pwm). I understand that GRBL 0.9 changed the pinout to allow PWM speed control.

    I am using GRBL 0.9j. If I comment out the #define VARIABLE_SPINDLE line in config.h, the output appears as expected on D12. However M3 only switches D12 HIGH if I have previously set S to some value other than zero. I expected the 'S' setting to be irrelevant if VARIABLE_SPINDLE is not defined. The S value doesn't persist and always resets to zero (presumably a safety feature) so I need to send S1 after every reset to allow motor control.

    Is it possible to change this behaviour or set S to default to a non-zero value? I have tried several compile-time options in config.h but am reluctant to change the main code with my limited knowledge.
     
  2. David the swarfer

    David the swarfer OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 6, 2013
    Messages:
    3,461
    Likes Received:
    1,915
    You can set it to a startup block so it always runs when GRBL turns on or resets, so you do not need to change the code other than turning off PWM.
    Configuring Grbl v0.9 · grbl/grbl Wiki · GitHub
    look for $N
    Code:
    $Nx are the startup blocks that Grbl runs every time you power on Grbl or reset Grbl. In other words, a startup block is a line of G-code that you can have Grbl auto-magically run to set your G-code modal defaults, or anything else you need Grbl to do everytime you start up your machine. Grbl can store two blocks of G-code as a system default.
    
    So, when connected to Grbl, type $N and then enter. Grbl should respond with something short like:
    
    $N0=
    $N1=
    ok
    
     
  3. drpeej

    drpeej New
    Builder

    Joined:
    Feb 23, 2016
    Messages:
    20
    Likes Received:
    2
    Thanks for that. I'll investigate
     
  4. OldDogSleeping

    Builder

    Joined:
    Oct 22, 2015
    Messages:
    11
    Likes Received:
    11
    I use a similar configuration, controlling my spindle via a solid state relay. M3 & M5 seem to just work for me, no need to set S, no startup blocks that I can see. I'm fairly certain that all I changed was commenting out the VARIABLE SPINDLE line in config.h. so I'm wondering what is different with my setup.
    The only thing I can think of is that I have homing enabled, so have to perform a homing cycle before I can do anything else.
     
  5. drpeej

    drpeej New
    Builder

    Joined:
    Feb 23, 2016
    Messages:
    20
    Likes Received:
    2
    Thanks, thats helpful. I haven't yet enabled my limit switches so don't use homing but I will in the future.
     
  6. David the swarfer

    David the swarfer OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 6, 2013
    Messages:
    3,461
    Likes Received:
    1,915
    it also depends on your Gcode creator. If you use SketchUcam, it always puts in an Sxxxx instruction along with the
    M03 motor start command.
    other generators may/should do so as well, but the original posters one obviously does not, though there must be a way to tell it to set a spindle speed which would also solve the problem. After all, if you want the spindle to run it does make sense to tell it how fast to run at the same time.
     
  7. David the swarfer

    David the swarfer OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 6, 2013
    Messages:
    3,461
    Likes Received:
    1,915
    btw it can be done without recompiling with the PWM turned off. S0 will turn it off and S1000 or whatever the defined max speed is will turn it on, equivalent o 0 and 5 volts on the pin. BUT you have to make sure that no other speeds are selected, ever, since the relay is unlikely to enjoy being pulsed one and off at some 400 hz.
     
  8. drpeej

    drpeej New
    Builder

    Joined:
    Feb 23, 2016
    Messages:
    20
    Likes Received:
    2
    Thanks for all the advice. I realise that many Gcode creators already add in S commands. However the $N0=S1 solution has achieved what I want - thanks.
     
    David the swarfer likes this.
  9. Sonny Jeon

    Sonny Jeon Well-Known
    Staff Member Moderator Builder

    Joined:
    Aug 6, 2015
    Messages:
    165
    Likes Received:
    66
    FYI, this issue has been fixed in the most recent version of Grbl. When VARIABLE_SPINDLE is disabled, Grbl will ignore the S value and turn on the spindle with S0.
     
  10. drpeej

    drpeej New
    Builder

    Joined:
    Feb 23, 2016
    Messages:
    20
    Likes Received:
    2
  11. Prometheus

    Builder

    Joined:
    Mar 21, 2015
    Messages:
    17
    Likes Received:
    0
    So with using latest GRBL 1.1, how does one go about wiring in a relay? I have the Gradus board (Panucatt) and a 12v relay (NOT wired in yet). I am using the 0-10v VFD/GND from Gradus to Huanyang VFD VI/ACM and FOR/DCM with a jumper to be able to use the spindle but that is where the relay is "SUPPOSED" to go.. Please advise if possible.

    Thanks for the help!
     

    Attached Files:

  12. David the swarfer

    David the swarfer OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 6, 2013
    Messages:
    3,461
    Likes Received:
    1,915
    not sure what you are asking.
    the 0-10v is both speed control and spindle enable.
    what do you need the relay for?

    the SPDL PWM output should be connected to the same pin that creates the 0-10V but shoudl be a 5v TTL output.
    you can use that to control a relay
    BUT
    you must always send it the correct commands, S0 for off and Sx for on where x is the max spindle speed you set for GRBL.
    this will ensure the pin is either off or on.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice