Topic: DMD0371 CALL - Call Subroutine |
|
The Call Subroutine (CALL) instruction is used to execute a user-defined Subroutine code-block. When a Call Subroutine instruction is executed, the ladder logic in the Subroutine runs at the point in the scan where the CALL instruction exists. Once the ladder logic within the Subroutine completes, normal scan execution resumes with the instruction immediately following the CALL instruction.
Subroutines can be called recursively, that is, a Subroutine can execute another instance of itself from within that Subroutine. Subroutines can be nested up to 84 levels deep. Exceeding this limit will generate a runtime error which will cause the CPU to revert to PROGRAM mode.
All Subroutines require a RET - Return Back to Call instruction be the last ladder logic instruction in the code block. One or more RETC - Conditional Return instructions can be used within the body of the Subroutine.
Note: by definition, the ladder logic in a Subroutine is meant to be reused. This is done through multiple CALL instructions, each with different input and output variables. To speed up the editing process, if one or more Subroutines already exist in the project the following message box will ask if you want to Utilize an existing CALL subroutine Input / Output parameter list ? as a starting point for this new CALL instruction.
Subroutine is the name of the Subroutine to execute. This can be an existing Subroutine, or you can enter the name of a new Subroutine and it will be created at this time. The Subroutine name can be 1 to 16 characters in length and consist of any combination of alphanumeric characters and underscores ('_', 'a-z', 'A-Z', 0-9), no spaces or punctuation marks are allowed, and must begin with a letter or an underscore.
Optional Input Parameters : it is usually preferred that you use unique memory locations inside the Subroutine. This is done by having the Call Subroutine instruction copy "external" input values to the locations that will be used in the ladder logic in the Subroutine. The Input Value locations are copied to the Into Subroutine locations each time the Call Subroutine instruction is executed. There can be up to 50 Input Parameters.
Note: Use the F9 key or click the 'three dot box' at the right edge of the parameter field to open the Default Element Selection Tool (the Element Picker or the Element Browser) or use the Down-Arrow key (Auto-Complete) on any parameter field to see a complete list of the memory locations that are valid for that parameter of the instruction.
Optional Output Parameters : it is usually preferred that you use unique memory locations inside the Subroutine. This is done by having the Call Subroutine instruction copy "internal" values to external locations that will be used in the rest of the project. The Out of Subroutine locations are copied to the Into locations each time the Call Subroutine execution is complete. There can be up to 50 Output Parameters.
Input Leg selects which of the following power-flow conditions will cause this instruction to run:
If enabled, the Called Counter increments each time the Subroutine execution is complete. This can be any writable numeric location.
|
|
Status Display:When the ladder status is ON the instruction will display the current value for Called Counter.
A gray triangle at the right end of the input leg this indicates this instruction is configured to be Edge Triggered Each time the input logic transitions from OFF to ON this instruction will execute. With each execution, this instruction will run to completion even if the input logic transitions to OFF before the instruction completes..
|
|
See Also:CALL - Call Subroutine
|
|
Related Topics:
|
|