Page 1 of 3

spindle brake

PostPosted: Wed Sep 11, 2019 3:26 pm
by dhanger
I recently converted from LinuxCNC to UCCNC. With LinuxCNC I had an output pin assigned to the spindle brake and the interface has a manual toggle for the brake on and off for tramming work. Spindle brake was automatically released on spindle start and then applied on spindle stop. Does UCCNC handle that in the background? I'm thinking not because there is no spindle brake assignment in the configuration so it wouldn't know. I looked through the list of output functions but didn't see it there either. Is there a substitute function I can use to assign my pin to that would activate every time the spindle is on? I suppose I could tie in to the M3/M4 relay but I don't really like that idea. I really liked having the spindle brake and would like to have it again in UCCNC.

Thanks, Dan

Re: spindle brake

PostPosted: Wed Sep 11, 2019 7:23 pm
by dhanger
So far what I've been able to come up with is that I could write a macro loop that autoruns and monitors the state of my spindle 'on' pin, then change the state of the brake pin accordingly. Am I on the right track? I also need to have a button on screen that I can use to temporarily disable the brake for tramming.

Re: spindle brake

PostPosted: Wed Sep 11, 2019 9:22 pm
by Robertspark
the only problem with that is a macroloop lags the other signals

What you can do is edit the M3, M4 and M5 macros to add in a toggle of an output in advance (of spindle CW or spindle CCW) and after spindle stop signal..... (if you add a while {} to monitor the actual spindle RPM it will allow the spindle to decelerate

you then add a screen button to toggle the same output.

Pick an output port and pin and I'll post something that may work for you

Re: spindle brake

PostPosted: Wed Sep 11, 2019 9:54 pm
by Robertspark
M3 macro text
Code: Select all
// if your spindle brake is fail safe (i.e. output needs to be HIGH to release)
exec.Setoutpin(1, 17); // port,pin

// Or if your spindle brake output needs to be low to release
//exec.Clroutpin(1, 17); // port, pin

exec.Wait(250); // allow the brake to release

exec.DospinCW(); // start spindle


M4 macro text
Code: Select all
// if your spindle brake is fail safe (i.e. output needs to be HIGH to release)
exec.Setoutpin(1, 17); // port,pin

// Or if your spindle brake output needs to be low to release
//exec.Clroutpin(1, 17); // port, pin

exec.Wait(250); // allow the brake to release

exec.DospinCCW();  // start spindle


M5 macro text
Code: Select all
exec.Stopspin();

while( Convert.ToDouble(AS3.Getfield(870)) >0 ) {};  // wait for actual spindle speed to slow to a stop before applying brake

// if your spindle brake is fail safe (i.e. output needs to be HIGH to release)
exec.Clroutpin(1, 16); // port, pin

// Or if your spindle brake output needs to be low to release
//exec.Setoutpin(1, 17); // port,pin

Re: spindle brake

PostPosted: Wed Sep 11, 2019 10:05 pm
by Robertspark
Button Macro Code (Choose an M number from M20000 to M21999 and add a button to the screen + assign it the corresponding number e.g. M20000, the button number would be "20000")

Code: Select all
//check if spindle is turning, if so, do nothing and return

if (Convert.ToDouble(AS3.Getfield(870)) >0)
{
return;
}

if (AS3.GetLED(17) == true) // check status of port1, pin 17
{
exec.Clroutpin(1, 17); // port, pin

}
else
{
exec.Setoutpin(1, 17); // port,pin

}



Re: spindle brake

PostPosted: Wed Sep 11, 2019 10:07 pm
by Robertspark
if you choose to use a different port + pin you will need to change the numbers in the M3, M4 M5 and Button code macros.

But, within the button code macro you will have to assign another number to the GetLED(17) to match the port and pin you are toggling, so that the GetLED can check the current state and allow you to flip its state.

Re: spindle brake

PostPosted: Thu Sep 12, 2019 12:20 pm
by dhanger
Hi Robert-

Thanks for taking the time with this, I'm just starting to get to know the way UCCNC works under the hood and your macro mods help with that understanding better. I'm only an occasional programmer and was able to figure out some of the simpler things with LinuxCNC's HAL but not much more than that. So far I'm finding UCCNC easier to understand so I'm liking that. As soon as I have a chance I'll give this a try. Whether I succeed or have more questions I'll re-post.

One question: I see what may be a potential problem with the M5 macro--when I do power tapping I don't have rigid tapping set up so I use a floating head, I wonder if the macro will be responsive enough to make and break the brake for that purpose. Since the spindle is not coupled with the Z axis I can see potentially getting too far out of sequence with the floating head. I could maybe modify my post to add a pause before reversing the spindle but that seems hit or miss. Is there a way to query the G code to see if it's tapping and disable the brake sequencing in M5 temporarily? Spindle reversing is responsive enough to not need braking during tapping.

Re: spindle brake

PostPosted: Thu Sep 12, 2019 12:40 pm
by Robertspark
All you do is create an LED on your screen and give it a unique (high) number to allow for room when CNCdrive update uccnc (this is just because the new screensets will probably add new LED's, adding a lower number won't affect UCCNC, its all to do with whether the screen already has that number assigned as to whether you get a clash, don't worry about it too much, juct pick a high number away from the defined numbers and all will be fine)

You then create another button on your screen to toggle that LED.

And you modify M5 to look at that LED and if it is active, then ignore the brake, otherwise apply the brake.

So when you are doing tapping you can click the screen button which will disable the brake, or at least it would be ignored when M5 runs.

Something like this, say your new LED is #500:

revised M5 macro:

Code: Select all
exec.Stopspin();

while( Convert.ToDouble(AS3.Getfield(870)) >0 ) {};  // wait for actual spindle speed to slow to a stop before applying brake

if (AS3.GetLED(500) == true) {  // i.e. ignore BRAKE for tapping is set
return;
}

// if your spindle brake is fail safe (i.e. output needs to be HIGH to release)
exec.Clroutpin(1, 16); // port, pin

// Or if your spindle brake output needs to be low to release
//exec.Setoutpin(1, 17); // port,pin



Your new button on the screen, say call it "20001" {so the macro would be M20001.txt}:
Code: Select all
if (AS3.GetLED(500) =! true) {  // i.e. LED not set
AS3.SetLED(true, 500);  //set it
}
else {
AS3.SetLED(false, 500);  // clear it
}

Re: spindle brake

PostPosted: Thu Sep 12, 2019 12:50 pm
by Vmax549
A problem you will face is M3/4/5 is not always used in UCCNC to turn teh spindle on/off.

Been there done that, (;-) TP

Re: spindle brake

PostPosted: Thu Sep 12, 2019 12:57 pm
by dhanger
Vmax549 wrote:A problem you will face is M3/4/5 is not always used in UCCNC to turn teh spindle on/off.

Been there done that, (;-) TP


Well that complicates things. Under what conditions are they ignored?