S7 functions

Nov 21, 2005 5 Replies

I wonder if somebody could explain to me the difference between function blocks and function calls.



Thanks


formatting link
?q=function+calls Jerry

Kinda hoping for a short definative reply rather than having to trawl through 26 million or so pages looking for a difference. Thanks anyway. ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

formatting link
formatting link
C++:
formatting link
Jerry

A S7 or PLC Open function has no state. It uses only the parameters. For instance, a sine or cosine function only care about the angle. When implemented all the parameters are pushed on the stack and a value is returned in the accumulator or stored using a pointer. However, all the data that is pushed on the stack is "popped" off so the function starts with all new parameters the next time it is executed.

A S7 or PLC Open function block has state. A PID would be a function block because it must keep track of the errors and integrator state. This means that each instance of a FB must be declared or allocated in some way because each instance of a FB has it's own copy of "static" variables to hold the state. In the case of a PID, each PID would need to keep track of its own integrator and error history.

A function block is like a C function with a pointer to static variables.

Peter Nachtwey

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required