%
O2001 (SUB PROGRAM)
....
IF[#4NE1]GOTO10
M21 (X MIRROR ON)
10
;
;
IF[#4NE1]GOTO20
M16 (A MIRROR ON)
X0.Y0.A.Z1.
20
....
M99
%
OR
%
O2001 (SUB PROGRAM)
....
IF[#4NE1]GOTO10
M21 (X MIRROR ON)
M16 (A MIRROR ON)
10
....
M99
%
Hi all,
is there a simple way to activate an M code using an IF statement? I'm attempting to modify an existing logic program at my workplace so that an operator may set a local variable in a main program to activate/deactivate mirroring (X and A axis) when executing the associated subprograms. Several thousand existing programs will be affected by this so I am attempting to keep edits to a minimum.
abbreviated example:
%
O1000 (MAIN PROGRAM)
G65P2001A.....D1. (D0. FOR MIRRORING OFF, D1. FOR MIRRORING ON)
...
%
%
O2001 (SUB PROGRAM)
....
IF[#4EQ1]M21 (X MIRROR ON)
IF[#4EQ1]M16 (A MIRROR ON)
X0.Y0.A.Z1.
....
M99
%
I know this doesn't work but it does illustrate what I am trying to accomplish with the IF conditional. Is there a way to do this without adding reference to a sequence number like the following:
i.e.
%
O2001 (SUB PROGRAM)
....
IF[#4EQ1]GOTO10
M21
M16
N10
X0.Y0.A.Z1.
....
M99
%
I'm new to the macro game so take it easy on me! Thank you in advance for any tips.
Nick
Similar Threads:
%
O2001 (SUB PROGRAM)
....
IF[#4NE1]GOTO10
M21 (X MIRROR ON)
10
;
;
IF[#4NE1]GOTO20
M16 (A MIRROR ON)
X0.Y0.A.Z1.
20
....
M99
%
OR
%
O2001 (SUB PROGRAM)
....
IF[#4NE1]GOTO10
M21 (X MIRROR ON)
M16 (A MIRROR ON)
10
....
M99
%
****************************************************************
*~~Darwinian Man, though well-behaved, At best is only a monkey shaved!~~*
****************************************************************
*__________If you feel inclined to pay for the support you receive__________*
*______Please give to charity [url]https://www.oxfam.org.au/get-involved/______*[/url]
****************************************************************
no need to edit any program. Set two custom macro called by M code. One by M16 an other by M21. On my 0MD its is prm#230 to #239 to call macro 9020 to 9029. Asume that you set prm #231 to 16 and prm#232 to 21. So each time M16 appear, it call macro 9021 and each time M21 appear, it call macro 9022. You just have to dedicate 2 variables that can be set manually. Say #501 for M16 and #502 for M21 (i choose Variable in the 500's cause they remain after power off)
O9021
IF [#501 EQ 0] GOTO 10
IF [#501 EQ 1] GOTO 20
#3000=1(#500 WRONG VALUE)
N10 M99
N20 M16
M99
O9022
IF [#502 EQ 0] GOTO 10
IF [#502 EQ 1] GOTO 20
#3000=1(#500 WRONG VALUE)
N10 M99
N20 M21
M99
We could think that M16 or M21 code inside the macro will recall the macro, but not. It will be executed as it should be inside the macro. #501 and #502 can be set manually or in the main program.
****************************************************************
*~~Darwinian Man, though well-behaved, At best is only a monkey shaved!~~*
****************************************************************
*__________If you feel inclined to pay for the support you receive__________*
*______Please give to charity [url]https://www.oxfam.org.au/get-involved/______*[/url]
****************************************************************
Thanks guys, I appreciate your input. I'm forced to be very picky about how I do this because it needs to be completely idiot proof for the operator. A single incorrectly machined product will cost many thousand $$ to repair/replace. I think I've found a way to accomplish what I need. I'm currently proving this out for different scenarios in my spare time before I implement. I will post what I have come up with after I know it works properly.
Thanks again, great forum!
answer to original question;
(DEFAULT= MIRROR OFF)
#30=20(M20,X MIRROR OFF)
#31=15(M15,A MIRROR OFF)
IF[#4EQ1]THEN#30=21 (X MIRROR ON)
IF[#4EQ1]THEN#31=16 (A MIRROR ON)
M#30
M#31
...
M99
Last edited by norbert.barnard; 07-19-2010 at 10:50 AM. Reason: typing error
That "if/then" should work. Be aware that #4 will be reset to zero when reset is pushed. The 500 + variables retain their value even when the machine is shut off. 100-199 don't, but retain their values if you reset the control.
Since you are new to macro programming, you may not be knowing why it does not work (with or without THEN, which you missed).
The format of IF_THEN_ is
IF<a conditional expression>THEN<a macro statement>;
An M-code is an NC statement, hence it is not allowed.
Some alternate methods have already been suggested.
i recommend familiarizing yourself with the parameters available on your control before you assume ANYTHING...
for example, beware when someone suggests the way your machine will act, like what your variables #1-33, #100-149, #500-999 will do when reset is pressed or M30 is reached... as this is customizable via parameters and will not necessarily be the same on all of the same control
even what your reset button does ("reset" or "clear", look it up) will not even necessarily be the same...Code:6001 CCV Custom macro’s common variables Nos. 100 through 149 0: Cleared to “vacant” by reset 1: Not cleared by reset CLV Custom macro’s local variables Nos. 1 through 33 0: Cleared to “vacant” by reset 1: Not cleared by reset
there's even a parameter for allowing conditional gotos or not... or at least somewhat related from what i remember...Code:3402 CLR Reset button on the CRT/MDI panel, external reset signal, reset and rewind signal, and emergency stop signal 0 : Cause reset state. 1 : Cause clear state.
so read the parameter manual so you at least know what is variable... setting as much the same as i could on all my machines (9 mills of 6 MTB's and with 7 different controls) has really helped my ability to make custom posts, macros, and procedures that apply everywhere in the shop
- gwarble
Moreover, you need to seriously read programming books/manuals.