0% found this document useful (0 votes)
7 views20 pages

6 - PLC Program

The document outlines the programming concepts related to PLC (Programmable Logic Controller) programs, distinguishing between system programs integrated into the CPU and user programs consisting of ordered instructions. It details the structure of user programs using organization blocks, function blocks, and global data blocks, and explains the differences between linear and modular programming structures. Additionally, it describes the standard programming languages available for S7-1200, including LAD, FBD, and SCL, and their respective functionalities.

Uploaded by

hthchuong2005
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views20 pages

6 - PLC Program

The document outlines the programming concepts related to PLC (Programmable Logic Controller) programs, distinguishing between system programs integrated into the CPU and user programs consisting of ordered instructions. It details the structure of user programs using organization blocks, function blocks, and global data blocks, and explains the differences between linear and modular programming structures. Additionally, it describes the standard programming languages available for S7-1200, including LAD, FBD, and SCL, and their respective functionalities.

Uploaded by

hthchuong2005
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Programming Concepts

Nguyễn Tấn Đời


What are the PLC programs
Two types:
 System program
 Be intergrated in CPU of PLC
 User program
 A set of instructions are arranged in order
 User program is loaded into PLC systems in machine code
 A sequence of binary code numbers represent the program instructions

2
PLC Operation

3
Start Events in the Operating System

4
The Cyclic Program Processing Sequence

5
Cyclic Program Processing

6
Blocks of User program
When you create a user program for the automation tasks, you insert the
instructions for the program into code blocks:
 An organization block (OB) responds to a specific event in the CPU and can interrupt the
execution of the user program.
 The default for the cyclic execution of the user program (OB 1) provides the base
structure for your user program and is the only code block required for a user program.
 A function block (FB) is a subroutine that is executed when called from another code block
(OB, FB, or FC).
 The calling block passes parameters to the FB and also identifies a specific data block (DB)
that stores the data for the specific call or instance of that FB.
 A function (FC) is a subroutine that is executed when called from another code block (OB, FB,
or FC).
 The FC does not have an associated instance DB. The calling block passes parameters to the
FC. The output values from the FC must be written to a memory address or to a global DB.

7
Functions
 Functions (FCs) are logic blocks without memory.
 They have no data memory in which values of block parameters can
be stored. Therefore, all interface parameters must be connected when
a function is called.
 To store data permanently, global data blocks must be created
beforehand.
 A function contains a program that is executed whenever the function is
called from another logic block.
 Functions can be used, for example, for the following purposes:
 Math functions – that return a result dependent on input values.
 Technological functions – such as individual controls with binary logic operations.
 A function can also be called several times at different points within a
program.
8
Organization Block Main [OB1] calls Function

9
Function Blocks and Instance Data Blocks
 Function blocks are logic blocks that store their input, output and in-out tags as well as static
tags permanently in instance data blocks, so that they are available after the block has been
executed.
For this reason, they are also referred to as blocks with "memory".
 Function blocks can also operate with temporary tags, which are are only available for one cycle.
 Function blocks are used for tasks that cannot be implemented with functions:
 Whenever timers and counters are required in the blocks, or
 When information must be stored in the program, such as preselection of the operating mode with a
button.
 Function blocks are always executed when called from another logic block. It can also be called
several times at different points within a program. This facilitates the programming of frequently
recurring complex functions.
 A call of a function block is referred to as an instance. Each instance of a function block is
assigned a memory area that contains the data that the function block uses. This memory is
made available by data blocks created automatically by the software.
 We can provide memory for multiple instances in one data block in the form of a multi-instance.
The maximum size of instance data blocks varies depending on the CPU. The tags declared in
the function block determine the structure of the instance data block.

10
OB1 calls Function Block and Instance

11
Global Data Blocks
 Data blocks contain no instructions. They
serve as memory for user data.
 Data blocks thus contain variable data that
is used by the user program. You can
define the structure of global data blocks as
required.
 Global data blocks store data that can be
used by all other blocks. Only the
 associated function block should access
instance data blocks. The maximum size of
data blocks varies depending on the CPU.
 Application examples for global data
blocks are:
 Saving of information about a storage system.
"Which product is located where?"
 Saving of recipes for particular products.

12
Type of structure user program
Based on the requirements of your application, you can choose either a linear
structure or a modular structure for creating your user program:
 A linear program: executes all of the instructions for your automation tasks in
sequence, one after the other. Typically, the linear program puts all of the program
instructions into the OB for the cyclic execution of the program (OB1).
 A modular program: calls specific code blocks that perform specific tasks. To
create a modular structure, you divide the complex automation task into smaller subordinate
tasks that correspond to the technological functions of the process. Each code block provides
the program segment for each subordinate task. You structure your program by calling one of
the code blocks from another block.

13
Using Blocks to Structure user program
 When a code block calls another code block, the CPU executes the program
code in the called block.
 After execution of the called block is complete, the CPU resumes the execution
of the calling block.
 Processing continues with execution of the instruction that follows after the
block call.

14
Using Blocks to Structure user program
 You can nest the block calls for a more modular structure.
 In the following example, the nesting depth is 4: the program cycle OB plus 3
layers of calls to code blocks.

15
Programming Language
STEP 7 provides the following standard programming languages for S7-1200:
 LAD (ladder logic) is a graphical programming language. The representation
is based on circuit diagrams.
 FBD (Function Block Diagram) is a programming language that is based on
the graphical logic symbols used in Boolean algebra.
 SCL (structured control language) is a text-based, high-level programming
language.
 When you create a code block, you select the programming language to be
used by that block.
 Your user program can utilize code blocks created in any or all of the
programming languages.

16
Lader Logic - LAD
 The elements of a circuit diagram, such as normally closed and normally
open contacts, and coils are linked to form networks.

 To create the logic for complex operations, you can insert branches to create
the logic for parallel circuits. Parallel branches are opened downwards or are
connected directly to the power rail. You terminate the branches upwards.
 LAD provides "box" instructions for a variety of functions, such as math, timer,
counter, and move.

17
Rules of a LAD Network

18
Function Block Diagram - FBD
 FBD is also a graphical programming language. The representation of the
logic is based on the graphical logic symbols used in Boolean algebra.

 Mathematical functions and other complex functions can be


represented directly in conjunction with the logic boxes.

19
Structure Control Language - SCL
 Structured Control Language (SCL) is a high-level, PASCAL-based programming
language for the SIMATIC S7 CPUs.
 You can also include program blocks written in SCL with program blocks written in
LAD and FBD.
 SCL instructions use standard programming operators, such as for assignment (:=),
mathematical functions (+, -, * and /).
 SCL also uses standard PASCAL program control operations, such as IF-THEN-
ELSE, CASE, REPEAT-UNTIL, GOTO and RETURN.
 Many of the other instructions for SCL, such as timers and counters, match the LAD
and FBD instructions.

20

You might also like