Open drain "Spindle enable" configuration on an SBase v1.3 with GRBL-LPC?

I’m trying to convert my JCUT 6090 laser cutter to use an MKS SBase board rather than the PCI controller card and dedicated computer I had before.

Initially I intended to use Smoothieware but due to various problems I have decided to switch to grbl-lpc. I have done a test build and have been able to control my external stepper drivers, but I haven’t wired up the laser power supply yet.

As best as I can tell, unlike a K40 LPS, my LPS is supposed to take PWM on pin 5 rather than an analog voltage. I plan to use the default P2.5 mosfet output for the PWM, but I also want to wire up an active low enable pin for the laser. I’m also trying to avoid adding to many extra components. What I would like is to set the “SPINDLE_DIRECTION_BIT” (that I’m using for SPINDLE_ENABLE) to be open drain and then add a pull up resistor to it.

So to finally get to my question, can I just edit the cpu_map.h file to use the Stepper A pins (which I have already set to open drain in the config.h file) for the “SPINDLE_DIRECTION_BIT”?

So it would look like // Define spindle enable and spindle direction output pins.
#define SPINDLE_ENABLE_BIT 30 // P1.30
#define SPINDLE_DIRECTION_BIT 22 // P0.22

Would that work? If yes, would I need to change "A_DIRECTION_BIT " to something else or can I just leave it defined in both places? If I change "A_DIRECTION_BIT " to something else, will the open drain config also change or will it stay on P0.22?

Or if I can’t do that, what about changing “SPINDLE_DIRECTION_BIT” to one the other Mosfet enable pins?

Or is there an easier way to make the “SPINDLE_DIRECTION_BIT” open drain?

I really don’t understand a lot about this and I’m trying to avoid burning up my MKS board.


I massaged a fork into shape and made a PR for @cprezzi to merge, but ended up not using it (at least so far). But OPEN_DRAIN_A sets open drain mode on P2.3, P0.22, and P0.21.

Thank you for the reply. I think I saw the thread about that and I believe @cprezzi added that to his code. In the config.h file I have this:

// Open Drain configuration
// In order to use stepper drivers with optocoupler input, you may need to use
// open drain configuration. In this configuration, STEP, DIR, and ENABLE each
// expose separate positive and negative pins. The positive pins on the driver
// are tied directly to +5V, and the negative pins are separately routed to the
// STEP, DIR, and ENABLE pins on the controller board, which function as
// low-side switches to ground.
#define OPEN_DRAIN_X
#define OPEN_DRAIN_Y
#define OPEN_DRAIN_Z
#define OPEN_DRAIN_A

But what I don’t know is can I assign P2.3, P0.22, and/or P0.21 to other uses and still have them be open drain? I’m sure this has to do with my lack of knowledge about programming, but I’m just trying to get by.

Thank you,

If you define OPEN_DRAIN_A then those three pins will be set to open drain every time steppers are set up, regardless of any other settings using those pins. That might be considered a bug, but that’s what the code does right now, as far as I see.