S7-1200 Basic Instructions
Nguyễn Tấn Đời
1
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
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.
5
Basic Instructions
Bit instructions
Timer
Counter
Compare
Math
Move
6
Bit Instructions – Check Bit
Checked bit
Checked bit
Checked bit
7
Bit Instructions – Asign Bit
8
Bit Instructions – Set/ Reset Bit
9
Example_1
Draw the wiring diagram.
Inputs Sinking
Outputs Sourcing
The motor 3 phases, the lamp 24VDC.
The Coil contactor 220VAC (optional).
Write the PLC program in 2 cases:
using Asign Bit instruction and
using Set/ Reset Bit instructions.
NO button pushed: the motor runs.
Sensor actived: the lamp turned on.
NC button pushed: the motor stops
and the lamp turned off.
10
Example_2
Draw the wiring diagram.
Inputs Sinking
Outputs Relay
The motor 3 phases, the solenoids 24VDC.
The Coil contactor 220VAC (optional).
Write the PLC program.
The tank is empty (FS signals low): solenoids
A and B energized, C de-energized.
Start button pushed: solenoids A and B
energized. Motor runs forward.
When the tank is full (FS signals high):
STOP
solenoid B de-energized, C energized. Motor
runs reverse.
Stop button pushed: Motor stops, all solenoids START
de-energized
11
Positive and Negative Edge Instructions
12
Timers Instructions
You use the Timer instructions to create programmed time delays. Each Timer uses a 16 byte
IEC_Timer data type DB structure to store timer data that is specified at the top of the box or coil
instruction. STEP 7 automatically creates the DB when you insert the instruction.
13
The Parameters of Timer
14
The PT and IN Parameters
15
Operation of the Timer – TON
TON: ON-delay timer
The TON timer sets output Q to ON after a preset time delay.
16
Timer Programming
17
Example_3
Draw the wiring diagram.
DI Sourcing.
DO Sinking.
Write the PLC program.
The barrow must be in the correct
position (limit switch S1 actived).
Start button pushed (NO): M2 runs.
5s later M1 runs. 10s later Y opens.
Stop button pushed (NC): Y closes.
5s later M1 stops. 5s later M2 stops.
One of two motors overloaded: the
system stop. The lamp turned on.
Lamp and Valve Y 24VDC. Motors M1
and M2 3 phases. Contactor 220V
18
Example_4
The system to be controlled by PLC consists
of two belts.
Draw the wiring diagram.
Construct a LAD for S7-1200 PLC to control
the system.
If the Start button is pressed, Conveyor Belt-1
will begin to run. After 5 seconds Conveyor
Belt-2 will be active. After the whole system
runs for 15 seconds, Conveyor Belt-1 will stop.
Then Conveyor Belt-2 continues to move for 5
seconds and then it will stop, too.
Also the system can be reset by the
emergency-stop button at any time.
19
Counter Instructions
20
The Parameters of Counter
21
Operation of the CTU
The CTU counter counts up by 1 when the
value of CU changes from 0 to 1.
The CTU timing diagram shows the
operation for an unsigned integer count
value (where PV = 3).
If the value of CV (current count value) is
greater than or equal to the value of PV
(preset count value), then the counter output
Q = 1.
If the value of the reset R changes from 0 to
1, then the current count value is reset to 0.
22
Operation of the CTD
The CTD counter counts down by 1 when
the value of CD changes from 0 to 1.
The CTD timing diagram shows the
operation for an unsigned integer count
value (where PV = 3).
If the value of CV (current count value) is
equal to or less than 0, the counter output
Q = 1.
If the value of LOAD changes from 0 to 1,
the value at PV (preset value) is loaded to
the counter as the new CV (current count
value).
23
Example_5
The ball classification system is controlled by S7-1200
CPU1214C DC/DC/DC.
The system contains two conveyor belts. The conveyor
carries balls and boxes, moving by two 3 phases motors.
If the Start button is pushed, box conveyor will begin to move.
When the box triggers the sensor SE2, the box conveyor
stops and the ball conveyor begins to move.
The weight sensor WS measures the ball weights. If the ball
weight is 500g, the WS is on state (it’s contact is closed).
The ball conveyor carries two size of the balls, 250g and
500g. If weight of the first ball is 500g, the box is filled with 3
balls. Otherwise the box filled with 5 balls with 250g.
In the system, the sensor SE1 is used to detect the balls.
After the box is filled with the balls as specified above, the ball
conveyor stops and box conveyor begins to move. 1. Draw the wiring diagram of the system.
The system can be reset by a Stop button any time. 2. Construct the PLC LAD program to control
SE1 and SE2 are NPN photoelectric sensors. WS is limit switch. the system.
24
Compare Instructions
25
Math Instructions – Calculate instruction
26
Add, Subtract, Multiply and Divide Instructions
27
Move and Block Move Instructions
28
Move and Block Move Instructions
29
Example_6
The parking lot which has a capacity of 100
cars is to be controlled by a PLC system.
The sensor S1 and S2 are used to count the
car at the entrance and exit.
If the number of the cars reaches to 100, red
light is lit and the gate arm is closed. The arm
stays closed until one or more parking space
is available in the lot.
The gate arm is controlled by activating or
deactivating the gate solenoid (GS).
Construct LAD for the parking lot controller by
using math instructions.
30