Hey all. What would it take to define a new digital output pin in marlin on the mini Rambo which simply inverts the logic of an existing pin?
Explanation: the vfd for my spindle runs on 12v logic, and has unique pins for fwd, rev, and reset (enable). These pins are pulled high by a pull-up internal to the vfd. They are activated by shorting to ground. So, pulling reset low disables the spindle. Fwd low turns forward, rev low turns in reverse. I am using an optoisolator to step up the 5v signal to 12v. The opto inverts the outputs. So in order to turn on reverse, I need to simultaneously set fwd high and rev low (I don’t know what happens if both are pulled low. When both are left high the spindle won’t turn, regardless of enable state. I assume one is set as default, or it won’t turn at all).
Right now fwd and enable work perfectly. But in order to get reverse working, I need a new output that is simply configured to be the opposite state as the SPINDLE-DIR pin.
I know enough coding in order to do this, but I don’t know WHERE in marlin to put it. I assume I would define a new pin in pins_minirambo…but where would I put the if statement. If spindle_dir is HIGH, rev_pin is LOW, and vice versa.
Is it actually more complex than this, or can it be done relatively easily?
Note: I’m not a Marlin developer, only a hack that ocassionally builds Marlin for his own machines.
I think you’d need to do that as code you write yourself, I don’t think there’s an easy way to define a pin that is opposite a different pin. If I"m wrong, then I’m sure the more competent developers will be along shortly to point out the error of my ways.
Wouldn’t it be easier to just use an inverting gate or even just daisy chain the opto , and thus do the logic level flip in hardware?
This is the point of my question. If it’s “a few lines of code” and a compile, then it’s easier than sourcing (albeit cheap) hardware I don’t have. If it’s REALLY involved on the software side, then you are absolutely right and the hardware approach IS easier
Don’t these align with M3, M4, M5 gcode commands? Are you sure they’re not already linked to pins for PWM spindle control? If so, you can probably just invert the existing pin rather than have to assign a new one.
I don’t think there is a way to invert an arbitrary pin, but for spindles there is SPINDLE_INVERT_DIR within Configuration_adv.h.
The same general approach is used for the stepper DIR pins via INVERT_X_DIR for example. It doesn’t change pin polarity in general, but the firmware has implemented the ability to change polarity for that specific pin.
Edit: Oops, I didn’t read the question carefully. This doesn’t help.
Find-in-files appears to show that this is the only important place where SPINDLE_DIR_PIN is used, so it should be sufficient to accomplish your complementary output.
To close the book on this, yes, the pins are linked to the m3, m4, m5 commands. and these are exactly the commands I am using. However m3 and m4 toggle the same pin (spindle_dir) in Marlin…HIGH for forward, LOW for reverse (or vise versa, dont remember the exact logic). However for my specific model of VFD, I need a unique pin for each m3 AND m4, since the VFD has a unique FWD (LOW=FWD, HIGH=OFF) and REV (LOW=REV, HIGH=OFF) pin. Hence Jaime’s solution was perfect as it just took another unused DO pin and made it the opposite of the native SPINDLE_DIR.
Now I can consider the ER style automatic tool changer like the RapidChange system: https://rapidchangeatc.com/
Oh no, I was just talking about buying that system, not developing my own. Having a working reverse is a pre-requisite. I could probably do it, but no reason to reinvent the wheel!