You are on page 1of 58

Programabilni Logički Kontroleri

PLC

1. PLC hardware

2. PLC programiranje i način funkcionisanja

3. PLC programske funkcije

4. Diskretne I/O funkcije i uređaji


Uvod
• PLC je digitalni elektronski uređaj projektovan da upravlja mašinam i/ili procesima
primenjujući sekvencijalno (vremensko ili vođeno događajima) upravljanje.
• PLC je dizajniran za upotrebu u teškim industrijskim uslovima. Može se programirati bez
posebnih znanja programiranja i može ga održavati tehničar za održavanje fabrike.
• Neke od prednosti PLC-a su:

1. Fleksibilnost. Jedan PLC može da obradi mnogo različitih operacija. Softverske


izmene se lakše implementiraju od hardverskih.

2. Pouzdanost. Solid-state uređaji su pouzdaniji i lakši za održavanje od mehaničkih


releja i tajmera.

3. Niža cena. Bazira se na činjenici da poluprovodnička tehnologija (procesori)


omogućuje implementaciju složenih funkcija i složenih izračunavanja po veoma
niskoj ceni.

4. Dokumentacija. Iz softvera za programiranje je moguće direktno iscrtati šeme


regulacionih krugova. Nema potrebe za posebnim crtanjem određenih crteža koji
postaju zastareli istog trenutka čim se izvrši neka izmena.
PLC hardware

PS CPU IM SM: SM: SM: SM: FM: CP:


(opcija) Procesor (opcija) DI DO AI AO - brojanje - Point-to Point
Napajanje Interfejs - pozicija - PROFIBUS
Signalni Moduli -Zatvorena - Industrial Ethernet
povratna petlja
Funkcijiski
Moduli
PLC hardware
CPU 314 until Oct. 2002 CPU 314 after Oct. 2002
PLC hardware
S7-400 Automation System
PLC programiranje i funkcionisanje - Ladder Diagram
• LD (Ladder – Lestvičasti Diagram) programski jezik koristi simbole kontakata za
formiranje dijagrama koji su veoma slični kontaktorskim šemama.

• Simbol za normalno otvoreni kontakt podseća simbol za električni kondenzator.

• Simbol za normalno zatvoren kontakt je isti kao za otvoreni kontakt sa dijagonalnom


linijom preko.

• Simbol za izlaz se sastoji od dve male zagrade.

• Svaki kontakt i izlazni simbol ima broj upisan odmah ispod (ili iznad) njega.
Ovaj broj identifikuje lokaciju u procesorskoj memoriji (RAM), gde se čuva vrednost
(podatak) sa tog kontakta ili izlaza.
PLC programiranje i funkcionisanje - Ladder Diagram
Upravljanje pneumatskim cilindrom
PLC programiranje i funkcionisanje - Ladder Diagram
Upravljanje pneumatskim cilindrom
PLC programiranje i funkcionisanje - Ladder Diagram
Upravljanje pneumatskim cilindrom
PLC programiranje i funkcionisanje - Ladder Diagram
Upravljanje pneumatskim cilindrom

Slika na prethodnom slajdu prikazuje ulazne, procesorsku i izlazne jedinice PLC-a korištene
za upravljanje pneumatskim cilindrom.
Kvadrati (1,2, 3 i 4) u ulaznom modulu IM:1 sadrže konvertore koji konvertuju prekidačke
ulaze u logičke naponske nivoe.
Četiri linije povezuju ulazne “kvadratiće” sa memorijskim ćelijama (lokacijama) koje čuvaju
informacije o statusu odgovoarajućih ulaza.
Gornja desna ćelija ulaznog dela memorije je povezana sa ulazom 1, ulaznog modula IM-1,
tak oda nosi oznaku IM: 1-1.
Krećući se nalevo kroz memorijske ćelije njihove oznake su IM:1-2, IM:1-3, IM:1-4. Vrednost 0
u memorijskoj ćeliji IM:1-1 znači da je taster START povezan sa ulazom 1 otvoren, što i jeste.
Jedinica u memorijskim ćelijama IM:1-2 and IM:1-3 označava da su prekidači STOP i LS1
zatvoreni, što i jeste.
Nula u ćeliji IM:1-4 pokazuje da je SW1 otvoren.
ZAPAMTITE! Ulazni podaci na lokacijama IM:1-2 i IM:1-3 daju informaciju da su kontakti
priključeni na odgovarajuće ulaze zatvoreni. Nemamo informaciju da li su to neaktivirani NC ili
aktivirani NO kontakti.
PLC programiranje i funkcionisanje - Ladder Diagram
Upravljanje pneumatskim cilindrom

Kvadratići(1, 2, 3 i 4) izlaznog modula OM:1 sadrže prekidačka kola koji koriste logičke
naponske nivoe (vrednosti izlaznih memorijskih ćelija) kako bi aktivirali ili deaktivirali izlazne
uređaje (stanja ON ili OFF).
Linija povezuje izlazni kvadratić 1 sa gornjom desnom izlaznom memorijskom ćelijom, tako da
je njena adresa OM:1-1.
Krećući se nalevo od ćelije OM:1-1 su ćelije OM:1-2, OM:1-3, and OM:1-4.
Nule u memorijskim ćelijama OM:1-1 i OM:1-2 znači da su solneoid i sijalica isključeni (stanje
OFF).
PLC programiranje i funkcionisanje - Ladder Diagram
Upravljanje pneumatskim cilindrom

Ladder diagram PLC program - Ladder diagram language


Upoređujući PLC program sa lestvičastim dijagramom (kontaktorskom šemom KŠ) mogu se uočiti
sličnosti, ali i neke razlike.
KŠ ima tri linije (prečage, lestvice) a program samo dve. Druga linija se izgubila pošto je Sol a,
izlazni uređaj povezan na izlazni terminal OM:1-1. Iz tog razloga se on ne pojavljuje u programu.
Izlaz OM:1-1 na prvoj liniji programa kontroliše relej CR1, koji aktivira Sol a. Prva linija programa
sadrži prve dve linije kontaktorske šeme.
PLC programiranje i principi funkcionisanja - Ladder Diagram
LD programski jezik postavlja određena ograničenja po pitanju pisanja programa, i ta
ograničenja variraju od proizvođača do proizvođača uređaja. Tipična ograničenja su:

1. Izlaz mora biti na desnom kraju grane.

2. Tok energije mora biti s leva na desno, nagore ili nadole.

3. Energija NE SME da teče s desna na levo.

4. Broj kontakata povezanih na red je maksimalno 11 (ili neki drugi broj postavljen od
strane proizvođača).

5. Broj paralelnih kontakata je maksimalno 7 (ili neki drugi broj postavljen od strane
proizvođača).

6. Grana može da ima samo jedan izlaz.

7. Izlaz mora da bude postavljen u najgronjoj liniji grane.


PLC programming and operation - Ladder Diagram Programming
• U relejnoj logici, tok energije s desna na levo se naziva “puzajući put”. Puzajući putevi nisu
dozvoljeni u PLC programiranju, što pojednostavljuje samo progrmiranje ali i zahteva
prilagođenje relejne logike (dijagrama). Puzajući putevi se moraju konvertovati u odgovarajuće
ladder dijagrame (kontaktorske šeme) koji ih ne sadrže.
• U LD programskom jeziku otvoreni i zatvoreni kontakti su u stvari programske instrukcije, a ne
preslikani kontakti kontaktorskih šema. Oni govore PLCu kako da interpretira 1 i 0 koji se nalaze
na ulaznim memorijskim lokacijama (za svaki pojedinačni kontakt). Simbol normalno otvorenog
kontakta (┤├) daje PlCu instrukciju da interpretira 1 kao TAČNO (TRUE) a 0 kao NETAČNO
(FALSE). Ako PLC uspe da pronađe TAČAN put od ulaza do izlaza, tada je izlaz ON, u
odgovarajuću izlaznu memorijsku ćeliju se upisuje 1 i aktivira se odgovarajući izlazni uređaj.
Ako nije pronađen tačan put, tada je izlaz OFF, i upisuje se 0 u odgovarajuću izlaznu
memorijsku lokaciju.
• Simbol NO kontakta se može koristiti i za NO i za NC fizičke kontakte. Naravno, mi kreiramo
rezultate u skladu sa potrebama.
PLC programming and operation - Ladder Diagram Programming
PLC programming and operation - Ladder Diagram Programming
PLC programming and operation - Ladder Diagram Programming

When a PLC is in the RUN mode, the processor repeats the following four-step cycle:

1. Input scan. Store a new image of input conditions.

2. Program scan. Derive the new image of output conditions.

3. Output scan. Transfer the new image of output conditions to output devices.

4. Housekeeping tasks. Communication and other tasks.


PLC programming and operation - Ladder Diagram Programming
Control circuit for a pneumatic cylinder

Cycle 1. start and SW1 are open, stop and LS1 are closed.
Input scan. New input image is IM:1-1 = 0, IM:1-2 = 1, IM:1-3 = 1, IM:1-4 = 0.
Program scan. Rung 1: IM:1-1 = FALSE, OM:1-1 = FALSE, IM:1-2 = TRUE, IM:1-3 =
TRUE, path is FALSE, so 0 is stored in cell OM:1-1. Rung 2: IM:1-4 = FALSE so 0 is
stored in cell OM:1-2.
Output scan. Both solenoid a and the light are off.
PLC programming and operation - Ladder Diagram Programming
Control circuit for a pneumatic cylinder

Cycle 2. START, SW1, STOP, and LS1 are all closed.


Input scan. New input image: IM:1-1 = 1, IM:1-2 = 1, IM:1-3 = 1, IM:1-4 = 1.
Program scan. Rung 1: IM:1-1 = TRUE, OM:1-1 = FALSE, IM:1-2 = TRUE, IM:1-3 = TRUE,
path is TRUE, so 1 is stored in cell OM:1-1. Rung 2: IM:1-4 = TRUE, so 1 is stored in cell
OM:1-2.
Output scan. Both solenoid a and the light are ON.
PLC programming and operation - Ladder Diagram Programming
Control circuit for a pneumatic cylinder

Cycle 3. START is open, SW1, STOP and LS1 are all closed.
Input scan. New input image: IM:1-1 = 0, IM:1-2 = 1, IM:1-3 = 1, IM:1-4 = 1.
Program scan. Rung 1: IM:1-1 = FALSE, OM:1-1 = TRUE, IM:1-2 = TRUE, IM:1-3 = TRUE,
path is TRUE, so 1 is stored in cell OM:1-1. Rung 2: IM:1-4 = TRUE so 1 is stored in cell
OM:1-2.
Output scan. Both solenoid a and the light are ON.
PLC programming and operation - Ladder Diagram Programming
Control circuit for a pneumatic cylinder

Cycle 4. START and LSI are open, STOP and SW1 are closed.
Input scan. New input image: IM:1-1 = 0, IM:1-2 = 1, IM:1-3 = 0, IM:1-4 = 1.
Program scan. Rung 1: IM:1-1 = FALSE, OM:1-1 = TRUE, IM:1-2 = TRUE, IM:1-3= FALSE,
path is FALSE, so 0 is stored in cell OM:1-1. Rung 2: IM:1-4 = TRUE so 1 is stored in cell
OM:1-2.
Output scan. Solenoid a is OFF, the light is ON.
PLC programming functions – Timer function

• The Timer is the most frequently used PLC function, and Time Delay On is the most
common timing function.

• Both Time Delay On and Time Delay Off are used in PLCs.

• Two types of timers are used in programmable logic controllers:

1. one-input nonretentive timer

2. two-input retentive timer.

• The nonretentive timer has one input, one output, and a preset delay time.

• The retentive timer has two inputs, one output, and two status bits that can be used as
internal outputs. The inputs are the Enable/Reset line and the Run line. The output is the
Done.
PLC programming functions – Timer function

A generic, two-input, retentive


timer and a typical timing
diagram. The timer is shown
with the output address T:12. In
the timing diagram,
Enable/Reset, and Run are
inputs, T:12, T:12-E, and T:12-R
are outputs. Observe that the
timing diagrams of T:12-E and
Enable/Reset match exactly,
but the diagrams of T:12-R and
Run do not. Output T:12-R is
ON only when Enable/Reset is
ON, Run input is ON, and Done
is OFF. Output T:12 (Done) is
ON only after the preset time
delay has been reached, and it
goes OFF when Enable/Reset
goes OFF.
Traditional Timer Functions
T44 T44
S_PULSE S_PEXT
I 0.7 S BI MW0 I 0.7 S BI MW0
S5T#35s BCD QW12 S5T#35s QW12
TV TV BCD
I 0.5 R Q M8.5 I 0.5 R Q M8.5
= =
Pulse Timer (SP) ON Delay (SD) Extended Pulse (SE)
T44
S_ODT
I 0.7 S BI MW0
S5T#35s BCD QW12
TV
I 0.5 R Q M8.5

Stored ON Delay (SS) = OFF Delay (SF)


T44 T44
S_ODTS S_OFFDT
I 0.7 S BI MW0 MW0
I 0.7 S BI
S5T#35s BCD QW12 S5T#35s QW12
TV TV BCD
I 0.5 R Q M8.5 I 0.5 R M8.5
Q
= =
Example of Timer Function: ON Delay (SD)
LAD FBD STL

T4 T4
I 0.7 S_ODT Q8.5 S_EVERZ A I 0.7
S Q I 0.7 S BI MW0 L S5T#35s
S5T#35s TV BI MW0 S5T#35s QW12
SD T4
TV BCD
I 0.5 Q8.5 A I 0.5
R BCD QW12 I 0.5 R Q = R T4
L T4
T MW0
RLO at S
LC T4
RLO at R T QW12
A T4
Time = Q8.5
operation
Example

Data type 0.01s <-- 0 0


0.1s <-- 0 1
“S5TIME” 1s <-- 1 0 Units of time: 0 to 999 (BCD-coded)
10s <-- 1 1
PLC programming functions – Counter function

• The PLC counter keeps track of the number of times a contact opens and ignores the
times the contact closes between each pair of openings.

• In this way, the counter is "counting" the event that causes the contact to open.

• The event might be an item that is conveyed past a photo detector. It might be a vehicle
that is driven over a pneumatic pressure detector. It might be a metal object on a shaft
that rotates past a magnetic detector. Industry has many events to count.

• Some PLC counters count from 0 up to a preset value; others count from the preset value
down to 0. Most PLCs include both up and down counters.
PLC programming functions – Counter function
A generic, two-input counter. The
counter is shown with the output
address C:7, the preset value 120, and
the counter register address RA:0027.
When the Enable/Reset line is OFF, the
counter ignores changes on the count
input line, output (C:7) is OFF, and the
count register (RA:0027) is reset to 0.
When the Enable/Reset line is ON, the
counter increments the count by 1 each
time the count input line goes from OFF
to ON. The counter output (C:7) is OFF
until the count in RA:0027 reaches the
preset value (120). At that time, C:7 is
turned ON and remains ON until
Enable/Reset is turned OFF. The
counter continues to increment the
count register beyond the preset value,
even though the output is ON, indicating
it is done.
Traditional Counter Functions
LAD FBD STL

A I 0.4
C5 C5
CU C5
S_CUD S_CUD A I 0.5
I 0.4 Q 8.3
CU Q
Q I 0.4 CU CD C5
A I 0.3
I 0.5
L C#5
CD CV MW 4 I 0.5 CD
S C5
I 0.3 A I 0.7
S CV_BCD QW 12 I 0.3 S CV MW 4 R C5
L C5
C#5 PV C#5 PV CV_BCD QW 12 T MW4
Q 8.3 LC C5
I 0.7
R I 0.7 R Q
Q = T QW12
A C5
= Q8.3
Counters: Function Diagram

CU

CD

5
4
3
Count
2
1
0

Q
PLC programming functions – Counter function

Exercise: explain the LD for a


two-counter PLC program
maintains a count of the
number of customers in a
store.
PLC programming functions – Sequencer Function
• The sequencer function goes through a sequence of steps, producing specified conditions
in a number of ON/OFF outputs at each step.

• The specified output pattern for each step is stored in one word of memory, and patterns
for successive steps are stored in successive memory cells.

• Each bit in the word is matched with one output (bit 0 is matched with output No.1, bit 1 is
matched with output No.2, . . . , bit 7 is matched with output No.8).

• If a bit holds a logical 1, the sequencer turns the matching output ON (or leaves it ON).

• If a bit holds a logical 0, the sequencer turns the matching output OFF (or leaves it OFF).

• The number of outputs that a sequencer can control depends on the word size of the
PLC. An 8-bit PLC can control up to 8 outputs, and a 16-bit PLC can control up to 16
outputs.

• Additional sequencer functions can be used to control additional outputs. For example,
two 16-bit sequencers can control up to 32 outputs.
PLC programming functions – Sequencer Function
• A generic sequencer with timed
steps.

• The timer is enabled by it’s own


output, causing it to reset
immediately after it has finished
a 30-s delay.

• After it has reset, the timer


immediately begins another 30-
s delay (assuming OM:1-1 is
ON).

• The timing diagram illustrates


the sequence of pulses
produced by the timer in this
circuit.
PLC programming functions – PID Control Function
In some PLCs, the PID control function
is built into an I/O module.
In other PLCs, the PID function is
programmed as a rung in the ladder
diagram program.

Enable: Enables the function when ON


Manual/Auto: OFF for manual, ON for
automatic control
Setpoint: Register that holds the process
variable
Error: Register that holds the error
Output: Register that holds the output
P: Register that holds the proportional gain
setting
I: Register that holds the integral action
time constant
D: Register that holds the derivative time A generic PID controller function
setting
DISCRETE I/O FUNCTIONS AND DEVICES - BINARY
OPERATIONS
I 0.0 I 0.1 Q 8.0

Q 8.1 I 1.0 &


M1.0 M8.0
I 1.1 P =

T4
I 0.7 S_ODT
Q8.5
S Q

S5T#35s TV BI MW0
I 0.5
R BCD QW12
Binary Logic Operations: AND, OR

Circuit Diagram LAD FBD STL

S1 (I 0.0)
I 0.0 I 0.1 Q 8.0 I 0.0 & Q 8.0 A I 0.0
= A I 0.1
AND S2 (I 0.1) I 0.1
= Q 8.0
Q 8.1 Q 8.1 = Q 8.1
=

L1 L2
(Q 8.0) (Q 8.1)

S3
(I 0.2) I 0.2 Q 8.2
Q 8.2 O I 0.2
S4 I 0.2 >=1
OR = O I 0.3
(I 0.3) I 0.3 = Q 8.2
I 0.3

L3 (Q 8.2)
Binary Logic Operations: Exclusive OR (XOR)

LAD FBD STL

I 0.4 & A I 0.4


I 0.4 I 0.5 Q 8.0 Q 8.0 AN I 0.5
I 0.5 >=1 O
=
AN I 0.4
I 0.4 & A I 0.5
I 0.4 I 0.5 I 0.5 = Q8.0

I 0.4 Q 8.0 X I 0.4


XOR
= X I 0.5
I 0.5 = Q8.0
Assignment, Setting, Resetting

LAD FBD STL

I 1.0 I 1.1 Q 8.0 A I 1.0


I 1.0 A I 1.1
& Q 8.0
Assignment ( ) = Q 8.0
I 1.1 =

I 1.2 I 1.3
Q 8.1 I 1.2 A I 1.2
& Q 8.1
Set (S) A I 1.3
I 1.3 S S Q 8.1

I 1.4 Q 8.1
(R) I 1.4 O I 1.4
>=1 Q 8.1 O I 1.5
Reset I 1.5 R R Q 8.1
I 1.5
RLO – Edge Detection
LAD FBD STL

A I 1.0
I 1.0 I 1.1 M1.0 M8.0 I 1.0 &
M1.0 M8.0 A I 1.1
P FP M1.0
I 1.1 P = = M8.0

I 1.0 I 1.1 M1.1 M8.1 I 1.0 A I 1.0


& M8.1 A I 1.1
M1.1
N FN M1.1
I 1.1 N = = M8.1

OB1 Cycle
I 1.0

I 1.1

RLO
Example
M1.0

M1.1

M8.0
M8.1
Digital Operations

I 0.0 I 0.1 Q 8.0

Q 8.1 I 1.0 &


M1.0 M8.0
I 1.1 P =

T4
I 0.7 S_ODT
Q8.5
S Q

S5T#35s BI MW0
TV
I 0.5
R BCD QW12
Integer (INT, 16-Bit Integer) Data Type
Value range -32768 to +32767 Arithmetic
(without sign: 0 to 65535) operations: such as + I, * I, <I, ==I

Display Formats:
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

DEC: + 662 BIN.: 2# 0000001010010110 HEX: W#16 #02 9 6


9 without
+2 7 sign
Sign +2 0
4 6 x 16 = 6
positive +2 2 1
numbers +2 1 9 x 16 = 144
+2 2 x 16
2
= 512
+ 662 662

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

DEC: - 662 BIN.: 2# 1111110101101010 HEX: W#16#F D6 A


15 without
-2
+2 13
14 sign
Sign
negative +2 12 0
+2 11 10 x 16 =16
numbers 1
6 x 16 = 96
+2 10 2
8 6
+2 +2 +2 5 13 x 16 = 3328
3 1 3
Representation as +2 +2 +2 15 x 16 = 61440
Twos complement - 662 64874
Double Integer (DINT, 32-Bit Integer) Data Type

Value range L# -2147483648 to L#+2147483647 Operations: such as + D, * D, <D, ==D


(without sign: 0 to 4294967295)

Display Formats:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

DEC: L# +540809 BIN.: 2# 00000000000010000100000010001001

Sign
positive
numbers

HEX: DW#16# 0 0 0 8 4 0 8 9
(without sign)

31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

DEC: L# -540809 BIN.: 2# 11111111111101111011111101110111

Sign
negative
numbers

Representation as HEX: DW#16# F F F 7 B F 7 7


Twos complement
(without sign)
REAL (Floating-point Number, 32 Bit) Data Type
Value range -3.402823•10+38 to -1.175495•10-38 , 0.0, +1.175495•10-38 to +3.402823•10+38

Operations: such as + R, * R, <R, ==R


sin, acos, ln, exp, SQR

General format of a Real number = (Sign) • (1.f) • (2e-127)

Example: 0.75

Sign of
Real no. e = Exponent (8 Bit) f = Mantissa (23 Bit)

31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

0 0 1 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
27 26 25 24 23 22 21 20 2-1 2-2 2-3 2-4 ..... 2-23

Real no. = +1.5 * 2 126-127 = 0.75


The BCD Code for Inputting and Outputting Integers

Value range 16 Bit: - 999 to + 999 Conversion


32 Bit: -9999999 to + 9999999 operations: BTI, BTD, ITB, DTB
(no arithmetic!)

0 2 9 6

16 Bit: BIN.: 2# 0000001010010110

Sign (+) 2 9 6

HEX: W#16# 0 2 9 6 DEC: + 662

Sign (+) 0 0 0 0 2 9 6

32 Bit: BIN.: 2# 0xxx0000000000000000001010010110

HEX: DW#16# 0 0 0 0 2 9 6 DEC: + 662


Conversion Operations BCD <-> Integer

Number Conversion
Entered in BCD 0 81 5 BCD->Integer
User program
Task
with Integer
math operations
Number Conversion
displayed 0 2 4 8 BCD<-Integer
in BCD

LAD FBD STL

BCD_I BCD_I L IW4


EN ENO EN OUT MW20 BTI
T MW20
IW4 IN OUT MW20 IW4 IN ENO

I_BCD I_BCD L MW10


EN ENO EN OUT QW12 ITB
T QW12
MW10 IN OUT QW12 MW10 IN ENO
Comparison Operations

LAD FBD STL

M 3.4 CMP >=I Q 9.7 CMP >=I A M 3.4


A(
IN1 L IW 0
IW0
L IW 2
IW 0 IN1 M 3.4 & Q9.7 >=I
IW 2 IN2 IW2 IN2 = )
= Q 9.7
Basic Mathematical Functions
LAD FBD STL

ADD_I ADD_I L MW4


Addition EN ENO EN OUT MW6 L MW10
MW4 IN1 MW4 IN1 +I
MW10 IN2 OUT MW6 MW10 IN2 ENO T MW6

SUB_I SUB_I L MW8


Subtrac- MW6
tion EN ENO EN OUT L MW12
MW8 IN1 MW8 IN1 -I
MW12 IN2 OUT MW6 MW12 IN2 ENO T MW6

MUL_DI MUL_DI L MD6


Multipli- MD66
cation EN ENO EN OUT L MD12
MD6 IN1 MD6 IN1 *D
MD12 MD66
T MD66
IN2 MD12 IN2 ENO

DIV_R DIV_R L MD40


EN OUT MD32
Division EN ENO L MD4
MD40 IN1 MD40 IN1 /R
MD4 IN2 OUT MD32 MD4 IN2 ENO T MD32
Storing Process Data in Data Blocks
Storage Areas for Data
Data Blocks (DBs)

Accessible to all blocks

Function
OB1
FC10
Global (shared)
data

Function DB20
FC20

Instance DB for FB1

Function Instance Data


Block
FB1 DB5
Overview of Data Types in STEP 7

Elementary • Bit data types (BOOL, BYTE, WORD, DWORD, CHAR)


data types
• Mathematical data types (INT, DINT, REAL)
(up to 32 bits)
• Time types (S5TIME, TIME, DATE, TIME_OF_DAY)

• Time type (DATE_AND_TIME)


Complex
data types • Array (ARRAY)
(longer than 32 bits)
• Structure (STRUCT)
• Character chain (STRING)

User-defined data types Data type UDT (User Defined


(longer than 32 bits) Data-Type)
Elementary Data Types in STEP 7

Keyword Length (in bits) Examples Variables

BOOL 1 True or false I 1.0


BYTE 8 B#16#A9 MB70
WORD 16 W#16#12AF MW72
DWORD 32 DW#16#ADAC1EF5 QD40
CHAR 8 'w' DBB4

S5TIME 16 S5T#5s_200ms MW30

INT 16 123 #Value


DINT 32 L#65539 MD80
REAL 32 1.2 or 3.45E-11 DBD60

TIME 32 T#2D_1H_3M_45S_12MS QD44


DATE 16 D#1993-01-20 MW32
TIME_OF_DAY 32 TOD#12:23:45.12 #Time
Complex Data Types
Keyword Length (in bits) Example
DATE_AND_TIME 64 DT#01-08-24-12:14:55:234-1

STRING 8 * (number of ´This is a string´


(character string with characters +2) ´SIEMENS´
max. 254 characters)

ARRAY user- Measured values: ARRAY[1..20]


(Group of elements defined INT
of the same data type)

STRUCT user- Motor: STRUCT


(Group of elements defined Speed : INT
of different data types) Current : REAL
END_STRUCT

UDT UDT as block UDT as array


element
(User Defined Data Type = user- STRUCT
"Template" consisting of defined Speed : INT Drive: ARRAY[1..4]
elementary or complex Current : REAL UDT1
data types END_STRUCT
Functions and Function Blocks (1)

Program CALL FB5, DB5 Drive


execution Start :=I 0.0
Stop :=I 0.1
Motor_on :=Q8.0
CALL FC 10 Speed :=QW12
On_1 := I 0.1 DB 5
On_2 := I 0.2
Off := Q8.0 0.0 Start BOOL
0.1 Stop BOOL
2.0 Motor_on BOOL
FB 5 4.0 Speed INT
Function FC10
in Start BOOL
in On_1 BOOL in Stop BOOL
in On_2 BOOL out Motor_On BOOL
out Off BOOL out Speed INT
... stat ...
Temp...

...
A #On_1
A #On_2 ...
= #Off A #Start
... AN #Stop
= #Motor_on
...
Exercise X of day 7
Summary of day 7

You might also like