Siemens 840D Training Course
Macro Programming Examples
This document is made available as a preliminary version (draft).
Questions and feedback should be sent to
[email protected]1
Macro Programming Examples using Siemens Arithmetic Variables & Programming Aids
and Cimco Editor, NC-Assistant, and Backplot
Example 1
There is a requirement to produce a range of plates with radial Keyhole Slots for a family of motor products. The
larger range require more slots in the radial array and the slot sizes vary dependent on the plate size. See below
the diagram of the keyhole slots and the variable sizes.
See below a section of the Header from the Program with the basic assignment of variables. The arithmetic R
variables can be edited to the sizes that are required for the current production run of parts. All sizes here are in
mm. The diagram is set at 0 degrees (3PM)
; KEY SLOT DETAILS
;------------------------------------------
R0=80 ;KEY SLOT LENGTH
R1=20 ;KEY SLOT WIDTH
R2=90 ;DIST TO START OF SLOT
R3=30 ;KEY HOLE DIAMETER
R4=20 ;TOTAL DEPTH
R5=4 ;NO. OF CUTS TO DEPTH
R6=10 ;NO. OF RADIAL SLOTS
R7=16 ;CUTTER DIAMETER
;-------------------------------------
2
When we have entered the variable details, we can test the program using the Cimco Editor Backplot facility.
Note the two screen shots below with different numbers of slots at different sizes.
Let’s look at the structure of the program that uses the ROT rotation of coordinates to achieve the multiple radial
keyhole slots and incremental depth cuts to machine through the plate. We need to have the end point
3
coordinates in X and Y to create the profile, we need to have the angle to rotate the coordinates depending on
the number of keyhole slots and we need to have the incremental depth from the number of cuts we have
decided on. See below the section of the program that assigns the variable and calculates the points we need to
make the program run. We are using the variables in the low digits for the basic assignment, and we are using
variables starting at R50 for the profile points and calculations. There are variables Savailable from R0 to R999.
See below the basic assignment and the description of the calculation blocks.
;KEY SLOT DETAILS
;------------------------------------------
R0=60 ;KEY SLOT LENGTH
R1=14 ;KEY SLOT WIDTH
R2=50 ;DIST TO START OF SLOT
R3=23 ;KEY HOLE DIAMETER
R4=20 ;TOTAL DEPTH
R5=4 ;NO. OF CUTS TO DEPTH
R6=8 ;NO. OF RADIAL SLOTS
R7=11 ;CUTTER DIAMETER
;-------------------------------------
R50=R2+R0/2 ;X CO-ORD OF KEY SLOT CENTRE
R51=R1/2 ;Y CO-ORD KEY OF SLOT EDGE
R52=R3/2 ;RAD OF KEY HOLE
R55=SQRT((R3/2*R3/2)-(R1/2*R1/2)) ;X START POINT OF KEY HOLE (POINT 2 & 3 see diagram)
R56=R0+R2-(R52+R55) ;X COORD TO START OF KEY HOLE
R57=R2+R1/2 ;X CO-ORD OF NEAR RADIUS
R58=360/R6 ;ANGLE BETWEEN SLOTS
R59=R4/R5 ;INC DEPTH
R60=1 ;DEPTH COUNTER
R61=0 ;ROTATION ANGLE COUNTER (0=3PM)
IF R7>=R1 ;TEST IF CUTTER IS TOO BIG GO TO LABEL "ERR" There is a requirement to test for errors in the
entry of variables in this type of programming.
GOTOF ERR1 Here is a simple example of a test to see it the
ELSE cutter selected is too big for the slot. A fully
formed program would have several tests to
GOTOF N1 safeguard the running of the program and the
correctness of part geometry, etc.
N1 G54 ;WORK SHIFT
G0 Z100
4
X0 Y0
T11
D1
ROT RPL=R61 ;SET ROTATION TO ZERO
ANGLE: ;LABEL
G0 Z10
G1 Z0 F1000 S350 M3 ;FEED DOWN TO Z ZERO
;--- SLOT PROFILE & Z MOVES---
SLOT: ;LABEL
X=R50 Y=0 ;MOVE TO SLOT CENTRE
G91 Z-R59 ;INCREMENT Z DOWN
G90 ;BACK TO ABSOLUTE
G1 G41 Y=-R51 ;ENGAGE CUTTER COMP
X=R56
G3 X=R56 Y=R51 I=R55 J=R51
G1 X=R57
G3 Y=-R51 I0 J=-R51
G1 X=R50
G40 Y0 ;DISENGAGE CUTTER COMP
ENDLABEL: ;END OF PROFILE
R60=R60+1 ;INCREMENT DEPTH COUNTER
IF R60>R5 ;TEST DEPTH COUNTER
GOTOF N2 ;GOTO FORWARD TO N2 IF R60 GT R5
ELSE
GOTOB SLOT ;ELSE GO BACK TO LABEL SLOT REPEAT PROFILE
ENDIF
N2 R60=1 ;RESET DEPTH COUNTER
G0 Z10 ;MOVE Z UP CLEAR
R61=R61+R58 ;INCREMENT ANGULAR ROTATION
IF R61>=360 ;TEST ANGULAR ROTATION
GOTOF END ; GO TO END LABEL
ELSE
ROT RPL=R61 ;SET NEW ROTATION ANGLE
5
GOTOB ANGLE ; GO BACK TO ANGLE LABEL
ENDIF
END:
G0 Z100
ROT ;CANCEL ANGULAR ROTATION
G0 X-200 Y-200 ;MOVE TO UNLOAD POSITION
M30 ;END OF PROGRAM AND RESET
;***** ERROR SECTION *****
ERR1: ;LABEL FOR CUTTER DIA TEST
MSG ("CUTTER DIAM GREATER THAN SLOT WIDTH")
M00 ; STOP PROGRAM AND THE MSG ABOVE WILL BE EVIDENT ON THE CNC HMI
6
Example 2
There is a requirement to produce an elliptical hole in a plate to accept a pipe to be welded to the plate that has
been cut at an angle. See drawing below.
From the start of the program, you can see the basic R variable assignment that will be used to control the size
and shape of the Ellipse.
R1=125 ;CENTRE IN X
R2=80 ;CENTRE IN Y
R3=61.5 ;RADIUS IN X
R4=47 ;RADIUS IN Y
R5=0 ;START ANGLE
R6=360 ;END ANGLE
R7=100 ;NO OF STEPS
See below the resulting Solid Animation Backplot. The program to create the ellipse is listed below with
comments attached to the blocks with explanations. We have only considered the elliptical shape here and some
area clearance or pilot holes may be required for Z axis entry etc.
7
%_N_0110_MPF
;$PATH=/_N_WKS_DIR/_N_SIEMENS_TEST_JB_WPD
;DESCRIPTION-ELLIPSE PARA SUB
Program Header with comment details
;DRAWING NO-00000 ISSUE-A
;OPERATION-MILL ELLIPSE PROFILE
;PROGRAMMER-JOE SMITH
;DATE/TIME-08/10/2021 10:50:44
;---------------
R1=125 ;CENTRE IN X
R2=80 ;CENTRE IN Y
Variable Assignment
R3=61.5 ;RADIUS IN X
R4=47 ;RADIUS IN Y
R5=0 ;START ANGLE
R6=360 ;END ANGLE
R7=100 ;NO OF STEPS
The Ellipse can be rotated to an angle with
R8=0 ;ROTATIONAL ANGLE OF ELLIPSE this variable. Zero degrees is at 3 O/Clock
R9=16 ;TOTAL DEPTH
R10=100 ;FEED FOR PLUNGING
R11=350 ;FEED FOR MILLING
8 Variable Assignment
R12=2 ;SET UP CLEARANCE
Variable Assignment
R13=50 ;RETRACT PLAIN
R14=30 ;PROFILE OFFSET INSIDE IN X
;-----------------------------
M6 T12 ;CALL THE TOOL INTO THE SPINDLE
D1 ;ACTIVATE TOOL OFFSET
G0 Z=R13 ; RAPID TO Z RETRACT PLANE
TRANS X=R1 Y=R2 ; TEMP WORK SHIFT TO CENTRE OF ELLIPSE
ROT RPL=R8 ; ROTATION ANGLE OF ELLIPSE (0=3PM)
R35=(R6-R5)/R7 ;CALC INCREMENTAL ANGLE
R36=R5 ;START ANGLE Angle count set to -1 to get a one-step
blend overlap
R37=-1 ;SET ANGLE COUNTER
R21=R3*COS(R36) ;CALC X END POINT OF CURRENT ANGLE
R22=R4*SIN(R36) ;CALC Y END POINT OF CURRENT ANGLE
R23=R3-R14 ;CALC SAFE START POSITION
S2000 M3 ;START SPINDLE
G0 X=R23 Y=R22 ;MOVE TO ELLIPSE SAFE START POSITION
Z=R12 ;RAPID DOWN TO SAFE START POSITION IN Z
G1 Z=-R9 F=R10 ;FEED DOWN TO DEPTH
G41 X=R21 Y0 ; MOVE ONTO ELLIPSE PROFILE
LBL1: ;LABLE
R36=R36 +R35 ;CALC NEW ANGLE
R37=R37 +1 ;INCREMENT COUNTER +1
R21=R3*COS(R36) ;CALC X END POINT OF CURRENT ANGLE
R22=R4*SIN(R36) ;CALC Y END POINT OF CURRENT ANGLE
G1 X=R21 Y=R22 F=R11 ;MACHINE CURRENT ELLIPSE INCREMENT
IF R37 < R7 GOTO LBL1 ;TEST INCREMENT COUNT
ENDLABEL: ;END LABEL
G0 G40 X=R23 Y=R22 ;MOVE BACK TO START POSITION
TRANS ;CANCEL TEMP WORK SHIFT TO ELLIPSE CENTRE
ROT ;CANCEL ROTATION OF ELLIPSE
G1 Z=R12 ; FEED UP TO Z SAFE POSITION
G0 Z=R13 ; RAPID UP TO Z RETRACT PLANE
9
G53 X0 Y0 ;MOVE TO MACHINE ZERO X & y TO UNLOAD
M30 ;END OF PROGRAM RESET
10
Example 3
There is a requirement to produce multiple profiled parts from a sheet on material in rows and columns. See
below the profile programmed here that can be found within the body of the program. A sub program machining
a more complex part could be called from this program instead of the profile here. From the diagram below see
the points as indicated 0-14 used to create the program blocks that will change family shape dependent on the
variables entered. A program that can be seen below further down the will facilitate the simple editing of these
variables to create multiple parts form a given sheet of material.
See the basic variable entries below:
;---NOTCHED PROFILE DETAILS ---
R1=80 ;WIDTH
R2=80 ;DEPTH
R3=20 ;CORNER RAD
R4=16 ;NOTCH RAD
R5=20 ;TOTAL DEPTH
R6=3 ;NO. OF CUTS TO DEPTH
;--- ROW, COLUMN, Z DETAILS ---
R7=50 ;RETRACT HEIGHT
11
R8=2 ;R PLANE Z POSITION
R9=4 ;NO OF ROWS Y
R10=3 ;NO OF COLUMNS X
R11=60 ;POSN OF 1ST PROFILE X
R12=86 ;POSN OF 1ST PROFILE Y
R13=132 ;DIST BETWEEN ROWS Y
R14=100 ;DIST BETWEEN COLUMNS X
R15=1500 ;Z PLUNGE FEED RATE
R16=2000 ;PROFILING FEED RATE
From the entries above the program can be tested. See the Tool path Backplot below showing the correct number
of depth cuts and regular spacing as per the entries …..
12
If we now wish to test the program in Solid Animation the Solid Setup must be set to depict the sheet size to test
the nesting of the multiple parts. To do this we need to fix the first part using variables R11 and R12 and then set
the Solid Setup X, Y, Z, plus and minus to represent the area of sheet material that our Rows and Columns will fit.
To set R11 and R12 see the guide below: The simple formula below will fix the first part on the sheet and other
parts will be spaced as per the other variables.
R11=R1/2+20 (Position of 1st part in X)
R12=R2/2+R4+20 (Position of 1st part in Y)
In Solid Animation, Solid Setup needs setting to represent the sheet so that the resultant sheet size shown on the
Editor screen, will accommodate all the parts. To achieve a sensible Solid Setup block size, use the formula below
and enter the Solid Setup box as indicated below:
X- (Min) = 0 --- X+ (Max)=(R10-1)*R14+R11*2 (EG (3-1)*100+60*2=320)
Y-(Min) = 0 --- Y+ (Max )=(R9-1)*R13+R12*2 (EG (4-1)*132+86*2=568)
Enter Block sizes here for X, Y, Z,
Min and Max sizes Open Solid Setup Box here
When finished tick here to retain
these sizes so that you can repeat
the test a few times if necessary.
13
See the resulting Solid Animation from the Cimco Editor below.
See the whole program set out below with comment descriptions on each block.
%_N_0110_MPF
;$PATH=/_N_WKS_DIR/_N_SIEMENS_TEST_JB_WPD
;DESCRIPTION-MULTIPAL PROFILES
;CPN-000
Program Header
;DRAWING NO-00000 ISSUE-0
;PROGRAMMER-JOHN BRIDGE
;DATE/TIME-21/10/2021 10:47:45
;------------------------------
;---NOTCHED PROFILE DETAILS ---
R1=80 ;WIDTH
R2=80 ;DEPTH
R3=20 ;CORNER RAD
R4=16 ;NOTCH RAD
R5=20 ;TOTAL DEPTH
14
R6=3 ;NO. OF CUTS TO DEPTH
;--- ROW, COLUMN, Z DETAILS ---
R7=50 ;RETRACT HEIGHT
R8=2 ;R PLANE
R9=4 ;NO OF ROWS Y
R10=3 ;NO OF COLUMNS X
R11=0 ;POSN OF 1ST PROFILE X
R12=0 ;POSN OF 1ST PROFILE Y
R13=132 ;DIST BETWEEN ROWS Y
R14=100 ;DIST BETWEEN COLUMNS X
R15=1500 ;Z PLUNGE FEED RATE
R16=2000 ;PROFILING FEED RATE
;--- Y COORD CALCS ---
R101=0 ;NOT USED
R102=R2/2-R3 ;Y START CORNER RAD
R103=R2/2 ;HALF DEPTH Y
;--- X COORD CALCS ---
R111=0 ;NOT USED
R112=R4 ;NOTCH RAD START X
R113=R1/2-R3 ;X START CORNER RAD
R114=R1/2 ;HALF WIDTH X
;--- DEPTH, COUNTER, SET ---
R55=R5/R6 ;INC DEPTH
R56=R6 ;DEPTH COUNTER
R57=0 ;ROW COUNTER
R58=0 ;COLUMN COUNTER
R60=0 ;Y TRANS POSN
R61=0 ;X TRANS POSN
;----------------------
;****** PROGRAM START ********
TRANS ;CANEL ALL TEMP ORGINS
G54 ;ACTVATE MAIN WORK ORIGIN
TC("7.3_ENDMILL") ;TOOL CHANGE
15
M00 ;PROGRAM STOP - CHECK TOOL
D1 ;ACTVATE TOOL OFFSET
G0 Z=R7 ; MOVE Z TO RETRACT HEIGHT
TRANS X=R11 Y=R12 ;ABSOLUTE TEMP ORIGIN
G0 X0 Y0 ;MOVE THE TEMP ORIGIN ZERO
Z=R8 F2000 S350 ;MOVE TO R PLANE
Z0 F=R15 ;MOVE TO Z ZERO
;----------------------
;***** COLUMN PROGRAMMING *****
REPEAT PROF1 ;JUMP TO PROF1
Z0 ;MOVE TO Z ZERO
R58=R58+1 ;INC COLUMN COUNTER
COL1: ;LABEL
G0 Z=R8 ;MOVE TO R PLANE
G0 Z0 ;RESET TO Z0
R58=R58+1 ;INC COLUMN COUNTER
R56=R6 ;RESET DEPTH COUNTER
ATRANS X=R14 ;SET COLUMN OFFSET
G0 X0 ;MOVE TO X0 Y0
Z0 ;MOVE TO Z0
REPEAT PROF1 ;CALL PROFILE SECTION
G0 Z=R8 ;MOVE TO Z R PLANE
IF R58<>R10 GOTOB COL1 ;TEST COLUMN COUNT
;--------------------
;***** ROW PROGRAMMING *****
R58=0 ;RESET COL COUNT
R57=R57+1 ;INC ROW COUNTER
IF R57==R9 GOTOF END ;TEST ROW COUNT
R60=R57*R13 ;CALC ROW COORDINATE
TRANS ;CANCEL ALL TEMP ORIGINS
TRANS X=R11 Y=R12 ;RESET TEMP ORIGIN
ATRANS Y=R60 ;SET ROW TEMP ORIGIN
G0 X0 Y0 ;MOVE TO NEW ROW
16
Z R8 F2000 S350 ;MOVE TO Z R PLANE
Z0 F=R15 ;MOVE TO Z ZERO
R56=R6 ;RESET DEPTH COUNTER
REPEAT PROF1 ;JUMP TO PROF1
R58=R58+1 ;INC COLUMN COUNTER
IF R57<>R9 GOTOB COL1 ;TEST ROW COUNT
GOTOF END ;JUMP TO END
;--------------------
;-- PROFILE --
PROF1: ;LABEL
R56=R56-1 ;INCREMENT COUNTER
G91 Z =-R55 ;INCREMENT Z DOWN G91
G90 ;BACK TO ABSOLUTE G90
G0 G41 X0 Y0 ;POINT 0
G1 X=R114 Y0 ;POINT 1
G1 X=R114 Y=R102 ;POINT 2
G3 X=R113 Y=R103 I=-R3 J0 ;POINT 3
G1 X=R112 Y=R103 ;POINT 4
G3 X=-R112 Y=R103 I=-R4 J0 ;POINT 5
G1 X=-R113 Y=R103 ;POINT 6
G3 X=-R114 Y=R102 I0 J=-R3 ;POINT 7
G1 X=-R114 Y=-R102 ;POINT 8
G3 X=-R113 Y=-R103 I=R3 J0 ;POINT 9
G1 X=-R112 Y=-R103 ;POINT 10
G3 X=R112 Y=-R103 I=R4 J0 ;POINT 11
G1 X=R113 Y=-R103 ;POINT 12
G3 X=R114 Y=-R102 I0 J=R3 ;POINT 13
G1 X=R114 Y0 ;POINT 14
G0 G40 X0 Y0 ;POINT 15
IF R56>0 GOTOB PROF1 ;TEST COUNT
ENDLABEL: ;END LABEL
;-------------
END: ;LABEL
17
G0 Z=R7 ;GO TO RETRACT HEIGHT
TRANS X0 ;CANCEL ALL TEMP ORIGINS
G0 X-100 Y-100 ;MOVE TO UNLOAD POSITION
M30 ;END OF PROGRAM RESET
18