4 Access Protection
F- System Blocks
5.1.3 Differences between the F-FBD and F-LAD Programming Languages and the Standard FBD and LAD Programming
Languages
Introduction
The user program in the F-CPU typically consists of a standard user program and a safety program. The standard user program is created in STEP 7 using standard programming languages such as STL, LAD, or FBD.
The safety program for S7 Distributed Safety is programmed using F-FBD or F-LAD.
Programming Languages F-FBD and F-LAD
The F-FBD and F-LAD programming languages correspond in principle to the standard FBD/LAD languages. The standard FBD/LAD editor in STEP 7 is used for programming.
The primary differences between the F-FBD and F-LAD programming languages and their standard counterparts are limitations in the instruction set and the data types and the address areas that can be used.
Supported Data and Parameter Types
The following elementary data types are supported in F-FBD/F-LAD: • BOOL
• INT • WORD • TIME
Illegal Data and Parameter Types
Illegal types are as follows:
• Elementary data types not listed above (for example, BYTE, DWORD, DINT, REAL)
• Complex data types (for example STRING, ARRAY, STRUCT, UDT) • Parameter types (for example, BLOCK_FB, BLOCK_DB, ANY)
Supported Address Areas
The system memory of an F-CPU is divided into the same address areas as the system memory of a standard CPU. You can access the address areas listed in the table below in the safety program.
Note that you can only access data in F-FBD and F-LAD as follows: • Data of data type BOOL only in bits
• Data of data type INT only in words • Data of data type WORD only in words • Data of data type TIME only in double words
For example: You can access input channels of data type BOOL in the process input image of F-I/O only by means of the "input (bit)" unit.
This restriction does not apply when accessing data from the standard user program (for bit memory or process image of standard I/O, refer to Communication between Standard User Program and Safety Program), if a data type declaration was not made for these data in the symbol table. However, you can access these data only by means of the same unit. For example: If you access M0.0, you cannot access MW0, as well.
For reasons of clarity, you should always access address areas in a safety program using a symbolic name.
Address Area Accessible Size Units: S7 Notation Description Process Input Image
• Of fail-safe I/O At the beginning of the F-runtime group (F-CALL), the F-CPU reads the inputs from the F-I/O and saves the values to the process input image. Input channels are read-only channels.
Therefore, transfer to IN_OUT parameters of an F-FB or F-FC is not permitted.
Channels of data type BOOL, such as digital channels
Input (bit) I Read access to input channels of data type BOOL is possible by means of the "input (bit)" unit only. Access is not possible, for example, with the "input word" unit. Channels of data
type INT (WORD), such as analog channels
Input word IW Read access to input channels of data type INT (WORD) is possible by means of the "input word" unit only. It is not possible to access individual bits by means of the "input (bit)" unit.
At the beginning of each OB1 cycle, the F- CPU reads the inputs from the standard I/O and saves the values to the process input image. With the S7-400, bear in mind the update timing when using process image partitions. • Of standard I/O Input (bit) Input word I IW
Input channels of the standard I/O can only be accessed as read-only channels by means of the units listed.
Therefore, transfer to IN_OUT parameters of an F-FB or F-FC is not permitted.
Moreover, a validity check is required specifically for each process (see
Communication between Standard User Program and Safety Program).
Process Output Image
• Of fail-safe I/O In the F-PB, the safety program calculates the values for the outputs of the F-I/O and stores them in the process output image. At the end of the F-runtime group (F-CALL), the F-CPU writes the calculated output values to the outputs of the F-I/O. Output channels are read-only channels.
Therefore, transfer to IN_OUT parameters of an F-FB or F-FC is not permitted.
Address Area Accessible Size Units: S7 Notation Description
In the F-PB, the safety program also calculates the values for the outputs of the standard I/O, if applicable, and stores them in the process output image. At the beginning of the next OB1 cycle, the F-CPU writes the calculated output values to the outputs of the standard I/O (see Communication between
Standard User Program and Safety
Program). With the S7-400, bear in mind the
update timing when using process image partitions. • Of standard I/O Output (bit) Output word Q QW
Output channels of the standard I/O can only be accessed as write-only channels by means of the units listed.
Therefore, transfer to IN_OUT parameters of an F-FB or F-FC is not permitted.
Memory Marker Memory marker (bit) Memory marker word
M MW
This area is used for data exchange with the standard user program.
Memory bits can only be accessed by means of the units listed.
In addition, read access requires a process- specific validity check.
Both read access and write access are possible for a memory marker in the safety program.
Therefore, transfer to IN_OUT parameters of an F-FB or F-FC is not permitted.
Note that memory bits are only allowed to connect the standard user program and the safety program; they cannot be used as a buffer for F-data (see Communication
between Standard User Program and Safety Program).
Data blocks store information for the program. They can either be defined such that all F-FBs, F-FCs, and F-PBs can access them (F-DBs), or they can be assigned to a particular F-FB or F-PB (instance DB). They must be created with the "F-DB"
programming language or as an instance DB of an F-FB or F-PB.
Data Block
Data bit Data word Data double word
DBX DBW DBD
Data can only be accessed by means of units that correspond to the data type in the declaration table.
Local Data This memory area accepts the temporary
Address Area Accessible Size Units: S7 Notation Description
Local data bit Local data word Local data double word
L LW LD
Local data can only be accessed by means of units that correspond to the data type in the declaration table.
Illegal Address Areas
Access by means of units other than those listed in the table above is illegal, as is access to address areas not listed, in particular:
• Counters (fail-safe counters are implemented using F-application blocks from the Distributed Safety F-library (V1) : F_CTU, F_CTD, F_CTUD)
• Timers (fail-safe timers are implemented using F-application blocks from the Distributed Safety F-library (V1) : F_TP, F_TON, F_TOF)
• Data blocks from the standard user program • Data blocks (F-DBs) by means of "OPN DI" • Data blocks that are automatically added
- Exception: certain data in the F-I/O and F-shared DB of the safety program • I/O area: inputs
• I/O area: outputs
Boolean Constants "0" and "1"
If you require Boolean constants "0" and "1" in your safety program to assign parameters during block calls, you can access the "RLO0" and "RLO1" variables in the F-shared DB using fully qualified DB access ("F_GLOBDB".RLO0 or
Local Data Address Area: Particularities
Note
Note when using the local data address area that the first access of a local data element in an F-PB/F-FB/F-FC must always be a write access, which initializes the local data element.
Make sure that the initialization of the local data element is not skipped over by JMP, JMPN or RET instructions (branching).
Initialization of a "local data bit" should be performed with the Assign ("=")
instruction (F-FBD) or Output Coil ("--()") instruction (F-LAD). Assign the local data bit signal state "0" or "1" as Boolean constant.
Local data bits cannot be initialized with the Flip Flop (SR, RS), Set Output (S) or Reset Output (R) instructions.
The F-CPU can go to STOP if this is not observed. One
of the following diagnostic events is then entered in the diagnostic buffer of the F-CPU:
• "Data corruption in the safety program prior to output to F I/O" • "Data corruption in the safety program prior to output to partner
F-CPU"
• "Safety program: internal CPU fault; internal error information: 404"
You can find out which address areas are possible for your F-CPU in the product information for the CPU you are using.
Address areas for N, P, NEG, POS, S, R, SR; RS addresses: particularities
Note
The "process input image," "process output image," and "bit memory" address areas must
not be used for edge memory bits of the RLO Edge Detection (N, P) or Address Edge Detection
(NEG, POS) instructions or for the address of the Flip Flop (SR, RS) instructions. If the "local data" address area is used for the edge memory bits of the RLO Edge Detection (N, P) or Address Edge Detection (NEG, POS) instructions or for the address of the Flip Flop (SR, RS), Set Output (S), or Reset Output (R) instructions, the local data bit must be initialized beforehand.
Supported Instructions
You can use the instructions listed in the table below in the safety program.
Instruction Function Description
F-FBD F-LAD
>=1 - Bit logic instruction OR logic operation & - Bit logic instruction AND logic operation
XOR - Bit logic instruction EXCLUSIVE OR logic operation ---| - Bit logic instruction Insert binary input
---o| - Bit logic instruction Negate binary input
= - Bit logic instruction Assign
- ---| |--- Bit logic instruction Normally open contact - ---| / |--- Bit logic instruction Normally closed contact - ---|NOT|--- Bit logic instruction Invert power flow - ---( ) Bit logic instruction Output coil # ---(#)--- Bit logic instruction Midline output S ---(S) Bit logic instruction Set output R ---(R) Bit logic instruction Reset output SR SR Bit logic instruction Set-reset flip flop RS RS Bit logic instruction Reset-set flip flop
N ---(N)--- Bit logic instruction Negative RLO edge detection NEG NEG Bit logic instruction Address negative edge detection P ---(P)--- Bit logic instruction Positive RLO edge detection POS POS Bit logic instruction Address positive edge detection WAND_W WAND_W Word logic instruction (Word) AND Word
WOR_W WOR_W Word logic instruction (Word) OR Word
WXOR_W WXOR_W Word logic instruction (Word) Exclusive OR Word ADD_I ADD_I Integer function Add integer
DIV_I DIV_I Integer function Divide integer MUL_I MUL_I Integer function Multiply integer SUB_I SUB_I Integer function Subtract integer
CMP ? I CMP ? I Comparison instruction Compare integer (CMP==I, CMP<>I, CMP>I, CMP<I, CMP>=I, CMP<=I)
NEG_I NEG_I Conversion instruction Twos complement integer OPN ---(OPN) DB instruction Open data block
Instruction Function Description
JMP ---( JMP ) Jump instruction Unconditional jump in block Jump in block if 1 (conditional) JMPN ---( JMPN ) Jump instruction Jump in block if 0 (conditional) OV OV ---| |--- Status bit Evaluate exception bit overflow
(OV bit in status word)
S Instruction: Particularities
Note
The Set Output (S) instruction is only executed if it is applied to an output of an F-I/O that is passivated (e.g., during startup of the F-system). For this reason, you should attempt to access outputs of F-I/O only with the Assign ("=") (F-FBD) or Output Coil ("--( )") (F-LAD) instruction.
You can evaluate whether an F-I/O is passivated in the associated F-I/O DB (see F-I/O Access).