1.3 Subroutine

Basically, there is no difference between a main program and a subroutine. Frequently recurring machining sequences are stored in subroutines, e.g certain contourshapes. These subroutines are called at the appropriate locations in the main program and then executed. One form of subroutine is the machining cycle. Machining cycles contain universally valid machining scenarios (e.g.: thread cutting, stock removal, etc.). By assigning values via included transfer parameters, you can adapt the subroutine to your specific application. The subprogram is given a unique name allowing it to be selected from among the others.

1.3.1  Classification and definition of the subroutine

Classification:

Standard subroutine: Subroutines without parameters, it can be called by the main program and another subroutine.

Parameter subroutine: It will work by transfer parameters to the subroutine, when you call a parameter subroutine.

Definition:

Standard subroutine: the same as main program.

Parameter subroutine: beginning with ‘PROC’, ending with ‘RET’.

Example:

PROC SUN (TYPE1 VAR1, TYPE2 VAR2, ……)

……

RET

1.3.2 Subroutine call

Subroutines are called in a program (main or subprogram) with their names. Subroutine is called must be in the same directory of the main program. To do this, a separate block is required. If a subroutine is to be executed several times in succession, write the number of times it is to be executed in the block of the call after the subroutine name under the address P. A maximum of 99 passes are possible (P1 ... P99).

Example1: Standard subroutine call, "()" can be omitted

N10 WELLE7() P3                                      ; Call of the subroutine WELLE7, 3 passes

Or N10 CALL WELLE7() P3                       ; Call of the subroutine WELLE7, 3 passes

Example2: Parameter subroutine call(assuming WELLE8 has 5 parameters)

N10 WELLE8(10, 50, R32, , R45) P5           ; Call of the subroutine WELLE8, 5 passes

Or N10 CALL WELLE8(10, 50, R32, , R45)  ; Call of the subroutine WELLE8

Parameter can be constants, variables or R Parameter. Parameters without assignment define as zero. That is, the fourth parameter is zero.

Note

1. Modal G functions can be changed in the subroutine, e.g. G90 −> G91. When returning to the calling program, ensure that all modal functions are set the way you need them to be.

2. When executing an M02 in the subroutine, the program returns to the main program, while the main program ends.

1.3.3 Program nesting depth

Subroutines can also be called from a subroutine, not only from a main program. Totally,  12 program levels, including the main program level are available for such a nested call.

                           Fig.1.4 Program call nesting

1.3.4 Subroutine parameter pass

Subroutine parameter passing is divided into two forms, passed by value and pass by address. Parameters passed by value only participate as an input parameter in the called subroutine, even if their value changes, they would not feedback to the upper program. Parameters passed by address participate as an input-output parameter in the called subroutine, they will feedback to the upper program. To realize the parameters being passed by address, "VAR" keywords need to be added in front of correspondence argument of the called routine.

Example:

PROC  SUB1 (……)

DEF REAL PT

DEF REAL M2PIT

……

SUB2 (PT, M2PIT)

……

RET

PROC SUB2 (VAR REAL PT, REAL M2PIT)

……

RET

In the subroutine "SUB1", it defines two parameters "PT" and "M2PIT". When calling the subroutine "SUB2", "PT" passes by address, "M2PIT" is passed by value. The aim of the call is that in "SUB2" according to "M2PIT" value accordingly modifies "PT", and the results feedback to the "SUB1" for continuing to use. That is the change "SUB2" to "PT" can be transmitted to the "SUB1".

0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
5.2.7 Boring with stop 1 (boring pass 3) CYCLE87
Viewed 2132 times since Fri, Aug 26, 2016
1.4 Program jumps
Viewed 25826 times since Thu, Aug 25, 2016
2.1 Absolute / incremental dimensioning: G90/G91, AC/IC
Viewed 5532 times since Thu, Aug 25, 2016
3.2 Tool offset number D
Viewed 1994 times since Fri, Aug 26, 2016
2.5 Programmable working area limitation: G25,G26,WALIMON,WALIMOF
Viewed 2350 times since Thu, Aug 25, 2016
4.2 System parameter
Viewed 3696 times since Fri, Aug 26, 2016
6.1 Outer contouring
Viewed 1740 times since Fri, Aug 26, 2016
5.3.1 Groove CYCLE93
Viewed 4249 times since Fri, Aug 26, 2016
5.2.5 Reaming1 (boring 1) CYCLE85
Viewed 10652 times since Fri, Aug 26, 2016
5.2.9 Reaming 2 (boring 5) CYCLE89
Viewed 1965 times since Fri, Aug 26, 2016