Jan 13, 2023 Zanechat vzkaz

Must Have Knowledge Of Macro Programming

 

Nowadays, many CNC technicians don't understand macro programs. They think that with automatic programming software, they don't need to learn macro programs. In fact, the functions of macro programs are very powerful. For example, to write some batch and repetitive programs, you only need to change a few data when using macro programs. There is no need for a large number of repeated programming, which can greatly simplify operations and greatly improve work efficiency.

Macro programs can use variables to perform mixed operations of arithmetic operations, logic operations and functions, and also provide loop statements, branch statements and subroutine call statements.

Generally speaking: macro program is suitable for the programming of a series of parts with the same graphics but with different sizes; it is suitable for the programming of a series of parts with the same process path but with different position parameters; it is suitable for the programming of parabolas, ellipses, hyperbolas and other curves without interpolation instructions.

01
Representation and use of variables

1. Variable representation

#I(I=1,2,3,…) or #[]
Example: #5, #109, #501, #[#1+#2-12]

2. Use of variables

1) Specify the variable number or formula after the address word
Format:

#I
Here "I" stands for variable number
Example: F#103, if #103=15, then it is F15
Z-#110, if #110=250, it is Z-250
X[#24+#18*COS[#1]]

2) The variable number can be replaced by a variable
Example: #[#30], if #30=3, it will be #3

3) Variables cannot use addresses O, N, I
Example: The following methods are allowed
O#1;
I#2 6.00×100.0;
N#3 Z200.0;

4) The variable corresponding to the variable number has a specific value range for each address
Example: When #30=1100, M#30 is not allowed

5) #0 is an empty variable, and a variable without a defined variable value is also an empty variable

6) Variable value definition:
The decimal point can be omitted when the program is defined, for example: #123=149

02
type of variable

Add pictures to WeChat: yuki7557 will send a macro program tutorial

1. Local variables #1~#33

A variable used locally in a macro program, its operation result cannot be used by other programs.
Example: A macro program B macro program
...
#10=20 X#10 does not mean X20
...
It will be cleared after power off, and the variable value will be filled in when the macro program is called

2. Public variables #100~#199, #500~#999

The common variable in each user macro program has the same operation result in any program call.
Example: When #10 in the above example is changed to #100, the
X#100 means X20
#100~#149 Empty after power off
#500~#531 Persistent variables (not lost after power off)

3. System variables

Fixed-purpose variable whose value depends on the state of the system
Example: #2001 is the X-axis compensation value of No. 1 tool compensation
#5221 value is X axis G54 workpiece origin offset value
A decimal point must be entered when entering, and the unit is μm when the decimal point is omitted

03
Operation instruction

The right side of the expression can be constants, variables, functions, expressions
In the formula, #j and #k can also be constants
The right side of the expression is the variable number, the expression

1. Definition

#I=#j

2. Arithmetic operations

#I=#j+#k
#I=#j-#k
#I=#j*#k
#I=#j/#k

3. Logical operations

#I=#JOK#k
#I=#JXOK#k
#I=#JAND#k

4. Functions

#I=SIN[#j] sine
#I=COS[#j] cosine
#I=TAN[#j] tangent
#I=ATAN[#j] arc tangent
#I=SQRT[#j] square root
#I=ABS[#j] absolute value
#I=ROUND[#j] Rounding off
#I=FIX[#j] round up
#I=FUP[#j] Round down
#I=BIN[#j] BCD→BIN (binary)
#I=BCN[#j] BIN→BCD

1) Angles are in degrees
Example: 90 degrees and 30 minutes are 90.5 degrees

2) The two side lengths after the ATAN function should be separated by "/"
Example: #1=ATAN[1]/[-1], #1 is 35.0

3) ROUND is used for the address in the statement, rounded up according to the minimum setting unit of each address
Example: Set #1=1.2345, #2=2.3456, setting unit is 1μm
G91 X-#1; X-1.235
X-#2 F300; X-2.346
X[#1+#2]; X3.580
is not returned and should be replaced by
X[ROUND[#1]+ROUND[#2]];

4) If the absolute value after rounding is greater than the original value, it will be rounded up, otherwise it will be rounded down
Example: When #1=1.2, #2=-1.2
If #3=FUP[#1], then #3=2.0
If #3=FIX[#1], then #3=1.0
If #3=FUP[#2], then #3=-2.0
If #3=FIX[#2], then #3=-1.0

5) When commanding a function, only the first two letters can be written
Example: ROUND→RO
FIX→FI

6) Priority
Function → multiplication and division (*, 1, AND) → addition and subtraction (+, -, OR, XOR)
Example: #1=#2+#3*SIN[#4];

7) The brackets are square brackets, up to 5 times, and the brackets are used for comment statements
Example: #1=SIN[[[#2+#3]*#4+#5]*#6]; (3 weights)

04
Branch and Loop Instructions

1. Unconditional Transfer

Format: GOTO n;

Unconditionally branch to block n
n: block number (1-99999)
n can also be replaced by variables or expressions
goto10;
GOTO #10;

2. Conditional transfer

IF [] GOTO n;
If the is satisfied, the next operation will transfer to the block with the block number n.
If not satisfied, execute the next block.
Add WeChat: yuki7557 to send a macro program tutorial
IF [] THEN ... ;
If the is satisfied, the macro program statement after THEN is executed, and only one statement is executed.
IF[#1EQ #2] THEN #3=0;

Conditional expression:

#j and #k can also be replaced by

Example: IF[#1 GT 10] GOTO 100;

N100 G00 G91 X10;
Example: Find the sum of 1 to 10
O9500;
#1=0
#2=1
N1 IF [#2 GT10] GOTO 2
#1=#1+#2;
#2=#2+1;
GOTO 1
N2 M30

3. Cycle

Format: WHILE[]DO m; (m=1, 2, 3)



ENDm

1. When the conditions are met, execute DOm to ENDm, then from the program segment of DOm
If not satisfied, execute the program segment following ENDm
2. If you omit the WHILE statement and only have DOm...ENDm, an infinite loop will be formed from DOm to ENDm
3. nesting
4. EQ NE, empty and "0" are different
Elsewhere, null is the same as "0"

Example: Find the sum of 1 to 10
O0001;
#1=0;
#2=1;
WHILE [#2LE10] DO1;
#1=#1+#2;
#2=#2+#1;
END1;
M30;

 

 

Odeslat dotaz

whatsapp

skype

E-mail

Dotaz