15.07.2013 Views

Automatic control function programming manual ladder language

Automatic control function programming manual ladder language

Automatic control function programming manual ladder language

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Return code<br />

If OK<br />

Value returned by the %SP module called using <strong>function</strong> return ().<br />

Not significant if the called module does not return a value.<br />

Example of Use of sp(), cpyarg(), return()<br />

General Purpose Functions<br />

Exchange of arguments during a call to an %SP module<br />

Calling module (%TS, %TF or %SP):<br />

%M100.W = sp(33, 10, %M20.B + %M30.B);<br />

Module called %SP33:<br />

Arguments 10 and (%M20.B + %M30.B) are extended to 32 bits<br />

and stored on the stack. The call to %SP33 is then made.<br />

cpyarg(M200.&, 2); Copies the two parameters of the call to local memory starting from<br />

%M200. The value 10 is stored in %M200.L and the result of the<br />

expression (%M20.B + %M30.B) is stored in %M204.L.<br />

return(%V100.W+25);<br />

Recommendation<br />

Return to calling module. The value of expression %V100.W + 25<br />

is loaded in %M100.W.<br />

Passing arguments avoids inter-module communication via common variables.<br />

This <strong>programming</strong> concept is recommended because it keeps the modules independent, thereby facilitating their<br />

reuse in other applications.<br />

6.26.2 Call an %SP Module with %Y Local Variables spy<br />

Syntax<br />

spy(moduleno {, argn}6 ...)<br />

moduleno: Number of the %SP module to be called.<br />

argn: Optional argument.<br />

Calls an %SP module (%SP0 to %SP255) with creation of 128 %Y local variables and passes it any arguments via<br />

the stack.<br />

Operation<br />

The module number must be between 0 (call to %SP0) and 255 (call to %SP255).<br />

128 %Y local variables are created in the stack. These variables are deleted on return to the calling programme.<br />

The arguments are extended on 32 bits and stored on the stack except moduleno which is not stacked.<br />

The total number of arguments (including moduleno) must not exceed NBM_PARAM (i.e. 7).<br />

spy(..) and %Y variables are used to write relocatable, reentrant %SP modules.<br />

REMARK The sample programme L_E_VAR.MCH available under PLCTOOL illustrates instruction<br />

spy().<br />

en-938846/7 6 - 23<br />

6

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!