Siemens SIMATIC S7-200 System Manual page 68

Programmable controller
Hide thumbs Also See for SIMATIC S7-200:
Table of Contents

Advertisement

S7-200 Programmable Controller System Manual
Subroutines
These optional elements of your program are executed only when called: by the main program, by
an interrupt routine, or by another subroutine. Subroutines are useful in cases where you want to
execute a function repeatedly. Rather than rewriting the logic for each place in the main program
where you want the function to occur, you can write the logic once in a subroutine and call the
subroutine as many times as needed during the main program. Subroutines provide several
benefits:
Using subroutines reduces the overall size of your program.
-
Using subroutines decreases your scan time because you have moved the code out of the
-
main program. The S7-200 evaluates the code in the main program every scan cycle,
whether the code is executed or not, but the S7-200 evaluates the code in the subroutine
only when you call the subroutine, and does not evaluate the code during the scans in
which the subroutine is not called.
Using subroutines creates code that is portable. You can isolate the code for a function in a
-
subroutine, and then copy that subroutine into other programs with little or no rework.
Tip
Using V memory addresses can limit the portability of your subroutine, because it is possible for
V memory address assignment from one program to conflict with an assignment in another
program. Subroutines that use the local variable table (L memory) for all address assignments,
by contrast, are highly portable because there is no concern about address conflicts between
the subroutine and another part of the program when using local variables.
Interrupt Routines
These optional elements of your program react to specific interrupt events. You design an interrupt
routine to handle a pre-defined interrupt event. Whenever the specified event occurs, the S7-200
executes the interrupt routine.
The interrupt routines are not called by your main program. You associate an interrupt routine with
an interrupt event, and the S7-200 executes the instructions in the interrupt routine only on each
occurrence of the interrupt event.
Tip
Because it is not possible to predict when the S7-200 might generate an interrupt, it is desirable
to limit the number of variables that are used both by the interrupt routine and elsewhere in the
program.
Use the local variable table of the interrupt routine to ensure that your interrupt routine uses only
the temporary memory and does not overwrite data used somewhere else in your program.
There are a number of programming techniques you can use to ensure that data is correctly
shared between your main program and the interrupt routines. These techniques are described
in Chapter 6 with the Interrupt instructions.
Other Elements of the Program
Other blocks contain information for the S7-200. You can choose to download these blocks when
you download your program.
System Block
The system block allows you to configure different hardware options for the S7-200.
System
Block
Data Block
The data block stores the values for different variables (V memory) used by your program. You
can use the data block to enter initial values for the data.
Data
Block
54

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents