Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: zmajmr on September 15, 2016, 03:22:44 AM

Title: Spindle button and M3 and M4
Post by: zmajmr on September 15, 2016, 03:22:44 AM
Hi guys,

I have CNC lathe , was running some G code yesterday, then wanted to pause spindle and feed in order to remove chips from tool safely, so I pressed feed hold button and spindle button.

When I wanted to proceed with execution of my G code program I pressed spindle button and cycle start button and thing is that I found out that spindle starts to rotate in M3 or CW mode/ direction ,
thing is that in program before stop it was command to use M4 or CCW , so it never crossed my mind that if I stop spindle that it will continue to execute g code program but with wrong RPM direction.

Today I went to find what is behind spindle button and it is function for spindle CW and reset THC height.

Now question is how to make that when I want to stop execution of g code and want to remove chips in safe way to proceed with g code but with spindle rotation which is programed by G code, did not tried yet but probably I can make same button below existing one that will give command to rotate spindel in CCW dirction,

Is it possible to make that by pressing only one button, somehow to program continue with correct RPM direction?

Yesterday was wondering how from some point my boring bar was producing chips like it was to aggressive cut, and was really surprised when I figured out that stopping spindle in the middle of program was thing that made problems , not depth of cut, luckily tool was not destroyed.
Hope somebody have some example how to solve this or what is normal procedure.

This is my machine and tool whit which I had problems (I thought that cuts to deep , first it was removing 0.1 mm of material then changed to 0.05 mm and after that I was, there is something wrong here LOL)
https://www.youtube.com/watch?v=8iJwtRoWx3o

Thanks in advance :)
Title: Re: Spindle button and M3 and M4
Post by: Davek0974 on September 15, 2016, 04:33:48 AM
Could possibly be done with a #var - every time the M3 or M4 is called it will store a value representing the last called direction in the variable, when you press spindle toggle manually, it would read that variable and call the correct direction.

I can see issues here but thats where i would probably start ;)
Title: Re: Spindle button and M3 and M4
Post by: zmajmr on September 15, 2016, 04:59:46 AM
Could possibly be done with a #var - every time the M3 or M4 is called it will store a value representing the last called direction in the variable, when you press spindle toggle manually, it would read that variable and call the correct direction.

I can see issues here but thats where i would probably start ;)
Hi

I read couple of time what you wrote and I do not not how to implement that, I mean where to use #var.

From my experience when some data need to be saved and read it only worked saving them in file otherwise every time I enter in macro variable is not remebered. Probbly I could use saving in file information but was hoping that there exist something simpler of what I am not aware of. Thank for your help. I assume somebody had this kind of problems already.
Title: Re: Spindle button and M3 and M4
Post by: Davek0974 on September 15, 2016, 05:32:53 AM
If done correctly, Mach will remember the variable for the current session.

I would need to test it out but possibly put the variable in M3,M4 macros or there may well be a better place.

It will need some testing but I'm sure this can be done.
Title: Re: Spindle button and M3 and M4
Post by: stirling on September 15, 2016, 06:16:17 AM
From my experience when some data need to be saved and read it only worked saving them in file otherwise every time I enter in macro variable is not remebered. Probbly I could use saving in file information but was hoping that there exist something simpler of what I am not aware of. Thank for your help. I assume somebody had this kind of problems already.

BASIC variables are destroyed between macro runs (except in the macropump) but GCODE vars are not. That's why Dave is suggesting you use a gcode var to maintain state between calls. Look up setVar and getVar().
Title: Re: Spindle button and M3 and M4
Post by: Davek0974 on September 15, 2016, 06:27:44 AM
This is quite an interesting issue, never thought about until now. ;)
Title: Re: Spindle button and M3 and M4
Post by: Davek0974 on September 15, 2016, 06:40:31 AM
I would start here....

First, get a safe backup copy of your entire Mach3 folder.

Next edit your M3 macro - its in the macro folder of the same name as the profile you are running.

Add, after the DoSpinCW() line...
SetVar(1601, 0)

Save the file

Edit the M4 file, same location,

Add after the DoSpinCCW() line
SetVar(1601,1)

Save the file

Edit your spindle button text.

Comment out the DoSpinCw() line by placing a ' at the start.

Then add...
 
If GetVar(1601)=0 then
DoSpinCW()
Else
DoSpinCCW()
End If

Save the button text.

Try that, I think it will work, with the usual disclaimers of course :)

This is all presuming that #var 1601 is a free variable and not used elsewhere, hard to tell with Mach ;)
Title: Re: Spindle button and M3 and M4
Post by: stirling on September 15, 2016, 07:16:44 AM
Close Dave but that means your spindle button has no way of turning OFF your spindle - but you're getting there  ;)
Title: Re: Spindle button and M3 and M4
Post by: Davek0974 on September 15, 2016, 07:43:14 AM
Ah, bugger, nobody mentioned turning it off :)

Ok, more thought......
Title: Re: Spindle button and M3 and M4
Post by: Davek0974 on September 15, 2016, 08:03:09 AM
I  can't see a better way so I would offer up

If IsOutputActive(OUTPUTcw) or IsOutputActive(OUTPUTccw) then
  DoSpinStop()
else
  If GetVar(1601)=0 then
    DoSpinCW()
  Else
    DoSpinCCW()
  End If
End if

Where cw and ccw are the port numbers assigned to M4 & M5 in ports & pins.
Title: Re: Spindle button and M3 and M4
Post by: stirling on September 15, 2016, 08:39:16 AM
You could remove the dependency on hard coded pins by using the CW and CCW Leds.
Title: Re: Spindle button and M3 and M4
Post by: Davek0974 on September 15, 2016, 08:46:08 AM
How about OEMLed(11) ?
My list shows "Spindle CCW/CW if either is requested"
Title: Re: Spindle button and M3 and M4
Post by: stirling on September 15, 2016, 08:49:29 AM
You need both LEDs to detect for ON just as you've used both outputs

Spindle rotating CW LED,   164
Spindle rotating CCW LED,   165
Title: Re: Spindle button and M3 and M4
Post by: Davek0974 on September 15, 2016, 08:58:42 AM
Fair enough then :)

If GetOEMLed(164) or GetOEMLed(165) then
  DoSpinStop()
else
  If GetVar(1601)=0 then
    DoSpinCW()
  Else
    DoSpinCCW()
  End If
End if

Seems better.
Title: Re: Spindle button and M3 and M4
Post by: Davek0974 on September 15, 2016, 09:05:33 AM
Will this work?
Brings all the code into the spindle-toggle button so no messing with M4/M5 etc

If GetOEMLed(164) Then          'was running forwards
  SetVar(1601,0)
  DoSpinStop()
ElseIf GetOEMLed(165) Then      'was running reverse
  SetVar(1601,0)
  DoSpinStop()
Else                                         'was not running
  If GetVar(1601)=0 Then
    DoSpinCW()
  Else
    DoSpinCCW()
  End If
End If
Title: Re: Spindle button and M3 and M4
Post by: stirling on September 15, 2016, 09:32:43 AM
Looks good - just a typo - you've set 1601 to 0 in both

Here's one for you though - what happens when you start Mach and hit the spindle button for the first time i.e. when it's off?
Title: Re: Spindle button and M3 and M4
Post by: Davek0974 on September 15, 2016, 09:39:43 AM
OK, sorted the typo...

Spindle start by toggle from first go, hmmm?

Are the #vars saved when Mach is closed?

If yes then it would start in the same rotation as left the day before - good or bad, I don't know.

If no then it would start forwards the first time as the #var would be zero, I guess we can add a reset macro to the INIT line that sets the #var however we want for the first time?

Depends if it's an issue or not i guess :)

Code: [Select]
If GetOEMLed(164) Then          'was running forwards
  SetVar(1601,0)
  DoSpinStop()
ElseIf GetOEMLed(165) Then      'was running reverse
  SetVar(1601,1)
  DoSpinStop()
Else                                         'was not running
  If GetVar(1601)=0 Then
    DoSpinCW()
  Else
    DoSpinCCW()
  End If
End If
Title: Re: Spindle button and M3 and M4
Post by: stirling on September 15, 2016, 10:14:40 AM
We'll make a programatist of you yet Dave  ;D

500-600 are persistent (they're saved in the xml) so you're good to go.
Title: Re: Spindle button and M3 and M4
Post by: Davek0974 on September 15, 2016, 10:29:11 AM
Ha, simple stuff i can handle, I do Visual Basic programming at work sometimes so this is pretty much the same.

Good to know about the 500-600, now if only there was a list of variables or a way of finding free ones ???

:)
Title: Re: Spindle button and M3 and M4
Post by: zmajmr on September 15, 2016, 04:09:16 PM
Hi , thx for help need to study all that and try , will let you know if it will work, I thought that somebody had that issue so there exist bulletproof solution and I only could not find it, also interesting info on destroying variables (BASIC) :)
Title: Re: Spindle button and M3 and M4
Post by: Davek0974 on September 15, 2016, 04:24:04 PM
Hi

reply no.16 has your answer, it all lives in the spindle toggle button.

One thing you may find with Mach is that there are few bullet proof solutions - many ways to solve most issues :)

Title: Re: Spindle button and M3 and M4
Post by: stirling on September 16, 2016, 04:06:54 AM
Just a thought but...

you start Mach and command M4, then M5. You then hit the spindle button - which way does the spindle turn?

I wonder if your original mods to M3/4 would give a more consistent feel.

Up to zmajmr I guess.

now if only there was a list of variables or a way of finding free ones ???

Not sure there's a definitive list but do some searches - there's bits and pieces scattered about - think of it as Mach3 Pokemon go  ;D.

also interesting info on destroying variables (BASIC) :)

The variables you create in a macro are all local, so like any other similar language, they are created and destroyed with each invocation.
Title: Re: Spindle button and M3 and M4
Post by: Davek0974 on September 16, 2016, 04:43:04 AM
Well, with the code all in the spindle button, it will rely on the status of the spindle LED's in Mach - providing these work it shouldn't matter if you pressed M4 M5 M4 M5 or whatever - it examines the status of those led's at the instant you press the toggle button ;)

Title: Re: Spindle button and M3 and M4
Post by: stirling on September 16, 2016, 05:22:44 AM
Nope.

You start Mach and do an M4 - spindle CCW
You do a M5 - spindle stopped.
You hit the button - both leds are off so it goes to the else clause to turn it on.
But which way?
Well - 1601 has never been touched yet so it's zero
So your spindle starts CW. - i.e. NOT what it was last doing.
Title: Re: Spindle button and M3 and M4
Post by: Davek0974 on September 16, 2016, 05:44:47 AM
Ah, i was wondering when you would spot that one :)

Definitely better to put the SetVar bits in the M3/M4 then I think, that would solve it, presuming there is no sneaky macro stuff running elsewhere calling an ActivateSignal(OUTPUTxx) :)
Title: Re: Spindle button and M3 and M4
Post by: stirling on September 16, 2016, 05:54:54 AM
presuming there is no sneaky macro stuff running elsewhere calling an ActivateSignal(OUTPUTxx) :)

well indeed - but if you have a system that does that I'd suggest a career in piano playing is not going to end well.  ;)
Title: Re: Spindle button and M3 and M4
Post by: Davek0974 on September 16, 2016, 06:11:18 AM
LOL ;)
Title: Re: Spindle button and M3 and M4
Post by: Davek0974 on September 16, 2016, 06:14:18 AM
So, to the OP,

In your M3 macro

Add...
SetVar(1601,0)

In your M4 macro

Add...
SetVar(1601,1)

In your spindle toggle code, find the line that says DoSpinCW() and put a ' at the start so it looks like 'DoSpinCW()

Then Add...

Code: [Select]
  If GetVar(1601)=0 Then
    DoSpinCW()
  Else
    DoSpinCCW()
  End If

Sorted :)
Title: Re: Spindle button and M3 and M4
Post by: stirling on September 16, 2016, 06:43:24 AM
Nooooooooooooooooooooooooooooo...  ;D

You've gone back to where you started.

See reply #7
Title: Re: Spindle button and M3 and M4
Post by: Davek0974 on September 16, 2016, 06:58:27 AM
Ah crap, i am trying to run a printing press at the same time though ;)(

This was the bit i wanted...

Code: [Select]
If GetOEMLed(164) or GetOEMLed(165) then
  DoSpinStop()
else
  If GetVar(1601)=0 then
    DoSpinCW()
  Else
    DoSpinCCW()
  End If
End if
Title: Re: Spindle button and M3 and M4
Post by: stirling on September 16, 2016, 07:25:48 AM
 ;)
Title: Re: Spindle button and M3 and M4
Post by: zmajmr on September 16, 2016, 03:45:24 PM
Thx guys, will definitely try that, today my sensor for referencing turret broke so I spent half of day to figure out what is going on, when I sort that will try that super spindle button code :)